db-ddlutils-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From m...@apache.org
Subject svn commit: r367414 - in /db/ddlutils/trunk/src: java/org/apache/ddlutils/ java/org/apache/ddlutils/platform/mysql/ test-profiles/mvdb/ test/ test/org/apache/ddlutils/io/ test/org/apache/ddlutils/platform/
Date Mon, 09 Jan 2006 22:21:10 GMT
Author: mvdb
Date: Mon Jan  9 14:21:00 2006
New Revision: 367414

URL: http://svn.apache.org/viewcvs?rev=367414&view=rev
Log:
Adding support for mysql5.0
The platform tests didn't get any attention yet. That's why not yet committed.
Changed testing the foreignkeys, since mysql5 returns the foreignkey not in the orde the keys
were created.
Just copy & pasted the platform and extended the default MysqlModelreader to keep the
code limited.

Added:
    db/ddlutils/trunk/src/java/org/apache/ddlutils/platform/mysql/MySql50ModelReader.java
    db/ddlutils/trunk/src/test-profiles/mvdb/jdbc.properties.mysql41
      - copied unchanged from r366273, db/ddlutils/trunk/src/test-profiles/mvdb/jdbc.properties.mysql
    db/ddlutils/trunk/src/test-profiles/mvdb/jdbc.properties.mysql50
    db/ddlutils/trunk/src/test/jdbc.properties.mysql50
    db/ddlutils/trunk/src/test/org/apache/ddlutils/platform/TestMySql50Platform.java
Removed:
    db/ddlutils/trunk/src/test-profiles/mvdb/jdbc.properties.mysql
Modified:
    db/ddlutils/trunk/src/java/org/apache/ddlutils/PlatformFactory.java
    db/ddlutils/trunk/src/test/org/apache/ddlutils/io/RoundtripTestBase.java

Modified: db/ddlutils/trunk/src/java/org/apache/ddlutils/PlatformFactory.java
URL: http://svn.apache.org/viewcvs/db/ddlutils/trunk/src/java/org/apache/ddlutils/PlatformFactory.java?rev=367414&r1=367413&r2=367414&view=diff
==============================================================================
--- db/ddlutils/trunk/src/java/org/apache/ddlutils/PlatformFactory.java (original)
+++ db/ddlutils/trunk/src/java/org/apache/ddlutils/PlatformFactory.java Mon Jan  9 14:21:00
2006
@@ -30,6 +30,7 @@
 import org.apache.ddlutils.platform.mckoi.MckoiPlatform;
 import org.apache.ddlutils.platform.mssql.MSSqlPlatform;
 import org.apache.ddlutils.platform.mysql.MySqlPlatform;
+import org.apache.ddlutils.platform.mysql.MySql50Platform;
 import org.apache.ddlutils.platform.oracle.Oracle8Platform;
 import org.apache.ddlutils.platform.oracle.Oracle9Platform;
 import org.apache.ddlutils.platform.postgresql.PostgreSqlPlatform;
@@ -188,6 +189,7 @@
         addPlatform(_platforms, MckoiPlatform.DATABASENAME,      MckoiPlatform.class);
         addPlatform(_platforms, MSSqlPlatform.DATABASENAME,      MSSqlPlatform.class);
         addPlatform(_platforms, MySqlPlatform.DATABASENAME,      MySqlPlatform.class);
+        addPlatform(_platforms, MySql50Platform.DATABASENAME,    MySql50Platform.class);
         addPlatform(_platforms, Oracle8Platform.DATABASENAME,    Oracle8Platform.class);
         addPlatform(_platforms, Oracle9Platform.DATABASENAME,    Oracle9Platform.class);
         addPlatform(_platforms, PostgreSqlPlatform.DATABASENAME, PostgreSqlPlatform.class);

Added: db/ddlutils/trunk/src/java/org/apache/ddlutils/platform/mysql/MySql50ModelReader.java
URL: http://svn.apache.org/viewcvs/db/ddlutils/trunk/src/java/org/apache/ddlutils/platform/mysql/MySql50ModelReader.java?rev=367414&view=auto
==============================================================================
--- db/ddlutils/trunk/src/java/org/apache/ddlutils/platform/mysql/MySql50ModelReader.java
(added)
+++ db/ddlutils/trunk/src/java/org/apache/ddlutils/platform/mysql/MySql50ModelReader.java
Mon Jan  9 14:21:00 2006
@@ -0,0 +1,58 @@
+package org.apache.ddlutils.platform.mysql;
+
+/*
+ * Copyright 1999-2006 The Apache Software Foundation.
+ * 
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * 
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+import java.sql.SQLException;
+import java.util.Map;
+
+import org.apache.ddlutils.PlatformInfo;
+import org.apache.ddlutils.model.Column;
+import org.apache.ddlutils.platform.DatabaseMetaDataWrapper;
+
+/**
+ * Reads a database model from a MySql50 database.
+ *
+ * @author Martin van den Bemt
+ * @version $Revision: $
+ */
+public class MySql50ModelReader extends MySqlModelReader
+{
+    /**
+     * Creates a new model reader for PostgreSql databases.
+     * 
+     * @param platformInfo The platform specific settings
+     */
+    public MySql50ModelReader(PlatformInfo platformInfo)
+    {
+        super(platformInfo);
+    }
+
+    /**
+     * (@inheritDoc)
+     */
+    protected Column readColumn(DatabaseMetaDataWrapper metaData, Map values) throws SQLException
+    {
+        Column column = super.readColumn(metaData, values);
+        // make sure the defaultvalue is null when an empty is returned.
+        if ("".equals(column.getDefaultValue()))
+        {
+            column.setDefaultValue(null);
+        }
+        return column;
+    }
+    
+}

Added: db/ddlutils/trunk/src/test-profiles/mvdb/jdbc.properties.mysql50
URL: http://svn.apache.org/viewcvs/db/ddlutils/trunk/src/test-profiles/mvdb/jdbc.properties.mysql50?rev=367414&view=auto
==============================================================================
--- db/ddlutils/trunk/src/test-profiles/mvdb/jdbc.properties.mysql50 (added)
+++ db/ddlutils/trunk/src/test-profiles/mvdb/jdbc.properties.mysql50 Mon Jan  9 14:21:00 2006
@@ -0,0 +1,17 @@
+# JDBC properties for Mysql
+# 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=MySQL50
+
+#
+# Using the plain DBCP datasource
+#
+
+datasource.class=org.apache.commons.dbcp.BasicDataSource
+datasource.driverClassName=com.mysql.jdbc.Driver
+datasource.url=jdbc:mysql://10.21.21.33:3307/ddlutils
+datasource.username=root
+datasource.password=ddlutils
+datasource.maxConnections=200

Added: db/ddlutils/trunk/src/test/jdbc.properties.mysql50
URL: http://svn.apache.org/viewcvs/db/ddlutils/trunk/src/test/jdbc.properties.mysql50?rev=367414&view=auto
==============================================================================
--- db/ddlutils/trunk/src/test/jdbc.properties.mysql50 (added)
+++ db/ddlutils/trunk/src/test/jdbc.properties.mysql50 Mon Jan  9 14:21:00 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=MySql50
+
+#
+# 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/RoundtripTestBase.java
URL: http://svn.apache.org/viewcvs/db/ddlutils/trunk/src/test/org/apache/ddlutils/io/RoundtripTestBase.java?rev=367414&r1=367413&r2=367414&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 Mon Jan  9 14:21:00
2006
@@ -369,10 +369,20 @@
         assertEquals("Not the same number of foreign keys in table "+actual.getName(),
                      expected.getForeignKeyCount(),
                      actual.getForeignKeyCount());
+        // order is not assumed with the way foreignkeys are returned.
         for (int fkIdx = 0; fkIdx < actual.getForeignKeyCount(); fkIdx++)
         {
-            assertEquals(expected.getForeignKey(fkIdx),
-                         actual.getForeignKey(fkIdx));
+            ForeignKey fk_expected = expected.getForeignKey(fkIdx);
+            ForeignKey fk_actual = null;
+            for (int i = 0; i < actual.getForeignKeyCount(); i++)
+            {
+                fk_actual = actual.getForeignKey(i);
+                if (fk_actual.getName().equals(fk_expected.getName()))
+                {
+                    break;
+                }
+            }
+            assertEquals(fk_expected, fk_actual);
         }
         assertEquals("Not the same number of indices in table "+actual.getName(),
                      expected.getIndexCount(),

Added: db/ddlutils/trunk/src/test/org/apache/ddlutils/platform/TestMySql50Platform.java
URL: http://svn.apache.org/viewcvs/db/ddlutils/trunk/src/test/org/apache/ddlutils/platform/TestMySql50Platform.java?rev=367414&view=auto
==============================================================================
--- db/ddlutils/trunk/src/test/org/apache/ddlutils/platform/TestMySql50Platform.java (added)
+++ db/ddlutils/trunk/src/test/org/apache/ddlutils/platform/TestMySql50Platform.java Mon Jan
 9 14:21:00 2006
@@ -0,0 +1,176 @@
+package org.apache.ddlutils.platform;
+
+/*
+ * Copyright 1999-2006 The Apache Software Foundation.
+ * 
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * 
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+import org.apache.ddlutils.TestPlatformBase;
+import org.apache.ddlutils.model.Database;
+import org.apache.ddlutils.platform.mysql.MySql50Platform;
+
+/**
+ * Tests the MySQL platform.
+ * 
+ * @author Thomas Dudziak
+ * @author Martin van den Bemt
+ * @version $Revision: 231110 $
+ */
+public class TestMySql50Platform extends TestPlatformBase
+{
+    /**
+     * {@inheritDoc}
+     */
+    protected String getDatabaseName()
+    {
+        return MySql50Platform.DATABASENAME;
+    }
+
+    /**
+     * Tests the column types.
+     */
+    public void testColumnTypes() throws Exception
+    {
+        assertEqualsIgnoringWhitespaces(
+            "DROP TABLE IF EXISTS `coltype`;\n"+
+            "CREATE TABLE `coltype`\n"+
+            "(\n"+
+            "    `COL_ARRAY`           LONGBLOB,\n"+
+            "    `COL_BIGINT`          BIGINT,\n"+
+            "    `COL_BINARY`          CHAR(254) BINARY,\n"+
+            "    `COL_BIT`             TINYINT(1),\n"+
+            "    `COL_BLOB`            LONGBLOB,\n"+
+            "    `COL_BOOLEAN`         TINYINT(1),\n"+
+            "    `COL_CHAR`            CHAR(15),\n"+
+            "    `COL_CLOB`            LONGTEXT,\n"+
+            "    `COL_DATALINK`        MEDIUMBLOB,\n"+
+            "    `COL_DATE`            DATE,\n"+
+            "    `COL_DECIMAL`         DECIMAL(15,3),\n"+
+            "    `COL_DECIMAL_NOSCALE` DECIMAL(15,0),\n"+
+            "    `COL_DISTINCT`        LONGBLOB,\n"+
+            "    `COL_DOUBLE`          DOUBLE,\n"+
+            "    `COL_FLOAT`           DOUBLE,\n"+
+            "    `COL_INTEGER`         INTEGER,\n"+
+            "    `COL_JAVA_OBJECT`     LONGBLOB,\n"+
+            "    `COL_LONGVARBINARY`   MEDIUMBLOB,\n"+
+            "    `COL_LONGVARCHAR`     MEDIUMTEXT,\n"+
+            "    `COL_NULL`            MEDIUMBLOB,\n"+
+            "    `COL_NUMERIC`         DECIMAL(15,0),\n"+
+            "    `COL_OTHER`           LONGBLOB,\n"+
+            "    `COL_REAL`            FLOAT,\n"+
+            "    `COL_REF`             MEDIUMBLOB,\n"+
+            "    `COL_SMALLINT`        SMALLINT,\n"+
+            "    `COL_STRUCT`          LONGBLOB,\n"+
+            "    `COL_TIME`            TIME,\n"+
+            "    `COL_TIMESTAMP`       DATETIME,\n"+
+            "    `COL_TINYINT`         TINYINT,\n"+
+            "    `COL_VARBINARY`       VARCHAR(15) BINARY,\n"+
+            "    `COL_VARCHAR`         VARCHAR(15)\n"+
+            ");\n",
+            createTestDatabase(COLUMN_TEST_SCHEMA));
+    }
+
+    /**
+     * Tests the column constraints.
+     */
+    public void testColumnConstraints() throws Exception
+    {
+        assertEqualsIgnoringWhitespaces(
+            "DROP TABLE IF EXISTS `constraints`;\n" +
+            "CREATE TABLE `constraints`\n"+
+            "(\n"+
+            "    `COL_PK`               VARCHAR(32),\n"+
+            "    `COL_PK_AUTO_INCR`     INTEGER AUTO_INCREMENT,\n"+
+            "    `COL_NOT_NULL`         CHAR(100) BINARY NOT NULL,\n"+
+            "    `COL_NOT_NULL_DEFAULT` DOUBLE DEFAULT -2.0 NOT NULL,\n"+
+            "    `COL_DEFAULT`          CHAR(4) DEFAULT 'test',\n"+
+            "    `COL_AUTO_INCR`        BIGINT AUTO_INCREMENT,\n"+
+            "    PRIMARY KEY (`COL_PK`, `COL_PK_AUTO_INCR`)\n"+
+            ");\n",
+            createTestDatabase(COLUMN_CONSTRAINT_TEST_SCHEMA));
+    }
+
+    /**
+     * Tests the table constraints.
+     */
+    public void testTableConstraints() throws Exception
+    {
+        assertEqualsIgnoringWhitespaces(
+            "ALTER TABLE `table3` DROP CONSTRAINT `testfk`;\n"+
+            "ALTER TABLE `table2` DROP CONSTRAINT `table2_FK_COL_FK_1_COL_FK_2_table1`;\n"+
+            "DROP TABLE IF EXISTS `table3`;\n"+
+            "DROP TABLE IF EXISTS `table2`;\n"+
+            "DROP TABLE IF EXISTS `table1`;\n"+
+            "CREATE TABLE `table1`\n"+
+            "(\n"+
+            "    `COL_PK_1`    VARCHAR(32) NOT NULL,\n"+
+            "    `COL_PK_2`    INTEGER,\n"+
+            "    `COL_INDEX_1` CHAR(100) BINARY NOT NULL,\n"+
+            "    `COL_INDEX_2` DOUBLE NOT NULL,\n"+
+            "    `COL_INDEX_3` CHAR(4),\n"+
+            "    PRIMARY KEY (`COL_PK_1`, `COL_PK_2`)\n"+
+            ");\n"+
+            "CREATE INDEX `testindex1` ON `table1` (`COL_INDEX_2`);\n"+
+            "CREATE UNIQUE INDEX `testindex2` ON `table1` (`COL_INDEX_3`, `COL_INDEX_1`);\n"+
+            "CREATE TABLE `table2`\n"+
+            "(\n"+
+            "    `COL_PK`   INTEGER,\n"+
+            "    `COL_FK_1` INTEGER,\n"+
+            "    `COL_FK_2` VARCHAR(32) NOT NULL,\n"+
+            "    PRIMARY KEY (`COL_PK`)\n"+
+            ");\n"+
+            "CREATE TABLE `table3`\n"+
+            "(\n"+
+            "    `COL_PK` VARCHAR(16),\n"+
+            "    `COL_FK` INTEGER NOT NULL,\n"+
+            "    PRIMARY KEY (`COL_PK`)\n"+
+            ");\n"+
+            "ALTER TABLE `table2` ADD CONSTRAINT `table2_FK_COL_FK_1_COL_FK_2_table1` FOREIGN
KEY (`COL_FK_1`, `COL_FK_2`) REFERENCES `table1` (`COL_PK_2`, `COL_PK_1`);\n"+
+            "ALTER TABLE `table3` ADD CONSTRAINT `testfk` FOREIGN KEY (`COL_FK`) REFERENCES
`table2` (`COL_PK`);\n",
+            createTestDatabase(TABLE_CONSTRAINT_TEST_SCHEMA));
+    }
+
+    /**
+     * Tests the usage of creation parameters.
+     */
+    public void testCreationParameters1() throws Exception
+    {
+        Database           testDb = parseDatabaseFromString(COLUMN_CONSTRAINT_TEST_SCHEMA);
+        CreationParameters params = new CreationParameters();
+
+        params.addParameter(testDb.getTable(0),
+                            "ROW_FORMAT",
+                            "COMPRESSED");
+        params.addParameter(null,
+                            "ENGINE",
+                            "INNODB");
+
+        getPlatformInfo().setCommentsSupported(false);
+        getPlatform().getSqlBuilder().createTables(testDb, params, true);
+
+        assertEqualsIgnoringWhitespaces(
+            "DROP TABLE IF EXISTS `constraints`;\n" +
+            "CREATE TABLE `constraints`\n"+
+            "(\n"+
+            "    `COL_PK`               VARCHAR(32),\n"+
+            "    `COL_PK_AUTO_INCR`     INTEGER AUTO_INCREMENT,\n"+
+            "    `COL_NOT_NULL`         CHAR(100) BINARY NOT NULL,\n"+
+            "    `COL_NOT_NULL_DEFAULT` DOUBLE DEFAULT -2.0 NOT NULL,\n"+
+            "    `COL_DEFAULT`          CHAR(4) DEFAULT 'test',\n"+
+            "    `COL_AUTO_INCR`        BIGINT AUTO_INCREMENT,\n"+
+            "    PRIMARY KEY (`COL_PK`, `COL_PK_AUTO_INCR`)\n"+
+            ") ENGINE=INNODB ROW_FORMAT=COMPRESSED;\n",
+            getBuilderOutput());
+    }
+}



Mime
View raw message