db-ddlutils-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From to...@apache.org
Subject svn commit: r332124 - in /db/ddlutils/trunk/src: java/org/apache/ddlutils/model/Column.java java/org/apache/ddlutils/model/TypeMap.java test/org/apache/ddlutils/io/TestDatabaseIO.java
Date Wed, 09 Nov 2005 19:41:39 GMT
Author: tomdz
Date: Wed Nov  9 11:41:33 2005
New Revision: 332124

URL: http://svn.apache.org/viewcvs?rev=332124&view=rev
Log:
Added read-support for the Torque/Turbine extensions BOOLEANINT/BOOLEANCHAR

Modified:
    db/ddlutils/trunk/src/java/org/apache/ddlutils/model/Column.java
    db/ddlutils/trunk/src/java/org/apache/ddlutils/model/TypeMap.java
    db/ddlutils/trunk/src/test/org/apache/ddlutils/io/TestDatabaseIO.java

Modified: db/ddlutils/trunk/src/java/org/apache/ddlutils/model/Column.java
URL: http://svn.apache.org/viewcvs/db/ddlutils/trunk/src/java/org/apache/ddlutils/model/Column.java?rev=332124&r1=332123&r2=332124&view=diff
==============================================================================
--- db/ddlutils/trunk/src/java/org/apache/ddlutils/model/Column.java (original)
+++ db/ddlutils/trunk/src/java/org/apache/ddlutils/model/Column.java Wed Nov  9 11:41:33 2005
@@ -233,8 +233,10 @@
         else
         {
             _typeCode = typeCode.intValue();
+            // we get the corresponding string value from the TypeMap in order
+            // to detect extension types which we don't want in the model
+            _type = TypeMap.getJdbcTypeName(_typeCode);
         }
-        _type = type;
     }
 
     /**

Modified: db/ddlutils/trunk/src/java/org/apache/ddlutils/model/TypeMap.java
URL: http://svn.apache.org/viewcvs/db/ddlutils/trunk/src/java/org/apache/ddlutils/model/TypeMap.java?rev=332124&r1=332123&r2=332124&view=diff
==============================================================================
--- db/ddlutils/trunk/src/java/org/apache/ddlutils/model/TypeMap.java (original)
+++ db/ddlutils/trunk/src/java/org/apache/ddlutils/model/TypeMap.java Wed Nov  9 11:41:33
2005
@@ -144,6 +144,10 @@
             registerJdbcType(Jdbc3Utils.determineBooleanTypeCode(),  BOOLEAN,  true,  false,
false, false);
             registerJdbcType(Jdbc3Utils.determineDatalinkTypeCode(), DATALINK, false, false,
false, true);
         }
+
+        // Torque/Turbine extensions which we only support when reading from an XML schema
+        _typeNameToTypeCode.put("BOOLEANINT",  new Integer(Types.TINYINT));
+        _typeNameToTypeCode.put("BOOLEANCHAR", new Integer(Types.CHAR));
     }
 
     /**

Modified: db/ddlutils/trunk/src/test/org/apache/ddlutils/io/TestDatabaseIO.java
URL: http://svn.apache.org/viewcvs/db/ddlutils/trunk/src/test/org/apache/ddlutils/io/TestDatabaseIO.java?rev=332124&r1=332123&r2=332124&view=diff
==============================================================================
--- db/ddlutils/trunk/src/test/org/apache/ddlutils/io/TestDatabaseIO.java (original)
+++ db/ddlutils/trunk/src/test/org/apache/ddlutils/io/TestDatabaseIO.java Wed Nov  9 11:41:33
2005
@@ -1261,6 +1261,78 @@
         System.out.println("Table : " + Arrays.asList(database.getTables()));
         assertEquals(0, database.getTableCount());
     }
+
+    /**
+     * Tests the Torque/Turbine extensions BOOLEANINT & BOOLEANCHAR.
+     */
+    public void testTurbineExtension() throws Exception
+    {
+        Database model = readModel(
+            "<database name='test'>\n" +
+            "  <table name='SomeTable'>\n" +
+            "    <column name='intField'\n" +
+            "            type='BOOLEANINT'/>\n" +
+            "    <column name='charField'\n" +
+            "            type='BOOLEANCHAR'/>\n" +
+            "  </table>\n" +
+            "</database>");
+
+        assertEquals("test",
+                     model.getName());
+        assertEquals(1,
+                     model.getTableCount());
+        
+        Table table = model.getTable(0);
+
+        assertEquals("SomeTable",
+                     table.getName());
+        assertNull(table.getDescription());
+        assertEquals(0, table.getAutoIncrementColumns().length);
+        assertEquals(2,
+                     table.getColumnCount());
+        assertEquals(0,
+                     table.getForeignKeyCount());
+        assertEquals(0,
+                     table.getIndexCount());
+
+        Column column = table.getColumn(0);
+
+        assertEquals("intField",
+                     column.getName());
+        assertEquals("TINYINT",
+                     column.getType());
+        assertEquals(Types.TINYINT,
+                     column.getTypeCode());
+        assertFalse(column.isPrimaryKey());
+        assertFalse(column.isRequired());
+        assertFalse(column.isAutoIncrement());
+        assertNull(column.getDefaultValue());
+        assertNull(column.getDescription());
+
+        column = table.getColumn(1);
+
+        assertEquals("charField",
+                     column.getName());
+        assertEquals("CHAR",
+                     column.getType());
+        assertEquals(Types.CHAR,
+                     column.getTypeCode());
+        assertFalse(column.isPrimaryKey());
+        assertFalse(column.isRequired());
+        assertFalse(column.isAutoIncrement());
+        assertNull(column.getDefaultValue());
+        assertNull(column.getDescription());
+
+        assertEquals(
+            "  <database name=\"test\">\n" +
+            "    <table name=\"SomeTable\">\n" +
+            "      <column name=\"intField\" primaryKey=\"false\" required=\"false\" type=\"TINYINT\"
autoIncrement=\"false\"/>\n" +
+            "      <column name=\"charField\" primaryKey=\"false\" required=\"false\"
type=\"CHAR\" autoIncrement=\"false\"/>\n" +
+            "    </table>\n" +
+            "  </database>\n",
+            writeModel(model));
+    }
+
     // TODO: Tests that include:
     // * foreign key references undefined table
     // * foreign key references undefined local column



Mime
View raw message