gdamour 2005/02/02 07:53:03
Modified: modules/core/src/java/org/openejb/entity/cmp
CollectionValuedSelect.java SetValuedSelect.java
SingleValuedSelect.java
Log:
Select methods should be added to the instance map and not to the interface
one.
Add a deployment test to verify that finders and selects are properly
hooked in and invokable.
Revision Changes Path
1.2 +25 -4
openejb/modules/core/src/java/org/openejb/entity/cmp/CollectionValuedSelect.java
Index: CollectionValuedSelect.java
===================================================================
RCS file:
/home/projects/openejb/scm/openejb/modules/core/src/java/org/openejb/entity/cmp/CollectionValuedSelect.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- CollectionValuedSelect.java 7 Jan 2005 06:37:52 -0000 1.1
+++ CollectionValuedSelect.java 2 Feb 2005 12:53:02 -0000 1.2
@@ -47,17 +47,38 @@
*/
package org.openejb.entity.cmp;
+import java.util.ArrayList;
+import java.util.Collection;
+
+import javax.ejb.FinderException;
+
+import org.apache.geronimo.core.service.SimpleInvocationResult;
+import org.tranql.field.Row;
+import org.tranql.ql.QueryException;
+import org.tranql.query.CollectionResultHandler;
import org.tranql.query.QueryCommandView;
+
/**
*
*
* @version $Revision$ $Date$
*/
-public class CollectionValuedSelect extends CollectionValuedFinder {
+public class CollectionValuedSelect implements InstanceOperation {
+ private final QueryCommandView commandView;
- public CollectionValuedSelect(QueryCommandView queryView) {
- super(queryView, queryView);
+ public CollectionValuedSelect(QueryCommandView commandView) {
+ this.commandView = commandView;
}
+ public Object invokeInstance(CMPInstanceContext ctx, Object[] args) {
+ Collection results = new ArrayList();
+ try {
+ CollectionResultHandler handler = new
CollectionResultHandler(commandView.getView()[0]);
+ commandView.getQueryCommand().execute(handler, new Row(args),
results);
+ } catch (QueryException e) {
+ return new FinderException(e.getMessage()).initCause(e);
+ }
+ return results;
+ }
}
1.2 +27 -5
openejb/modules/core/src/java/org/openejb/entity/cmp/SetValuedSelect.java
Index: SetValuedSelect.java
===================================================================
RCS file:
/home/projects/openejb/scm/openejb/modules/core/src/java/org/openejb/entity/cmp/SetValuedSelect.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- SetValuedSelect.java 7 Jan 2005 06:37:52 -0000 1.1
+++ SetValuedSelect.java 2 Feb 2005 12:53:02 -0000 1.2
@@ -47,6 +47,17 @@
*/
package org.openejb.entity.cmp;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.HashSet;
+import java.util.Set;
+
+import javax.ejb.FinderException;
+
+import org.apache.geronimo.core.service.SimpleInvocationResult;
+import org.tranql.field.Row;
+import org.tranql.ql.QueryException;
+import org.tranql.query.CollectionResultHandler;
import org.tranql.query.QueryCommandView;
/**
@@ -54,10 +65,21 @@
*
* @version $Revision$ $Date$
*/
-public class SetValuedSelect extends SetValuedFinder {
+public class SetValuedSelect implements InstanceOperation {
+ private final QueryCommandView commandView;
- public SetValuedSelect(QueryCommandView queryView) {
- super(queryView, queryView);
+ public SetValuedSelect(QueryCommandView commandView) {
+ this.commandView = commandView;
+ }
+
+ public Object invokeInstance(CMPInstanceContext ctx, Object[] args) {
+ Set results = new HashSet();
+ try {
+ CollectionResultHandler handler = new
CollectionResultHandler(commandView.getView()[0]);
+ commandView.getQueryCommand().execute(handler, new Row(args),
results);
+ } catch (QueryException e) {
+ return new FinderException(e.getMessage()).initCause(e);
+ }
+ return results;
}
-
}
1.2 +46 -4
openejb/modules/core/src/java/org/openejb/entity/cmp/SingleValuedSelect.java
Index: SingleValuedSelect.java
===================================================================
RCS file:
/home/projects/openejb/scm/openejb/modules/core/src/java/org/openejb/entity/cmp/SingleValuedSelect.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- SingleValuedSelect.java 7 Jan 2005 06:37:52 -0000 1.1
+++ SingleValuedSelect.java 2 Feb 2005 12:53:03 -0000 1.2
@@ -47,17 +47,59 @@
*/
package org.openejb.entity.cmp;
+import javax.ejb.FinderException;
+import javax.ejb.ObjectNotFoundException;
+
+import org.tranql.field.FieldTransform;
+import org.tranql.field.FieldTransformException;
+import org.tranql.field.Row;
+import org.tranql.ql.QueryException;
import org.tranql.query.QueryCommandView;
+import org.tranql.query.ResultHandler;
/**
*
*
* @version $Revision$ $Date$
*/
-public class SingleValuedSelect extends SingleValuedFinder {
+public class SingleValuedSelect implements InstanceOperation {
+ private static final Object NODATA = new Object();
+
+ private final QueryCommandView commandView;
+
+ public SingleValuedSelect(QueryCommandView commandView) {
+ this.commandView = commandView;
+ }
- public SingleValuedSelect(QueryCommandView queryView) {
- super(queryView, queryView);
+ public Object invokeInstance(CMPInstanceContext ctx, Object[] args)
throws Exception {
+ Object o;
+ try {
+ SingleValuedResultHandler handler = new
SingleValuedResultHandler(commandView.getView()[0]);
+ o = commandView.getQueryCommand().execute(handler, new
Row(args), NODATA);
+ } catch (QueryException e) {
+ return new FinderException(e.getMessage()).initCause(e);
+ }
+ if (NODATA == o) {
+ throw new ObjectNotFoundException();
+ }
+ return o;
}
+ private class SingleValuedResultHandler implements ResultHandler {
+ private final FieldTransform accessor;
+ public SingleValuedResultHandler(FieldTransform accessor) {
+ this.accessor = accessor;
+ }
+
+ public Object fetched(Row row, Object arg) throws QueryException {
+ if (arg == NODATA) {
+ try {
+ return accessor.get(row);
+ } catch (FieldTransformException e) {
+ throw new QueryException(e);
+ }
+ }
+ return new FinderException("More than one row returned from
single valued select.");
+ }
+ }
}