summaryrefslogtreecommitdiffstats
path: root/src/main/java/com/iciql/Db.java
diff options
context:
space:
mode:
authorJames Moger <james.moger@gitblit.com>2014-11-06 15:34:50 -0500
committerJames Moger <james.moger@gitblit.com>2014-11-09 11:15:14 -0500
commit96d0aca9ff3b29be62bc6558af80fe115b646b88 (patch)
tree250e525f8975d44c95c5111bfb66d6d2cdd84919 /src/main/java/com/iciql/Db.java
parentdb0d58c22a0bd4fa2baf023428599757aa4db381 (diff)
downloadiciql-96d0aca9ff3b29be62bc6558af80fe115b646b88.tar.gz
iciql-96d0aca9ff3b29be62bc6558af80fe115b646b88.zip
Implement Dao proxy generation with annotated sql statement execution
This functionality is inspired by JDBI but is not based on it's implementation.
Diffstat (limited to 'src/main/java/com/iciql/Db.java')
-rw-r--r--src/main/java/com/iciql/Db.java18
1 files changed, 14 insertions, 4 deletions
diff --git a/src/main/java/com/iciql/Db.java b/src/main/java/com/iciql/Db.java
index ca43e63..13c9260 100644
--- a/src/main/java/com/iciql/Db.java
+++ b/src/main/java/com/iciql/Db.java
@@ -194,7 +194,17 @@ public class Db implements AutoCloseable {
return new Db(conn);
}
-
+ /**
+ * Returns a new DAO instance for the specified class.
+ *
+ * @param daoClass
+ * @return
+ * @throws Exception
+ */
+ @SuppressWarnings("resource")
+ public <X extends Dao> X open(Class<X> daoClass) {
+ return new DaoProxy<X>(this, daoClass).buildProxy();
+ }
/**
* Convenience function to avoid import statements in application code.
@@ -675,7 +685,7 @@ public class Db implements AutoCloseable {
*/
public ResultSet executeQuery(String sql, Object... args) {
try {
- if (args.length == 0) {
+ if (args == null || args.length == 0) {
return conn.createStatement().executeQuery(sql);
} else {
PreparedStatement stat = conn.prepareStatement(sql);
@@ -717,7 +727,7 @@ public class Db implements AutoCloseable {
public <T> List<T> executeQuery(Class<? extends T> modelClass, String sql, Object... args) {
ResultSet rs = null;
try {
- if (args.length == 0) {
+ if (args == null || args.length == 0) {
rs = conn.createStatement().executeQuery(sql);
} else {
PreparedStatement stat = conn.prepareStatement(sql);
@@ -748,7 +758,7 @@ public class Db implements AutoCloseable {
Statement stat = null;
try {
int updateCount;
- if (args.length == 0) {
+ if (args == null || args.length == 0) {
stat = conn.createStatement();
updateCount = stat.executeUpdate(sql);
} else {