From 86ccd88f1e06476c2f9c8f917a223c57399c18ba Mon Sep 17 00:00:00 2001 From: James Moger Date: Tue, 18 Sep 2012 08:22:50 -0400 Subject: [PATCH] Fixed password bug in model generator tool (issue 7) --- docs/05_releases.mkd | 4 ++++ src/com/iciql/Db.java | 22 ++++++++++------------ src/com/iciql/util/GenerateModels.java | 8 +------- 3 files changed, 15 insertions(+), 19 deletions(-) diff --git a/docs/05_releases.mkd b/docs/05_releases.mkd index c31a8b8..fcaea77 100644 --- a/docs/05_releases.mkd +++ b/docs/05_releases.mkd @@ -4,6 +4,10 @@ **%VERSION%** ([zip](http://code.google.com/p/iciql/downloads/detail?name=%ZIP%)|[jar](http://code.google.com/p/iciql/downloads/detail?name=%JAR%))   *released %BUILDDATE%* +- Fixed password bug in model generator (issue 7) + +**1.1.0**   *released 2012-08-20* + - All bulk operations (insert all, update all, delete all) now use JDBC savepoints to ensure atomicity of the transaction **1.0.0**   *released 2012-07-14* diff --git a/src/com/iciql/Db.java b/src/com/iciql/Db.java index 6e23a59..d436b8d 100644 --- a/src/com/iciql/Db.java +++ b/src/com/iciql/Db.java @@ -31,7 +31,6 @@ import java.util.HashMap; import java.util.HashSet; import java.util.List; import java.util.Map; -import java.util.Properties; import java.util.Set; import javax.sql.DataSource; @@ -158,6 +157,15 @@ public class Db { throw new IciqlException(e); } } + + public static Db open(String url, String user, char[] password) { + try { + Connection conn = JdbcUtils.getConnection(null, url, user, password == null ? null : new String(password)); + return new Db(conn); + } catch (SQLException e) { + throw new IciqlException(e); + } + } /** * Create a new database instance using a data source. This method is fast, @@ -179,17 +187,7 @@ public class Db { return new Db(conn); } - public static Db open(String url, String user, char[] password) { - try { - Properties prop = new Properties(); - prop.setProperty("user", user); - prop.put("password", password); - Connection conn = JdbcUtils.getConnection(null, url, prop); - return new Db(conn); - } catch (SQLException e) { - throw new IciqlException(e); - } - } + /** * Convenience function to avoid import statements in application code. diff --git a/src/com/iciql/util/GenerateModels.java b/src/com/iciql/util/GenerateModels.java index 1a6270f..eac9f6c 100644 --- a/src/com/iciql/util/GenerateModels.java +++ b/src/com/iciql/util/GenerateModels.java @@ -24,8 +24,6 @@ import java.io.IOException; import java.io.PrintStream; import java.io.PrintWriter; import java.io.Writer; -import java.sql.Connection; -import java.sql.DriverManager; import java.sql.SQLException; import java.util.List; import java.util.regex.Matcher; @@ -130,14 +128,12 @@ public class GenerateModels { public static void execute(String url, String user, String password, String schema, String table, String packageName, String folder, boolean annotateSchema, boolean trimStrings) throws SQLException { - Connection conn = null; try { - conn = DriverManager.getConnection(url, user, password); Db db; if (password == null) { db = Db.open(url, user, (String) null); } else { - db = Db.open(url, user, password.toCharArray()); + db = Db.open(url, user, password); } DbInspector inspector = new DbInspector(db); List models = inspector.generateModel(schema, table, packageName, annotateSchema, @@ -164,8 +160,6 @@ public class GenerateModels { } } catch (IOException io) { throw new SQLException("could not generate model", io); - } finally { - JdbcUtils.closeSilently(conn); } } -- 2.39.5