@@ -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 | |||
@@ -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); |
@@ -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)); | |||
} |
@@ -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(); | |||
} |
@@ -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 |
@@ -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))) { |
@@ -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); |
@@ -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 |