db-ddlutils-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From to...@apache.org
Subject svn commit: r374879 - in /db/ddlutils/trunk/src: java/org/apache/ddlutils/ java/org/apache/ddlutils/platform/oracle/ test/org/apache/ddlutils/ test/org/apache/ddlutils/io/
Date Sat, 04 Feb 2006 15:07:57 GMT
Author: tomdz
Date: Sat Feb  4 07:07:24 2006
New Revision: 374879

URL: http://svn.apache.org/viewcvs?rev=374879&view=rev
Log:
Added flag that determines whether the platform can read the auto-increment status back from
an existing database (the Oracle platforms can't)
Added check of the alter tables sql to the datatypes and constraints tests

Modified:
    db/ddlutils/trunk/src/java/org/apache/ddlutils/PlatformInfo.java
    db/ddlutils/trunk/src/java/org/apache/ddlutils/platform/oracle/Oracle8Platform.java
    db/ddlutils/trunk/src/test/org/apache/ddlutils/TestDatabaseWriterBase.java
    db/ddlutils/trunk/src/test/org/apache/ddlutils/io/RoundtripTestBase.java
    db/ddlutils/trunk/src/test/org/apache/ddlutils/io/TestConstraints.java
    db/ddlutils/trunk/src/test/org/apache/ddlutils/io/TestDatatypes.java

Modified: db/ddlutils/trunk/src/java/org/apache/ddlutils/PlatformInfo.java
URL: http://svn.apache.org/viewcvs/db/ddlutils/trunk/src/java/org/apache/ddlutils/PlatformInfo.java?rev=374879&r1=374878&r2=374879&view=diff
==============================================================================
--- db/ddlutils/trunk/src/java/org/apache/ddlutils/PlatformInfo.java (original)
+++ db/ddlutils/trunk/src/java/org/apache/ddlutils/PlatformInfo.java Sat Feb  4 07:07:24 2006
@@ -121,6 +121,9 @@
     /** Whether the database returns a synthetic default value for non-identity required
columns. */ 
     private boolean _returningDefaultValueForRequired = false;
     
+    /** Whether the platform is able to determine auto increment status from an existing
database. */ 
+    private boolean _canReadAutoIncrementStatus = true;
+
     /**
      * Creates a new platform info object.
      */
@@ -871,4 +874,27 @@
         _returningDefaultValueForRequired = returningDefaultValue;
     }
 
+    /**
+     * Determines whether the platform is able to read the auto-increment status for columns
+     * from an existing database.
+     * 
+     * @return <code>true</code> if the auto-increment status can be determined
from an existing
+     *         database
+     */
+	public boolean getCanReadAutoIncrementStatus()
+	{
+		return _canReadAutoIncrementStatus;
+	}
+
+    /**
+     * Specifies whether the platform is able to read the auto-increment status for columns
+     * from an existing database.
+     * 
+     * @param canReadAutoIncrementStatus <code>true</code> if the auto-increment
status can be
+     *                                   determined from an existing database
+     */
+	public void setCanReadAutoIncrementStatus(boolean canReadAutoIncrementStatus)
+	{
+		_canReadAutoIncrementStatus = canReadAutoIncrementStatus;
+	}
 }

Modified: db/ddlutils/trunk/src/java/org/apache/ddlutils/platform/oracle/Oracle8Platform.java
URL: http://svn.apache.org/viewcvs/db/ddlutils/trunk/src/java/org/apache/ddlutils/platform/oracle/Oracle8Platform.java?rev=374879&r1=374878&r2=374879&view=diff
==============================================================================
--- db/ddlutils/trunk/src/java/org/apache/ddlutils/platform/oracle/Oracle8Platform.java (original)
+++ db/ddlutils/trunk/src/java/org/apache/ddlutils/platform/oracle/Oracle8Platform.java Sat
Feb  4 07:07:24 2006
@@ -58,6 +58,7 @@
         info.setPrimaryKeyEmbedded(true);
         info.setForeignKeysEmbedded(false);
         info.setIndicesEmbedded(false);
+        info.setCanReadAutoIncrementStatus(false);
 
         // Note that the back-mappings are partially done by the model reader, not the driver
         info.addNativeTypeMapping(Types.ARRAY,         "BLOB",             Types.BLOB);

Modified: db/ddlutils/trunk/src/test/org/apache/ddlutils/TestDatabaseWriterBase.java
URL: http://svn.apache.org/viewcvs/db/ddlutils/trunk/src/test/org/apache/ddlutils/TestDatabaseWriterBase.java?rev=374879&r1=374878&r2=374879&view=diff
==============================================================================
--- db/ddlutils/trunk/src/test/org/apache/ddlutils/TestDatabaseWriterBase.java (original)
+++ db/ddlutils/trunk/src/test/org/apache/ddlutils/TestDatabaseWriterBase.java Sat Feb  4
07:07:24 2006
@@ -284,6 +284,20 @@
     }
     
     /**
+     * Reads the database model from the database.
+     * 
+     * @return The model
+     */
+    protected String getAlterTablesSql(Database desiredModel)
+    {
+    	Properties props   = getTestProperties();
+        String     catalog = props.getProperty(DDLUTILS_PROPERTY_PREFIX + "catalog");
+        String     schema  = props.getProperty(DDLUTILS_PROPERTY_PREFIX + "schema");
+
+        return getPlatform().getAlterTablesSql(catalog, schema, null, desiredModel, true,
true, true);
+    }
+
+    /**
      * Determines the value of the bean's property that has the given name. Depending on
the
      * case-setting of the current builder, the case of teh name is considered or not. 
      * 

Modified: db/ddlutils/trunk/src/test/org/apache/ddlutils/io/RoundtripTestBase.java
URL: http://svn.apache.org/viewcvs/db/ddlutils/trunk/src/test/org/apache/ddlutils/io/RoundtripTestBase.java?rev=374879&r1=374878&r2=374879&view=diff
==============================================================================
--- db/ddlutils/trunk/src/test/org/apache/ddlutils/io/RoundtripTestBase.java (original)
+++ db/ddlutils/trunk/src/test/org/apache/ddlutils/io/RoundtripTestBase.java Sat Feb  4 07:07:24
2006
@@ -423,9 +423,14 @@
         assertEquals("Required status not the same for column "+actual.getName()+".",
                      expected.isRequired(),
                      actual.isRequired());
-        assertEquals("Auto-increment status not the same for column "+actual.getName()+".",
-                     expected.isAutoIncrement(),
-                     actual.isAutoIncrement());
+        if (getPlatformInfo().getCanReadAutoIncrementStatus())
+        {
+        	// we're only comparing this if the platform can actually read the
+        	// auto-increment status back from an existing database
+	        assertEquals("Auto-increment status not the same for column "+actual.getName()+".",
+	                     expected.isAutoIncrement(),
+	                     actual.isAutoIncrement());
+        }
         assertEquals("Type code not the same for column "+actual.getName()+".",
                      expected.getTypeCode(),
                      actual.getTypeCode());

Modified: db/ddlutils/trunk/src/test/org/apache/ddlutils/io/TestConstraints.java
URL: http://svn.apache.org/viewcvs/db/ddlutils/trunk/src/test/org/apache/ddlutils/io/TestConstraints.java?rev=374879&r1=374878&r2=374879&view=diff
==============================================================================
--- db/ddlutils/trunk/src/test/org/apache/ddlutils/io/TestConstraints.java (original)
+++ db/ddlutils/trunk/src/test/org/apache/ddlutils/io/TestConstraints.java Sat Feb  4 07:07:24
2006
@@ -16,6 +16,8 @@
  * limitations under the License.
  */
 
+import org.apache.ddlutils.model.Database;
+
 import junit.framework.Test;
 
 /**
@@ -185,16 +187,30 @@
     }
     
     /**
-     * Tests a nullable column.
+     * Tests a nullable column. Basically we're creating the test database
+     * and then read it back and compare the original with the read one.
+     * In addition we can also check that DdlUtils does not try to alter the new
+     * database when using the <code>alterTables</code>/<code>getAlterTablesSql</code>
+     * methods of the {@link org.apache.ddlutils.Platform} with the read-back model.
      * 
-     * @param modelXml The model to be tested in XML form
+     * @param modelXml        The model to be tested in XML form
+     * @param checkAlteration Whether to also check the alter tables sql
      */
-    protected void performConstraintsTest(String modelXml)
+    protected void performConstraintsTest(String modelXml, boolean checkAlteration)
     {
         createDatabase(modelXml);
 
+        Database modelFromDb = readModelFromDatabase("roundtriptest");
+        
         assertEquals(getAdjustedModel(),
-                     readModelFromDatabase("roundtriptest"));
+        		     modelFromDb);
+
+        if (checkAlteration)
+        {
+	        String alterTablesSql = getAlterTablesSql(modelFromDb).trim();
+	
+	        assertTrue(alterTablesSql.length() == 0);
+        }
     }
 
     /**
@@ -202,7 +218,7 @@
      */
     public void testNullableColumn()
     {
-        performConstraintsTest(TEST_NULL_MODEL);
+        performConstraintsTest(TEST_NULL_MODEL, true);
     }
 
     /**
@@ -210,7 +226,7 @@
      */
     public void testNotNullableColumn()
     {
-        performConstraintsTest(TEST_NOT_NULL_MODEL);
+        performConstraintsTest(TEST_NOT_NULL_MODEL, true);
     }
 
     /**
@@ -221,7 +237,8 @@
         // only test this if the platform supports it
         if (getPlatformInfo().isSupportingNonPKIdentityColumns())
         {
-            performConstraintsTest(TEST_AUTO_INCREMENT_INTEGER_MODEL);
+            performConstraintsTest(TEST_AUTO_INCREMENT_INTEGER_MODEL,
+            		               getPlatformInfo().getCanReadAutoIncrementStatus());
         }
     }
 
@@ -230,7 +247,8 @@
      */
     public void testPrimaryKeyAutoIncrementColumn()
     {
-        performConstraintsTest(TEST_PRIMARY_KEY_AUTO_INCREMENT_MODEL);
+        performConstraintsTest(TEST_PRIMARY_KEY_AUTO_INCREMENT_MODEL,
+	                           getPlatformInfo().getCanReadAutoIncrementStatus());
     }
 
     /**
@@ -240,7 +258,7 @@
     {
         if (getPlatformInfo().isSupportingNonUniqueIndices())
         {
-            performConstraintsTest(TEST_INDEX_MODEL);
+            performConstraintsTest(TEST_INDEX_MODEL, true);
         }
     }
 
@@ -249,7 +267,7 @@
      */
     public void testUniqueIndex()
     {
-        performConstraintsTest(TEST_UNIQUE_INDEX_MODEL);
+        performConstraintsTest(TEST_UNIQUE_INDEX_MODEL, true);
     }
 
     /**
@@ -259,7 +277,7 @@
     {
         if (getPlatformInfo().isSupportingNonUniqueIndices())
         {
-            performConstraintsTest(TEST_PRIMARY_KEY_INDEX_MODEL);
+            performConstraintsTest(TEST_PRIMARY_KEY_INDEX_MODEL, true);
         }
     }
 
@@ -268,7 +286,7 @@
      */
     public void testSimpleForeignKey()
     {
-        performConstraintsTest(TEST_SIMPLE_FOREIGN_KEY_MODEL);
+        performConstraintsTest(TEST_SIMPLE_FOREIGN_KEY_MODEL, true);
     }
 
     /**
@@ -276,7 +294,7 @@
      */
     public void testOverlappingForeignKeys()
     {
-        performConstraintsTest(TEST_OVERLAPPING_FOREIGN_KEYS_MODEL);
+        performConstraintsTest(TEST_OVERLAPPING_FOREIGN_KEYS_MODEL, true);
     }
 
     /**
@@ -284,6 +302,6 @@
      */
     public void testCircularForeignKeys()
     {
-        performConstraintsTest(TEST_CIRCULAR_FOREIGN_KEYS_MODEL);
+        performConstraintsTest(TEST_CIRCULAR_FOREIGN_KEYS_MODEL, true);
     }
 }

Modified: db/ddlutils/trunk/src/test/org/apache/ddlutils/io/TestDatatypes.java
URL: http://svn.apache.org/viewcvs/db/ddlutils/trunk/src/test/org/apache/ddlutils/io/TestDatatypes.java?rev=374879&r1=374878&r2=374879&view=diff
==============================================================================
--- db/ddlutils/trunk/src/test/org/apache/ddlutils/io/TestDatatypes.java (original)
+++ db/ddlutils/trunk/src/test/org/apache/ddlutils/io/TestDatatypes.java Sat Feb  4 07:07:24
2006
@@ -25,6 +25,8 @@
 import java.util.List;
 import java.util.TreeSet;
 
+import org.apache.ddlutils.model.Database;
+
 import junit.framework.Test;
 
 /**
@@ -467,7 +469,10 @@
     }
 
     /**
-     * Performs a data type test.
+     * Performs a data type test. In short, we're testing creation of a database, insertion
of values
+     * into it, and reading the model back. In addition we also check that DdlUtils does
not try to
+     * alter the new database when using the <code>alterTables</code>/<code>getAlterTablesSql</code>
+     * methods of the {@link org.apache.ddlutils.Platform} with the read-back model.
      * 
      * @param modelXml  The model as XML
      * @param inserted1 The non-pk value to insert for the first row 
@@ -486,8 +491,14 @@
         assertEquals(expected1, beans.get(0), "avalue");
         assertEquals(expected2, beans.get(1), "avalue");
 
+        Database modelFromDb = readModelFromDatabase("roundtriptest");
+        
         assertEquals(getAdjustedModel(),
-                     readModelFromDatabase("roundtriptest"));
+                     modelFromDb);
+
+        String alterTablesSql = getAlterTablesSql(modelFromDb).trim();
+
+        assertTrue(alterTablesSql.length() == 0);
     }
 
     /**



Mime
View raw message