summaryrefslogtreecommitdiffstats
path: root/src/main/java/com/iciql/Db.java
diff options
context:
space:
mode:
authorJames Moger <james.moger@gitblit.com>2014-11-10 11:10:01 -0500
committerJames Moger <james.moger@gitblit.com>2014-11-10 21:46:37 -0500
commitc1d81bcdfc948b417964c6b69be2ee5801e5e1c9 (patch)
treeeab491b340179bdf24f7645977977ddb245455c6 /src/main/java/com/iciql/Db.java
parent4b9a61d0ef0fc2a9230a53a0ade45a20889aa9e3 (diff)
downloadiciql-c1d81bcdfc948b417964c6b69be2ee5801e5e1c9.tar.gz
iciql-c1d81bcdfc948b417964c6b69be2ee5801e5e1c9.zip
Add support for runtime Mode in the DataTypeAdapters
Diffstat (limited to 'src/main/java/com/iciql/Db.java')
-rw-r--r--src/main/java/com/iciql/Db.java61
1 files changed, 54 insertions, 7 deletions
diff --git a/src/main/java/com/iciql/Db.java b/src/main/java/com/iciql/Db.java
index 13c9260..794417e 100644
--- a/src/main/java/com/iciql/Db.java
+++ b/src/main/java/com/iciql/Db.java
@@ -41,6 +41,7 @@ import com.iciql.DbUpgrader.DefaultDbUpgrader;
import com.iciql.Iciql.IQTable;
import com.iciql.Iciql.IQVersion;
import com.iciql.Iciql.IQView;
+import com.iciql.Iciql.Mode;
import com.iciql.util.IciqlLogger;
import com.iciql.util.JdbcUtils;
import com.iciql.util.StringUtils;
@@ -64,6 +65,7 @@ public class Db implements AutoCloseable {
private static final Map<String, Class<? extends SQLDialect>> DIALECTS;
private final Connection conn;
+ private final Mode mode;
private final Map<Class<?>, TableDefinition<?>> classMap = Collections
.synchronizedMap(new HashMap<Class<?>, TableDefinition<?>>());
private final SQLDialect dialect;
@@ -88,8 +90,9 @@ public class Db implements AutoCloseable {
DIALECTS.put("SQLite", SQLDialectSQLite.class);
}
- private Db(Connection conn) {
+ private Db(Connection conn, Mode mode) {
this.conn = conn;
+ this.mode = mode;
String databaseName = null;
try {
DatabaseMetaData data = conn.getMetaData();
@@ -148,50 +151,81 @@ public class Db implements AutoCloseable {
}
public static Db open(String url) {
+ return open(url, Mode.PROD);
+ }
+
+ public static Db open(String url, Mode mode) {
try {
Connection conn = JdbcUtils.getConnection(null, url, null, null);
- return new Db(conn);
+ return new Db(conn, mode);
} catch (SQLException e) {
throw new IciqlException(e);
}
}
public static Db open(String url, String user, String password) {
+ return open(url, user, password, Mode.PROD);
+ }
+
+ public static Db open(String url, String user, String password, Mode mode) {
try {
Connection conn = JdbcUtils.getConnection(null, url, user, password);
- return new Db(conn);
+ return new Db(conn, mode);
} catch (SQLException e) {
throw new IciqlException(e);
}
}
public static Db open(String url, String user, char[] password) {
+ return open(url, user, password, Mode.PROD);
+ }
+
+ public static Db open(String url, String user, char[] password, Mode mode) {
try {
Connection conn = JdbcUtils.getConnection(null, url, user, password == null ? null : new String(password));
- return new Db(conn);
+ return new Db(conn, mode);
} catch (SQLException e) {
throw new IciqlException(e);
}
}
+ public static Db open(DataSource ds) {
+ return open(ds, Mode.PROD);
+ }
+
/**
* Create a new database instance using a data source. This method is fast,
* so that you can always call open() / close() on usage.
*
* @param ds
* the data source
+ * @param mode
+ * the runtime mode
* @return the database instance.
*/
- public static Db open(DataSource ds) {
+ public static Db open(DataSource ds, Mode mode) {
try {
- return new Db(ds.getConnection());
+ return new Db(ds.getConnection(), mode);
} catch (SQLException e) {
throw new IciqlException(e);
}
}
public static Db open(Connection conn) {
- return new Db(conn);
+ return open(conn, Mode.PROD);
+ }
+
+ public static Db open(Connection conn, Mode mode) {
+ return new Db(conn, mode);
+ }
+
+ /**
+ * Returns the Iciql runtime mode.
+ *
+ * @return the runtime mode
+ */
+ public Mode getMode() {
+ return mode;
}
/**
@@ -806,4 +840,17 @@ public class Db implements AutoCloseable {
return this.autoSavePoint;
}
+ /**
+ *
+ * @author James Moger
+ *
+ */
+ class NoExternalDaoStatements implements DaoStatementProvider {
+
+ @Override
+ public String getStatement(String idOrStatement) {
+ return idOrStatement;
+ }
+
+ }
}