diff options
author | James Moger <james.moger@gmail.com> | 2011-08-31 13:59:20 -0400 |
---|---|---|
committer | James Moger <james.moger@gmail.com> | 2011-08-31 13:59:20 -0400 |
commit | 7b9af6d430452934da91760205861183c12c0bb4 (patch) | |
tree | a24230b874407e46f9fc794b02e2ab3e1b8b89c6 | |
parent | 69f2302c957a737564988aff2d9ae7b66287fe9d (diff) | |
download | iciql-7b9af6d430452934da91760205861183c12c0bb4.tar.gz iciql-7b9af6d430452934da91760205861183c12c0bb4.zip |
Fixes to model generation. Fixes to default SQL dialect.
-rw-r--r-- | docs/05_releases.mkd | 2 | ||||
-rw-r--r-- | src/com/iciql/Db.java | 9 | ||||
-rw-r--r-- | src/com/iciql/DbInspector.java | 6 | ||||
-rw-r--r-- | src/com/iciql/ModelUtils.java | 11 | ||||
-rw-r--r-- | src/com/iciql/SQLDialectDefault.java | 9 | ||||
-rw-r--r-- | src/com/iciql/TableInspector.java | 2 | ||||
-rw-r--r-- | src/com/iciql/util/GenerateModels.java | 7 | ||||
-rw-r--r-- | tests/com/iciql/test/ModelsTest.java | 2 |
8 files changed, 37 insertions, 11 deletions
diff --git a/docs/05_releases.mkd b/docs/05_releases.mkd index 3d50a5b..9ccbbde 100644 --- a/docs/05_releases.mkd +++ b/docs/05_releases.mkd @@ -13,6 +13,8 @@ - Created additional Define static methods to bring interface configuration to near-parity with annotation configuration
- Documented POJO configuration option (limited subset of interface configuration)
- Fix to PostgreSQL dialect when creating autoincrement columns
+- Fix to default dialect when creating autoincrement columns
+- Added Db.open(url) method
### Older Releases
diff --git a/src/com/iciql/Db.java b/src/com/iciql/Db.java index af3c139..05d7f46 100644 --- a/src/com/iciql/Db.java +++ b/src/com/iciql/Db.java @@ -139,6 +139,15 @@ public class Db { }
}
+ public static Db open(String url) {
+ try {
+ Connection conn = JdbcUtils.getConnection(null, url, null, null);
+ return new Db(conn);
+ } catch (SQLException e) {
+ throw new IciqlException(e);
+ }
+ }
+
public static Db open(String url, String user, String password) {
try {
Connection conn = JdbcUtils.getConnection(null, url, user, password);
diff --git a/src/com/iciql/DbInspector.java b/src/com/iciql/DbInspector.java index 12124b8..acaceea 100644 --- a/src/com/iciql/DbInspector.java +++ b/src/com/iciql/DbInspector.java @@ -168,6 +168,12 @@ public class DbInspector { rs = getMetaData().getTables(null, s, null, new String[] { "TABLE" }); while (rs.next()) { String t = rs.getString("TABLE_NAME"); + if (t.charAt(0) == '"') { + t = t.substring(1); + } + if (t.charAt(t.length() - 1) == '"') { + t = t.substring(0, t.length() - 1); + } if (!t.equalsIgnoreCase(iciqlTables)) { tables.add(new TableInspector(s, t, dateTimeClass)); } diff --git a/src/com/iciql/ModelUtils.java b/src/com/iciql/ModelUtils.java index 522da2a..678e7af 100644 --- a/src/com/iciql/ModelUtils.java +++ b/src/com/iciql/ModelUtils.java @@ -223,8 +223,15 @@ class ModelUtils { // leading or trailing _ continue; } - className.append(Character.toUpperCase(chunk.charAt(0))); - className.append(chunk.substring(1).toLowerCase()); + String [] subchunks = StringUtils.arraySplit(chunk, ' ', false); + for (String subchunk : subchunks) { + if (subchunk.length() == 0) { + // leading or trailing space + continue; + } + className.append(Character.toUpperCase(subchunk.charAt(0))); + className.append(subchunk.substring(1).toLowerCase()); + } } return className.toString(); } diff --git a/src/com/iciql/SQLDialectDefault.java b/src/com/iciql/SQLDialectDefault.java index 58848c1..193079f 100644 --- a/src/com/iciql/SQLDialectDefault.java +++ b/src/com/iciql/SQLDialectDefault.java @@ -177,14 +177,11 @@ public class SQLDialectDefault implements SQLDialect { protected boolean prepareColumnDefinition(StatementBuilder buff, String dataType,
boolean isAutoIncrement, boolean isPrimaryKey) {
- boolean isIdentity = false;
- if (isAutoIncrement && isPrimaryKey) {
- buff.append(" IDENTITY");
- isIdentity = true;
- } else if (isAutoIncrement) {
+ buff.append(dataType);
+ if (isAutoIncrement) {
buff.append(" AUTO_INCREMENT");
}
- return isIdentity;
+ return false;
}
@Override
diff --git a/src/com/iciql/TableInspector.java b/src/com/iciql/TableInspector.java index ce94c1b..9b67ac3 100644 --- a/src/com/iciql/TableInspector.java +++ b/src/com/iciql/TableInspector.java @@ -153,7 +153,7 @@ public class TableInspector { col.isAutoIncrement = n.intValue() > 0; } } catch (SQLException s) { - throw s; +// throw s; } if (primaryKeys.size() == 1) { if (col.name.equalsIgnoreCase(primaryKeys.get(0))) { diff --git a/src/com/iciql/util/GenerateModels.java b/src/com/iciql/util/GenerateModels.java index ce98105..1a6270f 100644 --- a/src/com/iciql/util/GenerateModels.java +++ b/src/com/iciql/util/GenerateModels.java @@ -133,7 +133,12 @@ public class GenerateModels { Connection conn = null; try { conn = DriverManager.getConnection(url, user, password); - Db db = Db.open(url, user, password.toCharArray()); + Db db; + if (password == null) { + db = Db.open(url, user, (String) null); + } else { + db = Db.open(url, user, password.toCharArray()); + } DbInspector inspector = new DbInspector(db); List<String> models = inspector.generateModel(schema, table, packageName, annotateSchema, trimStrings); diff --git a/tests/com/iciql/test/ModelsTest.java b/tests/com/iciql/test/ModelsTest.java index c5569d6..3900437 100644 --- a/tests/com/iciql/test/ModelsTest.java +++ b/tests/com/iciql/test/ModelsTest.java @@ -132,7 +132,7 @@ public class ModelsTest { // Derby uses username as schema name assertEquals(1489, models.get(0).length()); } else if (dbName.equals("PostgreSQL")) { - assertEquals(1514, models.get(0).length()); + assertEquals(1531, models.get(0).length()); } else if (dbName.equals("MySQL")) { // MySQL uses timestamp default values like // 0000-00-00 00:00:00 and CURRENT_TIMESTAMP |