summaryrefslogtreecommitdiffstats
path: root/src/com
diff options
context:
space:
mode:
authorJames Moger <james.moger@gmail.com>2012-09-18 08:22:50 -0400
committerJames Moger <james.moger@gmail.com>2012-09-18 08:22:50 -0400
commit86ccd88f1e06476c2f9c8f917a223c57399c18ba (patch)
tree31f21bd8a3bc8729c0c04c0ed9d4afb8debba9c5 /src/com
parent6d73bccdc39d9ee70fc744424778271a2509403e (diff)
downloadiciql-86ccd88f1e06476c2f9c8f917a223c57399c18ba.tar.gz
iciql-86ccd88f1e06476c2f9c8f917a223c57399c18ba.zip
Fixed password bug in model generator tool (issue 7)
Diffstat (limited to 'src/com')
-rw-r--r--src/com/iciql/Db.java22
-rw-r--r--src/com/iciql/util/GenerateModels.java8
2 files changed, 11 insertions, 19 deletions
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<String> 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);
}
}