Permalink
Browse files

Pull QueryResultImpl and CoreFinder into the runtime project

  • Loading branch information...
akeefer committed Feb 9, 2012
1 parent d2015b7 commit 4c97436234cab770179534af5a020afe507aa86a
@@ -3,10 +3,13 @@
import gw.internal.gosu.parser.expressions.NullExpression;
import gw.lang.reflect.*;
import gw.lang.reflect.java.JavaTypes;
+import gw.util.concurrent.LockingLazyVar;
import tosa.CachedDBObject;
import tosa.api.*;
import tosa.dbmd.DBColumnImpl;
+import java.util.Map;
+
/**
* Created by IntelliJ IDEA.
* User: alan
@@ -18,115 +21,140 @@
public static final String ID_COLUMN = "id";
+ private LockingLazyVar<DBTypeInfoDelegate> _delegate = new LockingLazyVar<DBTypeInfoDelegate>() {
+ @Override
+ protected DBTypeInfoDelegate init() {
+ return (DBTypeInfoDelegate) ReflectUtil.construct("tosa.impl.loader.DBTypeInfoDelegateImpl");
+ }
+ };
+
+ private DBTypeInfoDelegate getDelegate() {
+ return _delegate.get();
+ }
+
public DBTypeInfo(IDBType dbType) {
super(dbType);
-
- delegateStaticMethods(TypeSystem.getByFullName("tosa.loader.DBTypeDelegate"));
-
-// createMethod(
-// "fromId",
-// params(param("id", JavaTypes.pLONG(), "the id")),
-// getDBType(),
-// Modifiers.PublicStatic,
-// "Foo",
-// new IMethodCallHandler() {
-// @Override
-// public Object handleCall(Object context, Object... params) {
-// return _delegate.fromId(params[0]);
-// }
-// });
-//
-// createMethod(
-// "count",
-// params(param("sql", JavaTypes.STRING(), "the sql for the count query"),
-// param("params", JavaTypes.MAP().getParameterizedType(JavaTypes.STRING(), JavaTypes.OBJECT()), "parameters", NullExpression.instance())),
-// JavaTypes.pLONG(),
-// Modifiers.PublicStatic,
-// "Foo",
-// new IMethodCallHandler() {
-// @Override
-// public Object handleCall(Object context, Object... params) {
-// return _delegate.count(params[0], params[1]);
-// }
-// });
-//
-// createMethod(
-// "countAll",
-// params(),
-// JavaTypes.pLONG(),
-// Modifiers.PublicStatic,
-// "Foo",
-// new IMethodCallHandler() {
-// @Override
-// public Object handleCall(Object context, Object... params) {
-// return _delegate.countAll();
-// }
-// });
-//
-// createMethod(
-// "countWhere",
-// params(param("sql", JavaTypes.STRING(), "the sql for the WHERE clause in the count query"),
-// param("params", JavaTypes.MAP().getParameterizedType(JavaTypes.STRING(), JavaTypes.OBJECT()), "parameters", NullExpression.instance())),
-// JavaTypes.pLONG(),
-// Modifiers.PublicStatic,
-// "Foo",
-// new IMethodCallHandler() {
-// @Override
-// public Object handleCall(Object context, Object... params) {
-// return _delegate.countWhere(params[0], params[1]);
-// }
-// });
-//
-// createMethod(
-// "countLike",
-// params(param("template", getDBType(), "the template to use in forming the WHERE clause for the count query")),
-// JavaTypes.pLONG(),
-// Modifiers.PublicStatic,
-// "Foo",
-// new IMethodCallHandler() {
-// @Override
-// public Object handleCall(Object context, Object... params) {
-// return _delegate.countLike(params[0]);
-// }
-// });
- /*
- static function fromId(dbType : IDBType, id : long) : IDBObject {
- return new CoreFinder(dbType).fromId(id)
- }
-
- static function count(dbType : IDBType, sql : String, params : Map<String, Object> = null) : long {
- return new CoreFinder(dbType).count(sql, params)
- }
-
- static function countAll(dbType : IDBType) : long {
- return new CoreFinder(dbType).countAll()
- }
-
- static function countWhere(dbType : IDBType, sql : String, params : Map<String, Object> = null) : long {
- return new CoreFinder(dbType).countWhere(sql, params)
- }
-
- static function countLike(dbType : IDBType, template: IDBObject) : long {
- return new CoreFinder(dbType).countLike(template)
- }
-
- static function select(dbType : IDBType, sql : String, params : Map<String, Object> = null) : QueryResult<IDBObject> {
- return new CoreFinder(dbType).select(sql, params)
- }
-
- static function selectAll(dbType : IDBType) : QueryResult<IDBObject> {
- return new CoreFinder(dbType).selectAll()
- }
-
- static function selectWhere(dbType : IDBType, sql : String, params : Map<String, Object> = null) : QueryResult<IDBObject> {
- return new CoreFinder(dbType).selectWhere(sql, params)
- }
-
- static function selectLike(dbType : IDBType, template : IDBObject) : QueryResult<IDBObject> {
- return new CoreFinder(dbType).selectLike(template)
- }*/
-
+ createMethod(
+ "fromId",
+ params(param("id", JavaTypes.pLONG(), "the id of the object to find")),
+ getDBType(),
+ Modifiers.PublicStatic,
+ "TODO",
+ new IMethodCallHandler() {
+ @Override
+ public Object handleCall(Object context, Object... params) {
+ return getDelegate().fromId(getDBType(), (Long) params[0]);
+ }
+ });
+
+ createMethod(
+ "count",
+ params(param("sql", JavaTypes.STRING(), "the sql for the count query"),
+ param("params", JavaTypes.MAP().getParameterizedType(JavaTypes.STRING(), JavaTypes.OBJECT()), "parameters", NullExpression.instance())),
+ JavaTypes.pLONG(),
+ Modifiers.PublicStatic,
+ "TODO",
+ new IMethodCallHandler() {
+ @Override
+ public Object handleCall(Object context, Object... params) {
+ return getDelegate().count(getDBType(), (String) params[0], (Map<String, Object>) params[1]);
+ }
+ });
+
+ createMethod(
+ "countAll",
+ params(),
+ JavaTypes.pLONG(),
+ Modifiers.PublicStatic,
+ "TODO",
+ new IMethodCallHandler() {
+ @Override
+ public Object handleCall(Object context, Object... params) {
+ return getDelegate().countAll(getDBType());
+ }
+ });
+
+ createMethod(
+ "countWhere",
+ params(param("sql", JavaTypes.STRING(), "the sql for the WHERE clause in the count query"),
+ param("params", JavaTypes.MAP().getParameterizedType(JavaTypes.STRING(), JavaTypes.OBJECT()), "parameters", NullExpression.instance())),
+ JavaTypes.pLONG(),
+ Modifiers.PublicStatic,
+ "TODO",
+ new IMethodCallHandler() {
+ @Override
+ public Object handleCall(Object context, Object... params) {
+ return getDelegate().countWhere(getDBType(), (String) params[0], (Map<String, Object>) params[1]);
+ }
+ });
+
+ createMethod(
+ "countLike",
+ params(param("template", getDBType(), "the template to use in forming the WHERE clause for the count query")),
+ JavaTypes.pLONG(),
+ Modifiers.PublicStatic,
+ "TODO",
+ new IMethodCallHandler() {
+ @Override
+ public Object handleCall(Object context, Object... params) {
+ return getDelegate().countLike(getDBType(), (IDBObject) params[0]);
+ }
+ });
+
+ createMethod(
+ "select",
+ params(param("sql", JavaTypes.STRING(), "the sql for the query"),
+ param("params", JavaTypes.MAP().getParameterizedType(JavaTypes.STRING(), JavaTypes.OBJECT()), "parameters", NullExpression.instance())),
+ TypeSystem.getByFullName("tosa.api.QueryResult").getParameterizedType(getDBType()),
+ Modifiers.PublicStatic,
+ "TODO",
+ new IMethodCallHandler() {
+ @Override
+ public Object handleCall(Object context, Object... params) {
+ return getDelegate().select(getDBType(), (String) params[0], (Map<String, Object>) params[1]);
+ }
+ });
+
+ createMethod(
+ "selectAll",
+ params(),
+ TypeSystem.getByFullName("tosa.api.QueryResult").getParameterizedType(getDBType()),
+ Modifiers.PublicStatic,
+ "TODO",
+ new IMethodCallHandler() {
+ @Override
+ public Object handleCall(Object context, Object... params) {
+ return getDelegate().selectAll(getDBType());
+ }
+ });
+
+ createMethod(
+ "selectWhere",
+ params(param("sql", JavaTypes.STRING(), "the sql for the WHERE clause of the query"),
+ param("params", JavaTypes.MAP().getParameterizedType(JavaTypes.STRING(), JavaTypes.OBJECT()), "parameters", NullExpression.instance())),
+ TypeSystem.getByFullName("tosa.api.QueryResult").getParameterizedType(getDBType()),
+ Modifiers.PublicStatic,
+ "TODO",
+ new IMethodCallHandler() {
+ @Override
+ public Object handleCall(Object context, Object... params) {
+ return getDelegate().selectWhere(getDBType(), (String) params[0], (Map<String, Object>) params[1]);
+ }
+ });
+
+ createMethod(
+ "selectLike",
+ params(param("template", getDBType(), "the template to use in forming the WHERE clause for the query")),
+ TypeSystem.getByFullName("tosa.api.QueryResult").getParameterizedType(getDBType()),
+ Modifiers.PublicStatic,
+ "TODO",
+ new IMethodCallHandler() {
+ @Override
+ public Object handleCall(Object context, Object... params) {
+ return getDelegate().selectLike(getDBType(), (IDBObject) params[0]);
+ }
+ });
for (IDBColumn column : dbType.getTable().getColumns()) {
// TODO - AHK - Ideally this cast wouldn't be necessary
@@ -0,0 +1,33 @@
+package tosa.loader;
+
+import tosa.api.IDBObject;
+
+import java.util.Map;
+
+/**
+ * Created by IntelliJ IDEA.
+ * User: Alan
+ * Date: 2/9/12
+ * Time: 12:58 AM
+ * To change this template use File | Settings | File Templates.
+ */
+public interface DBTypeInfoDelegate {
+
+ IDBObject fromId(IDBType dbType, long id);
+
+ long count(IDBType dbType, String sql, Map<String, Object> params);
+
+ long countAll(IDBType dbType);
+
+ long countWhere(IDBType dbType, String sql, Map<String, Object> params);
+
+ long countLike(IDBType dbType, IDBObject template);
+
+ Object select(IDBType dbType, String sql, Map<String, Object> params);
+
+ Object selectAll(IDBType dbType);
+
+ Object selectWhere(IDBType dbType, String sql, Map<String, Object> params);
+
+ Object selectLike(IDBType dbType, IDBObject template);
+}
@@ -8,7 +8,7 @@ uses gw.lang.reflect.features.PropertyReference
uses tosa.loader.Util
uses java.util.Arrays
uses java.lang.IllegalStateException
-uses tosa.impl.query.QueryResultImpl
+uses tosa.impl.QueryResultImpl
uses java.sql.ResultSet
uses tosa.CachedDBObject
@@ -1,4 +1,4 @@
-package tosa.impl.query
+package tosa.impl
uses tosa.api.QueryResult
uses tosa.api.IPreparedStatementParameter
@@ -0,0 +1,54 @@
+package tosa.impl.loader
+
+uses tosa.loader.DBTypeInfoDelegate
+uses tosa.loader.IDBType
+uses tosa.api.IDBObject
+uses java.util.Map
+uses tosa.api.CoreFinder
+
+/**
+ * Created by IntelliJ IDEA.
+ * User: Alan
+ * Date: 2/9/12
+ * Time: 1:18 AM
+ * To change this template use File | Settings | File Templates.
+ */
+class DBTypeInfoDelegateImpl implements DBTypeInfoDelegate {
+
+ override function fromId(dbType : IDBType, id : long) : IDBObject {
+ return new CoreFinder(dbType).fromId(id)
+ }
+
+ override function count(dbType : IDBType, sql : String, params : Map<String, Object>) : long {
+ return new CoreFinder(dbType).count(sql, params)
+ }
+
+ override function countAll(dbType : IDBType) : long {
+ return new CoreFinder(dbType).countAll()
+ }
+
+ override function countWhere(dbType : IDBType, sql : String, params : Map<String, Object>) : long {
+ return new CoreFinder(dbType).countWhere(sql, params)
+ }
+
+ override function countLike(dbType : IDBType, template : IDBObject) : long {
+ return new CoreFinder(dbType).countLike(template)
+ }
+
+ override function select(dbType : IDBType, sql : String, params : Map<String, Object>) : java.lang.Object {
+ return new CoreFinder(dbType).select(sql, params)
+ }
+
+ override function selectAll(dbType : IDBType) : java.lang.Object {
+ return new CoreFinder(dbType).selectAll()
+ }
+
+ override function selectWhere(dbType : IDBType, sql : String, params : Map<String, Object>) : java.lang.Object {
+ return new CoreFinder(dbType).selectWhere(sql, params)
+ }
+
+ override function selectLike(dbType : IDBType, template : IDBObject) : java.lang.Object {
+ return new CoreFinder(dbType).selectLike(template)
+ }
+
+}
@@ -9,7 +9,7 @@ uses org.junit.runners.Suite.SuiteClasses
@SuiteClasses({
tosa.impl.JoinArrayEntityCollectionImplTest,
tosa.impl.ReverseFkEntityCollectionImplTest,
- tosa.impl.query.QueryResultImplTest,
+ tosa.impl.QueryResultImplTest,
tosa.loader.DatabaseAccessTypeTest,
tosa.loader.DBTypeInfoSelectTest,
tosa.loader.DBTypeInfoTest,
@@ -1,4 +1,4 @@
-package tosa.impl.query
+package tosa.impl
uses tosa.TosaDBTestBase
uses org.junit.Test
Oops, something went wrong.

0 comments on commit 4c97436

Please sign in to comment.