User: dsundstrom
Date: 02/02/12 14:35:12
Modified: src/main/org/jboss/ejb/plugins/cmp/jdbc/bridge
JDBCAbstractCMPFieldBridge.java
JDBCCMP1xFieldBridge.java JDBCCMRFieldBridge.java
JDBCFieldBridge.java
Log:
Fixed code that throws an exception if bean provider attempts to set a
primary key field out side of ejbCreate or if the bean provider attempts
to add a bean to a relation inside of ejbCreate.
Revision Changes Path
1.11 +19 -1
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.10
retrieving revision 1.11
diff -u -r1.10 -r1.11
--- JDBCAbstractCMPFieldBridge.java 15 Jan 2002 20:43:56 -0000 1.10
+++ JDBCAbstractCMPFieldBridge.java 12 Feb 2002 22:35:12 -0000 1.11
@@ -40,7 +40,7 @@
* One for each entity bean cmp field.
*
* @author <a href="mailto:[EMAIL PROTECTED]">Dain Sundstrom</a>
- * @version $Revision: 1.10 $
+ * @version $Revision: 1.11 $
*/
public abstract class JDBCAbstractCMPFieldBridge implements JDBCCMPFieldBridge {
protected JDBCStoreManager manager;
@@ -93,6 +93,24 @@
public boolean isPrimaryKeyMember() {
return metadata.isPrimaryKeyMember();
+ }
+
+ public Object getValue(EntityEnterpriseContext ctx) {
+ // no user checks yet, but this is where they would go
+ return getInstanceValue(ctx);
+ }
+
+ public void setValue(EntityEnterpriseContext ctx, Object value) {
+ if(isReadOnly()) {
+ throw new EJBException("Field is read-only: " +
+ "fieldName=" + getFieldName());
+ }
+ if(isPrimaryKeyMember() && manager.getEntityBridge().isCreated(ctx)) {
+ throw new IllegalStateException("A CMP field that is a member " +
+ "of the primary key can only be set in ejbCreate " +
+ "[EJB 2.0 Spec. 10.3.5].");
+ }
+ setInstanceValue(ctx, value);
}
public Object getPrimaryKeyValue(Object primaryKey)
1.11 +1 -6
jboss/src/main/org/jboss/ejb/plugins/cmp/jdbc/bridge/JDBCCMP1xFieldBridge.java
Index: JDBCCMP1xFieldBridge.java
===================================================================
RCS file:
/cvsroot/jboss/jboss/src/main/org/jboss/ejb/plugins/cmp/jdbc/bridge/JDBCCMP1xFieldBridge.java,v
retrieving revision 1.10
retrieving revision 1.11
diff -u -r1.10 -r1.11
--- JDBCCMP1xFieldBridge.java 15 Jan 2002 20:48:16 -0000 1.10
+++ JDBCCMP1xFieldBridge.java 12 Feb 2002 22:35:12 -0000 1.11
@@ -35,7 +35,7 @@
* One for each entity bean cmp field.
*
* @author <a href="mailto:[EMAIL PROTECTED]">Dain Sundstrom</a>
- * @version $Revision: 1.10 $
+ * @version $Revision: 1.11 $
*/
public class JDBCCMP1xFieldBridge extends JDBCAbstractCMPFieldBridge {
private Field field;
@@ -72,11 +72,6 @@
}
public void setInstanceValue(EntityEnterpriseContext ctx, Object value) {
- if(isPrimaryKeyMember() && manager.getEntityBridge().isCreated(ctx)) {
-// throw new IllegalStateException("A field that is a member " +
-// "of the primary key can only be set in ejbCreate");
- }
-
try {
field.set(ctx.getInstance(), value);
1.23 +40 -25
jboss/src/main/org/jboss/ejb/plugins/cmp/jdbc/bridge/JDBCCMRFieldBridge.java
Index: JDBCCMRFieldBridge.java
===================================================================
RCS file:
/cvsroot/jboss/jboss/src/main/org/jboss/ejb/plugins/cmp/jdbc/bridge/JDBCCMRFieldBridge.java,v
retrieving revision 1.22
retrieving revision 1.23
diff -u -r1.22 -r1.23
--- JDBCCMRFieldBridge.java 12 Feb 2002 06:17:15 -0000 1.22
+++ JDBCCMRFieldBridge.java 12 Feb 2002 22:35:12 -0000 1.23
@@ -53,7 +53,7 @@
* One for each role that entity has.
*
* @author <a href="mailto:[EMAIL PROTECTED]">Dain Sundstrom</a>
- * @version $Revision: 1.22 $
+ * @version $Revision: 1.23 $
*/
public class JDBCCMRFieldBridge implements JDBCFieldBridge {
// ------ Invocation messages ------
@@ -488,17 +488,34 @@
return true;
}
+ public Object getValue(EntityEnterpriseContext ctx) {
+ // no user checks yet, but this is where they would go
+ return getInstanceValue(ctx);
+ }
+
+ public void setValue(EntityEnterpriseContext ctx, Object value) {
+ if(isReadOnly()) {
+ throw new EJBException("Field is read-only: " +
+ "fieldName=" + getFieldName());
+ }
+ if(!entity.isCreated(ctx)) {
+ throw new IllegalStateException("A CMR field cannot be set " +
+ "in ejbCreate; this should be done in the ejbPostCreate " +
+ "method instead [EJB 2.0 Spec. 10.5.2].");
+ }
+ if(isCollectionValued() && value == null) {
+ throw new IllegalArgumentException("null cannot be assigned to a " +
+ "collection-valued cmr-field [EJB 2.0 Spec. 10.3.8].");
+ }
+
+ setInstanceValue(ctx, value);
+ }
+
/**
* Gets the value of the cmr field for the instance associated with
* the context.
*/
public Object getInstanceValue(EntityEnterpriseContext myCtx) {
- if(!entity.isCreated(myCtx)) {
-// throw new IllegalStateException("A CMR field cannot be set " +
-// "in ejbCreate; this should be done in the ejbPostCreate " +
-// "method instead.");
- }
-
load(myCtx);
FieldState fieldState = getFieldState(myCtx);
@@ -528,15 +545,6 @@
public void setInstanceValue(
EntityEnterpriseContext myCtx, Object newValue) {
- if(isReadOnly()) {
- throw new EJBException("Field is read-only: " + getFieldName());
- }
-
- if(isCollectionValued() && newValue == null) {
-// throw new IllegalArgumentException("null cannot be assigned to a " +
-// "collection-valued cmr-field [EJB 2.0 Spec. 10.3.8].");
- }
-
load(myCtx);
FieldState fieldState = getFieldState(myCtx);
@@ -740,7 +748,7 @@
if(!entity.isCreated(myCtx)) {
throw new IllegalStateException("A CMR field cannot be set or added " +
"to a relationship in ejbCreate; this should be done in the " +
- "ejbPostCreate method instead.");
+ "ejbPostCreate method instead [EJB 2.0 Spec. 10.5.2].");
}
load(myCtx);
@@ -815,9 +823,11 @@
}
// check the preload cache
- log.debug("Read ahead cahce load:"+
- " cmrField="+getFieldName()+
- " pk="+myCtx.getId());
+ if(log.isDebugEnabled()) {
+ log.debug("Read ahead cahce load:"+
+ " cmrField="+getFieldName()+
+ " pk="+myCtx.getId());
+ }
manager.getReadAheadCache().load(myCtx);
if(fieldState.isLoaded()) {
return;
@@ -847,7 +857,10 @@
fieldState.setLoaded(true);
}
- public void loadPreloadedValue(EntityEnterpriseContext myCtx, Collection values)
{
+ public void loadPreloadedValue(
+ EntityEnterpriseContext myCtx,
+ Collection values) {
+
if(isSingleValued() && values.size() > 1) {
throw new EJBException("Preload data contains multiple values, but " +
"this cmr field is single valued");
@@ -874,10 +887,12 @@
// mark the field loaded
fieldState.setLoaded(true);
- log.debug("Preloaded value: "+
- " cmrField="+getFieldName()+
- " pk="+myCtx.getId()+
- " values="+values);
+ if(log.isDebugEnabled()) {
+ log.debug("Preloaded value: "+
+ " cmrField="+getFieldName()+
+ " pk="+myCtx.getId()+
+ " values="+values);
+ }
}
/**
1.2 +20 -0
jboss/src/main/org/jboss/ejb/plugins/cmp/jdbc/bridge/JDBCFieldBridge.java
Index: JDBCFieldBridge.java
===================================================================
RCS file:
/cvsroot/jboss/jboss/src/main/org/jboss/ejb/plugins/cmp/jdbc/bridge/JDBCFieldBridge.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- JDBCFieldBridge.java 15 Jan 2002 20:46:29 -0000 1.1
+++ JDBCFieldBridge.java 12 Feb 2002 22:35:12 -0000 1.2
@@ -27,6 +27,12 @@
public boolean isPrimaryKeyMember();
/**
+ * Is this field read only.
+ * @return true if this field is read only
+ */
+ public boolean isReadOnly();
+
+ /**
* Has current data read timed out?
*/
public boolean isReadTimedOut(EntityEnterpriseContext ctx);
@@ -54,6 +60,20 @@
PreparedStatement ps,
int parameterIndex,
EntityEnterpriseContext ctx);
+
+ /**
+ * Gets the internal value of this field without user level checks.
+ * @param ctx the context for which this field's value should be fetched
+ * @return the value of this field
+ */
+ public Object getInstanceValue(EntityEnterpriseContext ctx);
+
+ /**
+ * Sets the internal value of this field without user level checks.
+ * @param ctx the context for which this field's value should be set
+ * @param value the new value of this field
+ */
+ public void setInstanceValue(EntityEnterpriseContext ctx, Object value);
/**
* Loads the data from result set into the instance associated with
_______________________________________________
Jboss-development mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/jboss-development