db-ddlutils-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From to...@apache.org
Subject svn commit: r366018 - in /db/ddlutils/trunk/src: java/org/apache/ddlutils/platform/mysql/MySqlModelReader.java java/org/apache/ddlutils/platform/mysql/MySqlPlatform.java test/jdbc.properties.mysql test/org/apache/ddlutils/io/TestDatatypes.java
Date Wed, 04 Jan 2006 23:10:40 GMT
Author: tomdz
Date: Wed Jan  4 15:10:32 2006
New Revision: 366018

URL: http://svn.apache.org/viewcvs?rev=366018&view=rev
Log:
Datatypes are now mapped correctly according to the tests

Added:
    db/ddlutils/trunk/src/test/jdbc.properties.mysql
Modified:
    db/ddlutils/trunk/src/java/org/apache/ddlutils/platform/mysql/MySqlModelReader.java
    db/ddlutils/trunk/src/java/org/apache/ddlutils/platform/mysql/MySqlPlatform.java
    db/ddlutils/trunk/src/test/org/apache/ddlutils/io/TestDatatypes.java

Modified: db/ddlutils/trunk/src/java/org/apache/ddlutils/platform/mysql/MySqlModelReader.java
URL: http://svn.apache.org/viewcvs/db/ddlutils/trunk/src/java/org/apache/ddlutils/platform/mysql/MySqlModelReader.java?rev=366018&r1=366017&r2=366018&view=diff
==============================================================================
--- db/ddlutils/trunk/src/java/org/apache/ddlutils/platform/mysql/MySqlModelReader.java (original)
+++ db/ddlutils/trunk/src/java/org/apache/ddlutils/platform/mysql/MySqlModelReader.java Wed
Jan  4 15:10:32 2006
@@ -51,86 +51,96 @@
         setDefaultTablePattern(null);
     }
 
-    
-    
     /**
-     * @see org.apache.ddlutils.platform.JdbcModelReader#readTable(org.apache.ddlutils.platform.DatabaseMetaDataWrapper,
java.util.Map)
+     * {@inheritDoc}
      * @todo This needs some more work, since table names can be case sensitive or lowercase
      *       depending on the platform (really cute).
      *       See http://dev.mysql.com/doc/refman/4.1/en/name-case-sensitivity.html for more
info.
      */
-    protected Table readTable(DatabaseMetaDataWrapper metaData, Map values) throws SQLException
{
+    protected Table readTable(DatabaseMetaDataWrapper metaData, Map values) throws SQLException
+    {
         Table table =  super.readTable(metaData, values);
-        List indexes = new ArrayList();
-        // this could be optimized, we need to check if an index can be named PRIMARY without
-        // being a primary key. Taking the safe path for now.
-        for (int i = 0; i < table.getIndexCount(); i++)
-        {
-            Index index = table.getIndex(i);
-            if ("PRIMARY".equals(index.getName()))
-            {
-                for (int c = 0; c < index.getColumnCount(); c++)
-                {
-                    String columnName = index.getColumn(c).getName();
-                    Column column  = table.findColumn(columnName);
-                    if (column.isPrimaryKey())
-                    {
-                        indexes.add(index);
-                    }
-                }
-            }
-            else
-            {
-                for (int f = 0; f < table.getForeignKeyCount(); f++)
-                {
-                    ForeignKey fk = table.getForeignKey(f);
-                    if (fk.getName().equals(index.getName()))
-                    {
-                        indexes.add(index);
-                    }
-                }
-            }
-        }
-        for (int i = 0; i < indexes.size(); i++)
-        {
-            table.removeIndex((Index) indexes.get(i));
-        }
+//        List indexes = new ArrayList();
+//        // this could be optimized, we need to check if an index can be named PRIMARY without
+//        // being a primary key. Taking the safe path for now.
+//        for (int i = 0; i < table.getIndexCount(); i++)
+//        {
+//            Index index = table.getIndex(i);
+//            if ("PRIMARY".equals(index.getName()))
+//            {
+//                for (int c = 0; c < index.getColumnCount(); c++)
+//                {
+//                    String columnName = index.getColumn(c).getName();
+//                    Column column  = table.findColumn(columnName);
+//                    if (column.isPrimaryKey())
+//                    {
+//                        indexes.add(index);
+//                    }
+//                }
+//            }
+//            else
+//            {
+//                for (int f = 0; f < table.getForeignKeyCount(); f++)
+//                {
+//                    ForeignKey fk = table.getForeignKey(f);
+//                    if (fk.getName().equals(index.getName()))
+//                    {
+//                        indexes.add(index);
+//                    }
+//                }
+//            }
+//        }
+//        for (int i = 0; i < indexes.size(); i++)
+//        {
+//            table.removeIndex((Index) indexes.get(i));
+//        }
         return table;
     }
 
-
-
     /**
-     * @see org.apache.ddlutils.platform.JdbcModelReader#readColumn(org.apache.ddlutils.platform.DatabaseMetaDataWrapper,
java.util.Map)
+     * {@inheritDoc}
      */
     protected Column readColumn(DatabaseMetaDataWrapper metaData, Map values) throws SQLException
     {
         Column column = super.readColumn(metaData, values);
 
-        if ("".equals(column.getDescription()))
-        {
-            column.setDescription(null);
-        }
-        if ("".equals(column.getParsedDefaultValue()))
+        if (column.getTypeCode() == Types.BIT)
         {
-            column.setDefaultValue(null);
-        }
-        if ("auto_increment".equals(column.getDescription()))
-        {
-            column.setAutoIncrement(true);
-        }
-        switch (column.getTypeCode())
-        {
-            case Types.INTEGER:
-                if ("0".equals(column.getDefaultValue()))
-                {
-                    column.setDefaultValue(null);
-                }
-            case Types.DOUBLE:
-                column.setSize(null);
-                break;
+            // MySql
         }
+//        if ("".equals(column.getDescription()))
+//        {
+//            column.setDescription(null);
+//        }
+//        if ("".equals(column.getParsedDefaultValue()))
+//        {
+//            column.setDefaultValue(null);
+//        }
+//        if ("auto_increment".equals(column.getDescription()))
+//        {
+//            column.setAutoIncrement(true);
+//        }
+//        switch (column.getTypeCode())
+//        {
+//            case Types.INTEGER:
+//                if ("0".equals(column.getDefaultValue()))
+//                {
+//                    column.setDefaultValue(null);
+//                }
+//            case Types.DOUBLE:
+//                column.setSize(null);
+//                break;
+//        }
         return column;
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    protected boolean isInternalPrimaryKeyIndex(Table table, Index index)
+    {
+        // MySql defines a unique index "PRIMARY" for primary keys
+        return "PRIMARY".equals(index.getName());
     }
 
 

Modified: db/ddlutils/trunk/src/java/org/apache/ddlutils/platform/mysql/MySqlPlatform.java
URL: http://svn.apache.org/viewcvs/db/ddlutils/trunk/src/java/org/apache/ddlutils/platform/mysql/MySqlPlatform.java?rev=366018&r1=366017&r2=366018&view=diff
==============================================================================
--- db/ddlutils/trunk/src/java/org/apache/ddlutils/platform/mysql/MySqlPlatform.java (original)
+++ db/ddlutils/trunk/src/java/org/apache/ddlutils/platform/mysql/MySqlPlatform.java Wed Jan
 4 15:10:32 2006
@@ -46,38 +46,41 @@
         PlatformInfo info = new PlatformInfo();
 
         info.setMaxIdentifierLength(64);
-        info.setRequiringNullAsDefaultValue(false);
+        info.setRequiringNullAsDefaultValue(true);
+        info.setSupportingDefaultValuesForLongTypes(false);
         info.setPrimaryKeyEmbedded(true);
         info.setForeignKeysEmbedded(false);
         info.setIndicesEmbedded(false);
         // see http://dev.mysql.com/doc/refman/4.1/en/example-auto-increment.html
         info.setSupportingNonPKIdentityColumns(false);
+        // MySql returns synthetic default values for pk columns
+        info.setReturningDefaultValueForPrimaryKeys(true);
         info.setCommentPrefix("#");
         // Double quotes are only allowed for delimiting identifiers if the server SQL mode
includes ANSI_QUOTES 
         info.setDelimiterToken("`");
-        // the BINARY types are also handled by MySqlBuilder.getSqlType(Column)
-        info.addNativeTypeMapping(Types.ARRAY,         "LONGBLOB");
-        info.addNativeTypeMapping(Types.BINARY,        "CHAR {0} BINARY");
+
+        info.addNativeTypeMapping(Types.ARRAY,         "LONGBLOB",          Types.LONGVARBINARY);
         info.addNativeTypeMapping(Types.BIT,           "TINYINT(1)");
-        info.addNativeTypeMapping(Types.BLOB,          "LONGBLOB");
-        info.addNativeTypeMapping(Types.CLOB,          "LONGTEXT");
-        info.addNativeTypeMapping(Types.DISTINCT,      "LONGBLOB");
-        info.addNativeTypeMapping(Types.FLOAT,         "DOUBLE");
-        info.addNativeTypeMapping(Types.JAVA_OBJECT,   "LONGBLOB");
+        info.addNativeTypeMapping(Types.BLOB,          "LONGBLOB",          Types.LONGVARBINARY);
+        info.addNativeTypeMapping(Types.CLOB,          "LONGTEXT",          Types.LONGVARCHAR);
+        info.addNativeTypeMapping(Types.DISTINCT,      "LONGBLOB",          Types.LONGVARBINARY);
+        info.addNativeTypeMapping(Types.FLOAT,         "DOUBLE",            Types.DOUBLE);
+        info.addNativeTypeMapping(Types.JAVA_OBJECT,   "LONGBLOB",          Types.LONGVARBINARY);
         info.addNativeTypeMapping(Types.LONGVARBINARY, "MEDIUMBLOB");
         info.addNativeTypeMapping(Types.LONGVARCHAR,   "MEDIUMTEXT");
-        info.addNativeTypeMapping(Types.NULL,          "MEDIUMBLOB");
-        info.addNativeTypeMapping(Types.NUMERIC,       "DECIMAL");
-        info.addNativeTypeMapping(Types.OTHER,         "LONGBLOB");
+        info.addNativeTypeMapping(Types.NULL,          "MEDIUMBLOB",        Types.LONGVARBINARY);
+        info.addNativeTypeMapping(Types.NUMERIC,       "DECIMAL",           Types.DECIMAL);
+        info.addNativeTypeMapping(Types.OTHER,         "LONGBLOB",          Types.LONGVARBINARY);
         info.addNativeTypeMapping(Types.REAL,          "FLOAT");
-        info.addNativeTypeMapping(Types.REF,           "MEDIUMBLOB");
-        info.addNativeTypeMapping(Types.STRUCT,        "LONGBLOB");
+        info.addNativeTypeMapping(Types.REF,           "MEDIUMBLOB",        Types.LONGVARBINARY);
+        info.addNativeTypeMapping(Types.STRUCT,        "LONGBLOB",          Types.LONGVARBINARY);
         // Since TIMESTAMP is not a stable datatype yet, and does not support a higher precision
         // that DATETIME (year to seconds) as of MySQL 5, we map the JDBC type here to DATETIME
         // TODO: Make this configurable
         info.addNativeTypeMapping(Types.TIMESTAMP,     "DATETIME");
-        info.addNativeTypeMapping(Types.VARBINARY,     "VARCHAR {0} BINARY");
-        info.addNativeTypeMapping("BOOLEAN",  "TINYINT(1)");
+        // In MySql, TINYINT has only a range of -128 to 127
+        info.addNativeTypeMapping(Types.TINYINT,       "SMALLINT",          Types.SMALLINT);
+        info.addNativeTypeMapping("BOOLEAN",  "TINYINT(1)", "BIT");
         info.addNativeTypeMapping("DATALINK", "MEDIUMBLOB");
 
         info.addDefaultSize(Types.CHAR,      254);

Added: db/ddlutils/trunk/src/test/jdbc.properties.mysql
URL: http://svn.apache.org/viewcvs/db/ddlutils/trunk/src/test/jdbc.properties.mysql?rev=366018&view=auto
==============================================================================
--- db/ddlutils/trunk/src/test/jdbc.properties.mysql (added)
+++ db/ddlutils/trunk/src/test/jdbc.properties.mysql Wed Jan  4 15:10:32 2006
@@ -0,0 +1,16 @@
+# JDBC properties for MySQL using Connector/J
+# Note: Properties starting with "datasource." will be fed into the datasource instance of
the
+# class configured via the datasource.class property
+
+# Use this property if ddlutils does not recognize the platform from the settings
+#ddlutils.platform=MySql
+
+#
+# Using the plain DBCP datasource
+#
+
+datasource.class=org.apache.commons.dbcp.BasicDataSource
+datasource.driverClassName=com.mysql.jdbc.Driver
+datasource.url=jdbc:mysql://localhost/ddlutils
+datasource.username=root
+datasource.password=root123

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=366018&r1=366017&r2=366018&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 Wed Jan  4 15:10:32
2006
@@ -739,12 +739,15 @@
      */
     public void testLongVarCharWithDefault()
     {
-        String value = "1234567890123456789012345678901234567890123456789012345678901234"+
-                       "1234567890123456789012345678901234567890123456789012345678901234"+
-                       "1234567890123456789012345678901234567890123456789012345678901234"+
-                       "1234567890123456789012345678901234567890123456789012345678901234";
-        
-        performDataTypeTest(TEST_LONGVARCHAR_MODEL_WITH_DEFAULT, null, value, "some value");
+        if (getPlatformInfo().isSupportingDefaultValuesForLongTypes())
+        {
+            String value = "1234567890123456789012345678901234567890123456789012345678901234"+
+                           "1234567890123456789012345678901234567890123456789012345678901234"+
+                           "1234567890123456789012345678901234567890123456789012345678901234"+
+                           "1234567890123456789012345678901234567890123456789012345678901234";
+            
+            performDataTypeTest(TEST_LONGVARCHAR_MODEL_WITH_DEFAULT, null, value, "some value");
+        }
     }
 
     /**



Mime
View raw message