User: dsundstrom
Date: 01/08/26 12:37:10
Modified: src/main/org/jboss/ejb/plugins/cmp/jdbc/bridge
JDBCAbstractCMPFieldBridge.java
JDBCCMPFieldBridge.java JDBCEntityBridge.java
JDBCSelectorBridge.java
Log:
Added ejbSelect query support.
Revision Changes Path
1.4 +30 -17
jboss/src/main/org/jboss/ejb/plugins/cmp/jdbc/bridge/JDBCAbstractCMPFieldBridge.java
Index: JDBCAbstractCMPFieldBridge.java
===================================================================
RCS file:
/cvsroot/jboss/jboss/src/main/org/jboss/ejb/plugins/cmp/jdbc/bridge/JDBCAbstractCMPFieldBridge.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- JDBCAbstractCMPFieldBridge.java 2001/08/03 17:15:47 1.3
+++ JDBCAbstractCMPFieldBridge.java 2001/08/26 19:37:10 1.4
@@ -41,7 +41,7 @@
* One for each entity bean cmp field.
*
* @author <a href="mailto:[EMAIL PROTECTED]">Dain Sundstrom</a>
- * @version $Revision: 1.3 $
+ * @version $Revision: 1.4 $
*/
public abstract class JDBCAbstractCMPFieldBridge implements JDBCCMPFieldBridge {
protected JDBCStoreManager manager;
@@ -190,13 +190,14 @@
public int loadInstanceResults(ResultSet rs, int parameterIndex,
EntityEnterpriseContext ctx) {
try {
- Object value = null; //will be set in loop below
- Class[] javaTypes = getJDBCType().getJavaTypes();
- for(int i=0; i<javaTypes.length; i++) {
- Object columnValue = JDBCUtil.getResult(log, rs,
parameterIndex++, javaTypes[i]);
- value = getJDBCType().setColumnValue(i, value,
columnValue);
- }
- setInstanceValue(ctx, value);
+ // value of this field, will be filled in below
+ Object[] argumentRef = new Object[1];
+
+ // load the cmp field value from the result set
+ parameterIndex = loadArgumentResults(rs, parameterIndex,
argumentRef);
+
+ // set the value into the context
+ setInstanceValue(ctx, argumentRef[0]);
return parameterIndex;
} catch(EJBException e) {
// to avoid double wrap of EJBExceptions
@@ -209,28 +210,40 @@
}
public int loadPrimaryKeyResults(ResultSet rs, int parameterIndex, Object[]
pkRef) throws IllegalArgumentException {
+ // value of this field, will be filled in below
+ Object[] argumentRef = new Object[1];
+
+ // load the cmp field value from the result set
+ parameterIndex = loadArgumentResults(rs, parameterIndex, argumentRef);
+
+ // set the value of this field into the pk
+ pkRef[0] = setPrimaryKeyValue(pkRef[0], argumentRef[0]);
+
+ // retrun the updated parameterIndex
+ return parameterIndex;
+ }
+
+ public int loadArgumentResults(ResultSet rs, int parameterIndex, Object[]
argumentRef) throws IllegalArgumentException {
try {
// value of this field, will be filled in below
- Object value = null;
+ // set the value of this field into the pk
+ argumentRef[0] = null;
// update the value from the result set
Class[] javaTypes = getJDBCType().getJavaTypes();
for(int i=0; i<javaTypes.length; i++) {
Object columnValue = JDBCUtil.getResult(log, rs,
parameterIndex++, javaTypes[i]);
- value = getJDBCType().setColumnValue(i, value,
columnValue);
+ argumentRef[0] = getJDBCType().setColumnValue(i,
argumentRef[0], columnValue);
}
-
- // set the value of this field into the pk
- pkRef[0] = setPrimaryKeyValue(pkRef[0], value);
-
+
// retrun the updated parameterIndex
return parameterIndex;
} catch(SQLException e) {
// Non recoverable internal exception
- throw new EJBException("Internal error getting results for
primary key field member " + getFieldName() + ": " + e);
+ throw new EJBException("Internal error getting results for
field member " + getFieldName() + ": " + e);
}
- }
-
+ }
+
protected final boolean changed(Object current, Object old) {
return
(current == null && old != null) || // TRUE if I am null and
I wasn't before
1.4 +7 -3
jboss/src/main/org/jboss/ejb/plugins/cmp/jdbc/bridge/JDBCCMPFieldBridge.java
Index: JDBCCMPFieldBridge.java
===================================================================
RCS file:
/cvsroot/jboss/jboss/src/main/org/jboss/ejb/plugins/cmp/jdbc/bridge/JDBCCMPFieldBridge.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- JDBCCMPFieldBridge.java 2001/08/03 17:15:47 1.3
+++ JDBCCMPFieldBridge.java 2001/08/26 19:37:10 1.4
@@ -40,7 +40,7 @@
* One for each entity bean cmp field.
*
* @author <a href="mailto:[EMAIL PROTECTED]">Dain Sundstrom</a>
- * @version $Revision: 1.3 $
+ * @version $Revision: 1.4 $
*/
public interface JDBCCMPFieldBridge extends CMPFieldBridge {
/**
@@ -85,5 +85,9 @@
* Loads the data from result set into the primary key object.
*/
public int loadPrimaryKeyResults(ResultSet rs, int parameterIndex, Object[]
pkRef) throws IllegalArgumentException;
-}
-
\ No newline at end of file
+
+ /**
+ * Loads the value of this cmp field from result set into argument referance.
+ */
+ public int loadArgumentResults(ResultSet rs, int parameterIndex, Object[]
argumentRef) throws IllegalArgumentException;
+}
\ No newline at end of file
1.7 +20 -3
jboss/src/main/org/jboss/ejb/plugins/cmp/jdbc/bridge/JDBCEntityBridge.java
Index: JDBCEntityBridge.java
===================================================================
RCS file:
/cvsroot/jboss/jboss/src/main/org/jboss/ejb/plugins/cmp/jdbc/bridge/JDBCEntityBridge.java,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -r1.6 -r1.7
--- JDBCEntityBridge.java 2001/08/18 16:03:35 1.6
+++ JDBCEntityBridge.java 2001/08/26 19:37:10 1.7
@@ -33,6 +33,8 @@
import org.jboss.ejb.plugins.cmp.jdbc.metadata.JDBCEntityMetaData;
import org.jboss.ejb.plugins.cmp.jdbc.metadata.JDBCCMPFieldMetaData;
+import org.jboss.ejb.plugins.cmp.jdbc.metadata.JDBCQlQueryMetaData;
+import org.jboss.ejb.plugins.cmp.jdbc.metadata.JDBCQueryMetaData;
import org.jboss.ejb.plugins.cmp.jdbc.metadata.JDBCRelationshipRoleMetaData;
import org.jboss.proxy.Proxies;
@@ -51,7 +53,7 @@
* One per cmp entity bean type.
*
* @author <a href="mailto:[EMAIL PROTECTED]">Dain Sundstrom</a>
- * @version $Revision: 1.6 $
+ * @version $Revision: 1.7 $
*/
public class JDBCEntityBridge implements EntityBridge {
protected JDBCEntityMetaData metadata;
@@ -65,6 +67,7 @@
protected Map cmrFieldsByName;
protected JDBCSelectorBridge[] selectors;
+ protected Map selectorsByMethod;
protected JDBCCMPFieldBridge[] eagerLoadFields;
protected ArrayList lazyLoadGroups;
@@ -177,8 +180,22 @@
}
}
- protected void loadSelectors(JDBCEntityMetaData metadata) {
- selectors = new JDBCSelectorBridge[0];
+ protected void loadSelectors(JDBCEntityMetaData metadata) throws
DeploymentException {
+ // Don't know if this is the best way to do this. Another way would
be to
+ // deligate seletors to the JDBCFindEntitiesCommand, but this is
easier now.
+
+ selectorsByMethod = new HashMap(metadata.getQueries().size());
+ Iterator definedFinders =
manager.getMetaData().getQueries().iterator();
+ while(definedFinders.hasNext()) {
+ JDBCQueryMetaData q = (JDBCQueryMetaData)definedFinders.next();
+
+ if(q instanceof JDBCQlQueryMetaData) {
+ selectorsByMethod.put(q.getMethod(), new
JDBCSelectorBridge(manager, (JDBCQlQueryMetaData)q));
+ }
+ }
+
+ selectors = new JDBCSelectorBridge[selectorsByMethod.values().size()];
+ selectors =
(JDBCSelectorBridge[])selectorsByMethod.values().toArray(selectors);
}
public String getEntityName() {
1.3 +56 -7
jboss/src/main/org/jboss/ejb/plugins/cmp/jdbc/bridge/JDBCSelectorBridge.java
Index: JDBCSelectorBridge.java
===================================================================
RCS file:
/cvsroot/jboss/jboss/src/main/org/jboss/ejb/plugins/cmp/jdbc/bridge/JDBCSelectorBridge.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- JDBCSelectorBridge.java 2001/08/03 17:15:47 1.2
+++ JDBCSelectorBridge.java 2001/08/26 19:37:10 1.3
@@ -17,23 +17,72 @@
* One for each entity bean ejbSelect method.
*
* @author <a href="mailto:[EMAIL PROTECTED]">Dain Sundstrom</a>
- * @version $Revision: 1.2 $
+ * @version $Revision: 1.3 $
*/
+import java.lang.reflect.Method;
+import java.rmi.RemoteException;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.HashSet;
+import java.util.Set;
+import javax.ejb.EJBException;
+import javax.ejb.FinderException;
+import javax.ejb.ObjectNotFoundException;
+import org.jboss.ejb.DeploymentException;
import org.jboss.ejb.plugins.cmp.bridge.SelectorBridge;
+import org.jboss.ejb.plugins.cmp.jdbc.JDBCEJBQLFinderCommand;
+import org.jboss.ejb.plugins.cmp.jdbc.JDBCStoreManager;
+import org.jboss.ejb.plugins.cmp.jdbc.metadata.JDBCQlQueryMetaData;
public class JDBCSelectorBridge implements SelectorBridge {
- protected String selectorName;
- protected Class returnType;
+ protected final JDBCQlQueryMetaData queryMetaData;
+ protected final JDBCStoreManager manager;
+ public JDBCSelectorBridge(JDBCStoreManager manager, JDBCQlQueryMetaData
queryMetaData) {
+ this.queryMetaData = queryMetaData;
+ this.manager = manager;
+ }
+
public String getSelectorName() {
- return selectorName;
+ return queryMetaData.getMethod().getName();
+ }
+
+ public Method getMethod() {
+ return queryMetaData.getMethod();
}
public Class getReturnType() {
- return returnType;
+ return queryMetaData.getMethod().getReturnType();
}
- public Object execute(Object[] args) {
- return null;
+ public Object execute(Object[] args) throws FinderException {
+ Collection retVal = null;
+ try {
+ retVal = manager.findEntities(getMethod(), args, null);
+ } catch(FinderException e) {
+ throw e;
+ } catch(EJBException e) {
+ throw e;
+ } catch(Exception e) {
+ throw new EJBException("Error in " + getSelectorName(), e);
+ }
+
+ if(!Collection.class.isAssignableFrom(getReturnType())) {
+ // single object
+ if(retVal.size() == 0) {
+ throw new ObjectNotFoundException();
+ }
+ if(retVal.size() > 1) {
+ throw new FinderException(getSelectorName() + "
returned " + retVal.size() + " objects");
+ }
+ return retVal.iterator().next();
+ } else {
+ // collection or set
+ if(Set.class.isAssignableFrom(getReturnType())) {
+ return new HashSet(retVal);
+ } else {
+ return new ArrayList(retVal);
+ }
+ }
}
}
_______________________________________________
Jboss-development mailing list
[EMAIL PROTECTED]
http://lists.sourceforge.net/lists/listinfo/jboss-development