User: dsundstrom
  Date: 01/12/12 11:47:06

  Modified:    src/main/org/jboss/ejb/plugins/cmp/jdbc/bridge
                        JDBCCMRFieldBridge.java
  Log:
  Added code to support readonly cmr fields.
  
  Revision  Changes    Path
  1.17      +64 -9     
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.16
  retrieving revision 1.17
  diff -u -r1.16 -r1.17
  --- JDBCCMRFieldBridge.java   2001/12/02 01:41:46     1.16
  +++ JDBCCMRFieldBridge.java   2001/12/12 19:47:05     1.17
  @@ -47,7 +47,7 @@
    *      One for each role that entity has.       
    *
    * @author <a href="mailto:[EMAIL PROTECTED]";>Dain Sundstrom</a>
  - * @version $Revision: 1.16 $
  + * @version $Revision: 1.17 $
    */                            
   public class JDBCCMRFieldBridge implements CMRFieldBridge {
      // ------ Invocation messages ------
  @@ -428,6 +428,27 @@
      }
   
      /**
  +    * Is this field readonly?
  +    */
  +   public boolean isReadOnly() {
  +      return getRelationMetaData().isReadOnly();
  +   }
  +
  +   /**
  +    * Had the read time expired?
  +    */
  +   public boolean isReadTimedOut(EntityEnterpriseContext ctx) {
  +      if(isReadOnly()) {
  +         long readInterval = System.currentTimeMillis() - 
  +               getFieldState(ctx).getLastRead(); 
  +         return readInterval > getRelationMetaData().getReadTimeOut();
  +      }
  +      
  +      // if we are read/write then we are always timed out
  +      return true;
  +   }
  +
  +   /**
       * Gets the value of the cmr field for the instance associated with 
       * the context.
       */
  @@ -458,6 +479,10 @@
       * the context.
       */
      public void setValue(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].");
  @@ -504,6 +529,10 @@
      public void createRelationLinks(
            EntityEnterpriseContext myCtx, Object relatedId) {      
   
  +      if(isReadOnly()) {
  +         throw new EJBException("Field is read-only: " + getFieldName());
  +      }
  +
         // If my multiplicity is one, then we need to free the new related context
         // from its old relationship.
         if(metadata.isMultiplicityOne()) {
  @@ -548,6 +577,10 @@
            Object relatedId,
            boolean updateValueCollection) {
   
  +      if(isReadOnly()) {
  +         throw new EJBException("Field is read-only: " + getFieldName());
  +      }
  +
         removeRelation(myCtx, relatedId, updateValueCollection);      
         relatedCMRField.invokeRemoveRelation(
               myCtx.getTransaction(), relatedId, myCtx.getId());
  @@ -655,6 +688,10 @@
       * any foreign key fields.
       */
      public void addRelation(EntityEnterpriseContext myCtx, Object fk) {
  +      if(isReadOnly()) {
  +         throw new EJBException("Field is read-only: " + getFieldName());
  +      }
  +
         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 " +
  @@ -701,6 +738,10 @@
            Object fk,
            boolean updateValueCollection) {
   
  +      if(isReadOnly()) {
  +         throw new EJBException("Field is read-only: " + getFieldName());
  +      }
  +
         load(myCtx);
         
         // remove from current related set
  @@ -719,7 +760,7 @@
       */
      private void load(EntityEnterpriseContext myCtx) {
         FieldState fieldState = getFieldState(myCtx);
  -      if(fieldState != null) {
  +      if(fieldState.getValue() != null) {
            return;
         }
         
  @@ -791,12 +832,14 @@
       * resets the persistence context of the foreign key fields
       */
      public void resetPersistenceContext(EntityEnterpriseContext ctx) {
  -      setFieldState(ctx, null);
  +      if(isReadTimedOut(ctx)) {
  +         setFieldState(ctx, null);
         
  -      if(hasForeignKey()) {
  -         JDBCCMPFieldBridge[] foreignKeyFields = getForeignKeyFields();
  -         for(int i=0; i<foreignKeyFields.length; i++) {
  -            foreignKeyFields[i].resetPersistenceContext(ctx);
  +         if(hasForeignKey()) {
  +            JDBCCMPFieldBridge[] foreignKeyFields = getForeignKeyFields();
  +            for(int i=0; i<foreignKeyFields.length; i++) {
  +               foreignKeyFields[i].resetPersistenceContext(ctx);
  +            }
            }
         }
      }
  @@ -806,7 +849,12 @@
       */
      private FieldState getFieldState(EntityEnterpriseContext ctx) {
         JDBCContext jdbcCtx = (JDBCContext)ctx.getPersistenceContext();
  -      return (FieldState)jdbcCtx.get(this);
  +      FieldState fieldState = (FieldState)jdbcCtx.get(this);
  +      if(fieldState == null) {
  +         fieldState = new FieldState(ctx);
  +         jdbcCtx.put(this, fieldState);
  +      }
  +      return fieldState;
      }
   
      /**
  @@ -831,9 +879,13 @@
      }
   
      private class FieldState {
  -      EntityEnterpriseContext ctx;
  +      private EntityEnterpriseContext ctx;
         private Set[] setHandle = new Set[1];
         private Set relationSet;
  +      private long lastRead = System.currentTimeMillis();
  +      public FieldState(EntityEnterpriseContext ctx) {
  +         this.ctx = ctx;
  +      }
         public FieldState(EntityEnterpriseContext ctx, Set value) {
            this.ctx = ctx;
            setHandle[0] = value;
  @@ -847,6 +899,9 @@
                     JDBCCMRFieldBridge.this, ctx, setHandle);
            }
            return relationSet;
  +      }
  +      public long getLastRead() {
  +         return lastRead;
         }
         public void invalidateRelationSet() {
            // make a new set handle with the existing value
  
  
  

_______________________________________________
Jboss-development mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/jboss-development

Reply via email to