]> source.dussan.org Git - iciql.git/commitdiff
Fix name collissions on indexes, unique keys, and foreign keys
authorJames Moger <james.moger@gmail.com>
Mon, 15 Oct 2012 14:55:47 +0000 (10:55 -0400)
committerJames Moger <james.moger@gmail.com>
Mon, 15 Oct 2012 14:55:47 +0000 (10:55 -0400)
src/com/iciql/TableDefinition.java
tests/com/iciql/test/AnnotationsTest.java
tests/com/iciql/test/ModelsTest.java

index a2b4f366e326bb8e995dbfa35f77ca90c6d5a1cc..1ecf394546138f79cb1ff8b3e172177d6519c99b 100644 (file)
@@ -294,7 +294,7 @@ public class TableDefinition<T> {
        private void addIndex(String name, IndexType type, List<String> columnNames) {\r
                IndexDefinition index = new IndexDefinition();\r
                if (StringUtils.isNullOrEmpty(name)) {\r
-                       index.indexName = tableName + "_" + indexes.size();\r
+                       index.indexName = tableName + "_idx_" + indexes.size();\r
                } else {\r
                        index.indexName = name;\r
                }\r
@@ -325,7 +325,7 @@ public class TableDefinition<T> {
        private void addConstraintUnique(String name, List<String> columnNames) {\r
                ConstraintUniqueDefinition constraint = new ConstraintUniqueDefinition();\r
                if (StringUtils.isNullOrEmpty(name)) {\r
-                       constraint.constraintName = tableName + "_" + constraintsUnique.size();\r
+                       constraint.constraintName = tableName + "_unique_" + constraintsUnique.size();\r
                } else {\r
                        constraint.constraintName = name;\r
                }\r
@@ -886,8 +886,8 @@ public class TableDefinition<T> {
                        try {\r
                                stat.executeUpdate();\r
                        } catch (IciqlException e) {\r
-                               // maybe we should check more error codes\r
-                               if (e.getIciqlCode() != IciqlException.CODE_OBJECT_ALREADY_EXISTS) {\r
+                               if (e.getIciqlCode() != IciqlException.CODE_OBJECT_ALREADY_EXISTS\r
+                                               && e.getIciqlCode() != IciqlException.CODE_DUPLICATE_KEY) {\r
                                        throw e;\r
                                }\r
                        }\r
@@ -901,8 +901,8 @@ public class TableDefinition<T> {
                        try {\r
                                stat.executeUpdate();\r
                        } catch (IciqlException e) {\r
-                               // maybe we should check more error codes\r
-                               if (e.getIciqlCode() != IciqlException.CODE_OBJECT_ALREADY_EXISTS) {\r
+                               if (e.getIciqlCode() != IciqlException.CODE_OBJECT_ALREADY_EXISTS\r
+                                               && e.getIciqlCode() != IciqlException.CODE_DUPLICATE_KEY) {\r
                                        throw e;\r
                                }\r
                        }\r
@@ -1090,7 +1090,7 @@ public class TableDefinition<T> {
                        ConstraintUpdateType updateType, ConstraintDeferrabilityType deferrabilityType) {\r
                ConstraintForeignKeyDefinition constraint = new ConstraintForeignKeyDefinition();\r
                if (StringUtils.isNullOrEmpty(name)) {\r
-                       constraint.constraintName = tableName + "_" + constraintsForeignKey.size();\r
+                       constraint.constraintName = tableName + "_fkey_" + constraintsForeignKey.size();\r
                } else {\r
                        constraint.constraintName = name;\r
                }\r
index ad229d9480f59479595db2b65a1b2ddb7620dca6..6aa75ad083608306b8798f82e6969244171ad5c1 100644 (file)
@@ -79,8 +79,8 @@ public class AnnotationsTest {
                        String index = rs.getString("INDEX_NAME");
                        list.add((col + ":" +  index).toLowerCase());
                }
-               assertTrue(list.contains("name:annotatedproduct_0"));
-               assertTrue(list.contains("cat:annotatedproduct_0"));
+               assertTrue(list.contains("name:annotatedproduct_idx_0"));
+               assertTrue(list.contains("cat:annotatedproduct_idx_0"));
                assertTrue(list.contains("name:nameidx"));
        }
 
index ceed7a96dfafbc5c09811e1d5f47bbfa7c782af4..c5ba27a3b002833b3b839833b0a740b59f31e43d 100644 (file)
@@ -123,20 +123,20 @@ public class ModelsTest {
                // a poor test, but a start
                String dbName = IciqlSuite.getDatabaseEngineName(db);
                if (dbName.equals("H2")) {
-                       assertEquals(1579, models.get(0).length());
+                       assertEquals(1587, models.get(0).length());
                } else if (dbName.startsWith("HSQL")) {
                        // HSQL uses Double instead of Float
-                       assertEquals(1583, models.get(0).length());
+                       assertEquals(1591, models.get(0).length());
                } else if (dbName.equals("Apache Derby")) {
                        // Derby uses java.sql.Timestamp not java.util.Date
                        // Derby uses username as schema name
-                       assertEquals(1593, models.get(0).length());
+                       assertEquals(1601, models.get(0).length());
                } else if (dbName.equals("PostgreSQL")) {
-                       assertEquals(1635, models.get(0).length());
+                       assertEquals(1643, models.get(0).length());
                } else if (dbName.equals("MySQL")) {
                        // MySQL uses timestamp default values like
                        // 0000-00-00 00:00:00 and CURRENT_TIMESTAMP
-                       assertEquals(1665, models.get(0).length());
+                       assertEquals(1673, models.get(0).length());
                } else {
                        // unknown database
                        assertEquals(0, models.get(0).length());