gdamour     2005/08/05 06:52:09

  Modified:    modules/core/src/java/org/openejb/entity/cmp CMPFinder.java
                        CMPSelectMethod.java CollectionValuedFinder.java
                        CollectionValuedSelect.java
                        EnumerationValuedFinder.java SetValuedFinder.java
                        SetValuedSelect.java SingleValuedFinder.java
                        SingleValuedSelect.java
  Added:       modules/core/src/java/org/openejb/entity/cmp
                        CacheFiller.java
  Log:

  GERONIMO-665 - CMP - Prefetching of CMP and CMR fields.
  
  This is a final tweak to add to the transactional cache the CMP returned by
  finders and selects. This way when a CMP or CMR field is accessed after
  a finder or a select returning an entity, which is not associated to a
  prefetching group, only one query is executed by the engine.
  
  The previous implementation was executing two queries in this specific
  scenario.
  
  Revision  Changes    Path
  1.14      +24 -7     
openejb/modules/core/src/java/org/openejb/entity/cmp/CMPFinder.java
  
  Index: CMPFinder.java
  ===================================================================
  RCS file: 
/home/projects/openejb/scm/openejb/modules/core/src/java/org/openejb/entity/cmp/CMPFinder.java,v
  retrieving revision 1.13
  retrieving revision 1.14
  diff -u -r1.13 -r1.14
  --- CMPFinder.java    22 Jun 2005 11:27:17 -0000      1.13
  +++ CMPFinder.java    5 Aug 2005 10:52:08 -0000       1.14
  @@ -52,8 +52,12 @@
   import org.openejb.EJBInvocation;
   import org.openejb.dispatch.VirtualOperation;
   import org.tranql.cache.InTxCache;
  +import org.tranql.field.Row;
  +import org.tranql.identity.IdentityDefiner;
   import org.tranql.ql.QueryException;
   import org.tranql.query.QueryCommand;
  +import org.tranql.query.ResultHandler;
  +import org.tranql.sql.prefetch.PrefetchGroupHandler;
   
   /**
    * @version $Revision$ $Date$
  @@ -62,22 +66,35 @@
       private final QueryCommand localCommand;
       private final QueryCommand remoteCommand;
       private final boolean flushCache;
  -
  -    public CMPFinder(QueryCommand localCommand, QueryCommand remoteCommand, 
boolean flushCache) {
  +    private final IdentityDefiner idDefiner;
  +    private final IdentityDefiner idInjector;
  +    
  +    public CMPFinder(QueryCommand localCommand, QueryCommand remoteCommand, 
boolean flushCache, IdentityDefiner idDefiner, IdentityDefiner idInjector) {
           this.localCommand = localCommand;
           this.remoteCommand = remoteCommand;
           this.flushCache = flushCache;
  +        this.idDefiner = idDefiner;
  +        this.idInjector = idInjector;
       }
   
       protected QueryCommand getCommand(EJBInvocation invocation) {
           return invocation.getType().isLocal() ? localCommand : remoteCommand;
       }
  -    
  -    protected InTxCache flushCache(EJBInvocation invocation) throws 
QueryException {
  +
  +    protected Object execute(EJBInvocation invocation, ResultHandler 
handler, Object ctx) throws QueryException {
           InTxCache cache = invocation.getTransactionContext().getInTxCache();
           if (flushCache) {
               cache.flush();
           }
  -        return cache;
  +        
  +        QueryCommand command = getCommand(invocation);
  +        Row arguments = new Row(invocation.getArguments());
  +        PrefetchGroupHandler groupHandler = 
command.getQuery().getPrefetchGroupHandler();
  +        if (null != groupHandler) {
  +            groupHandler = new PrefetchGroupHandler(groupHandler, handler);
  +            return groupHandler.execute(cache, command, arguments, ctx);
  +        }
  +        handler = new CacheFiller(handler, idDefiner, idInjector, cache);
  +        return command.execute(handler, arguments, ctx);
       }
  -}
  +}
  \ No newline at end of file
  
  
  
  1.5       +39 -19    
openejb/modules/core/src/java/org/openejb/entity/cmp/CMPSelectMethod.java
  
  Index: CMPSelectMethod.java
  ===================================================================
  RCS file: 
/home/projects/openejb/scm/openejb/modules/core/src/java/org/openejb/entity/cmp/CMPSelectMethod.java,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- CMPSelectMethod.java      23 Apr 2004 08:18:32 -0000      1.4
  +++ CMPSelectMethod.java      5 Aug 2005 10:52:08 -0000       1.5
  @@ -55,7 +55,15 @@
    */
   package org.openejb.entity.cmp;
   
  +import org.tranql.cache.InTxCache;
  +import org.tranql.field.FieldTransform;
  +import org.tranql.field.Row;
  +import org.tranql.identity.IdentityDefiner;
  +import org.tranql.ql.Query;
  +import org.tranql.ql.QueryException;
   import org.tranql.query.QueryCommand;
  +import org.tranql.query.ResultHandler;
  +import org.tranql.sql.prefetch.PrefetchGroupHandler;
   
   /**
    *
  @@ -63,26 +71,38 @@
    *
    * @version $Revision$ $Date$
    */
  -public class CMPSelectMethod implements InstanceOperation {
  -    private final QueryCommand query;
  +public abstract class CMPSelectMethod implements InstanceOperation {
  +    protected final QueryCommand command;
  +    protected final FieldTransform resultAccessor;
  +    private final PrefetchGroupHandler groupHandler;
  +    private final boolean flushCache;
  +    private final IdentityDefiner idDefiner;
  +    private final IdentityDefiner idInjector;
   
  -    public CMPSelectMethod(QueryCommand query) {
  -        this.query = query;
  +    public CMPSelectMethod(QueryCommand command, boolean flushCache, 
IdentityDefiner idDefiner, IdentityDefiner idInjector) {
  +        this.command = command;
  +        this.flushCache = flushCache;
  +        this.idDefiner = idDefiner;
  +        this.idInjector = idInjector;
  +     
  +        Query query = command.getQuery();
  +        resultAccessor = query.getResultAccessors()[0];
  +        groupHandler = query.getPrefetchGroupHandler();
       }
  +    
  +    protected Object execute(CMPInstanceContext instCtx, ResultHandler 
handler, Object[] args, Object ctx) throws QueryException {
  +        InTxCache cache = instCtx.getTransactionContext().getInTxCache();
  +        if (flushCache) {
  +            cache.flush();
  +        }
   
  -    public Object invokeInstance(CMPInstanceContext ctx, Object[] args) 
throws Exception {
  -        throw new UnsupportedOperationException();
  -/*
  -        try {
  -            InTxCache inTxCache = ctx.getTransactionContext().getInTxCache();
  -            return query.execute(inTxCache, new Row(args));
  -        } catch (QueryException e) {
  -            throw (FinderException) new FinderException().initCause(e);
  -        } catch (RuntimeException e) {
  -            throw e;
  -        } catch (Exception e) {
  -            throw new EJBException(e);
  +        if (null != groupHandler) {
  +            PrefetchGroupHandler newHandler = new 
PrefetchGroupHandler(groupHandler, handler);
  +            return newHandler.execute(cache, command, new Row(args), ctx);
  +        }
  +        if (null != idDefiner) {
  +            handler = new CacheFiller(handler, idDefiner, idInjector, cache);
           }
  -*/
  +        return command.execute(handler, new Row(args), ctx);
       }
  -}
  +}
  \ No newline at end of file
  
  
  
  1.9       +7 -17     
openejb/modules/core/src/java/org/openejb/entity/cmp/CollectionValuedFinder.java
  
  Index: CollectionValuedFinder.java
  ===================================================================
  RCS file: 
/home/projects/openejb/scm/openejb/modules/core/src/java/org/openejb/entity/cmp/CollectionValuedFinder.java,v
  retrieving revision 1.8
  retrieving revision 1.9
  diff -u -r1.8 -r1.9
  --- CollectionValuedFinder.java       22 Jun 2005 11:27:17 -0000      1.8
  +++ CollectionValuedFinder.java       5 Aug 2005 10:52:09 -0000       1.9
  @@ -54,13 +54,12 @@
   
   import org.apache.geronimo.core.service.InvocationResult;
   import org.openejb.EJBInvocation;
  -import org.tranql.cache.InTxCache;
   import org.tranql.field.FieldTransform;
  -import org.tranql.field.Row;
  +import org.tranql.identity.IdentityDefiner;
   import org.tranql.ql.QueryException;
   import org.tranql.query.CollectionResultHandler;
   import org.tranql.query.QueryCommand;
  -import org.tranql.sql.prefetch.PrefetchGroupHandler;
  +import org.tranql.query.ResultHandler;
   
   /**
    * 
  @@ -69,26 +68,17 @@
    */
   public class CollectionValuedFinder extends CMPFinder {
   
  -    public CollectionValuedFinder(QueryCommand localCommand, QueryCommand 
remoteCommand, boolean flushCache) {
  -        super(localCommand, remoteCommand, flushCache);
  +    public CollectionValuedFinder(QueryCommand localCommand, QueryCommand 
remoteCommand, boolean flushCache, IdentityDefiner idDefiner, IdentityDefiner 
idInjector) {
  +        super(localCommand, remoteCommand, flushCache, idDefiner, 
idInjector);
       }
   
       public InvocationResult execute(EJBInvocation invocation) throws 
Throwable {
  -        InTxCache cache = flushCache(invocation);
  -
           try {
               QueryCommand command = getCommand(invocation);
               Collection results = new ArrayList();
               FieldTransform resultAccessor = 
command.getQuery().getResultAccessors()[0];
  -            CollectionResultHandler handler = new 
CollectionResultHandler(resultAccessor);
  -            Row arguments = new Row(invocation.getArguments());
  -            PrefetchGroupHandler groupHandler = 
command.getQuery().getPrefetchGroupHandler();
  -            if (null != groupHandler) {
  -                groupHandler = new PrefetchGroupHandler(groupHandler, 
handler);
  -                groupHandler.execute(cache, command, arguments, results);
  -            } else {
  -                command.execute(handler, arguments, results);
  -            }
  +            ResultHandler handler = new 
CollectionResultHandler(resultAccessor);
  +            execute(invocation, handler, results);
               return invocation.createResult(results);
           } catch (QueryException e) {
               return invocation.createExceptionResult((Exception)new 
FinderException(e.getMessage()).initCause(e));
  
  
  
  1.6       +6 -29     
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.5
  retrieving revision 1.6
  diff -u -r1.5 -r1.6
  --- CollectionValuedSelect.java       22 Jun 2005 11:27:17 -0000      1.5
  +++ CollectionValuedSelect.java       5 Aug 2005 10:52:09 -0000       1.6
  @@ -52,11 +52,7 @@
   
   import javax.ejb.FinderException;
   
  -import org.tranql.cache.InTxCache;
  -import org.tranql.sql.prefetch.PrefetchGroupHandler;
  -import org.tranql.field.FieldTransform;
  -import org.tranql.field.Row;
  -import org.tranql.ql.Query;
  +import org.tranql.identity.IdentityDefiner;
   import org.tranql.ql.QueryException;
   import org.tranql.query.CollectionResultHandler;
   import org.tranql.query.QueryCommand;
  @@ -68,36 +64,17 @@
    * 
    * @version $Revision$ $Date$
    */
  -public class CollectionValuedSelect implements InstanceOperation {
  -    private final QueryCommand command;
  -    private final FieldTransform resultAccessor;
  -    private final PrefetchGroupHandler groupHandler;
  -    private final boolean flushCache;
  +public class CollectionValuedSelect extends CMPSelectMethod {
   
  -    public CollectionValuedSelect(QueryCommand command, boolean flushCache) {
  -        this.command = command;
  -        this.flushCache = flushCache;
  -        
  -        Query query = command.getQuery();
  -        resultAccessor = query.getResultAccessors()[0];
  -        groupHandler = query.getPrefetchGroupHandler();
  +    public CollectionValuedSelect(QueryCommand command, boolean flushCache, 
IdentityDefiner idDefiner, IdentityDefiner idInjector) {
  +        super(command, flushCache, idDefiner, idInjector);
       }
   
       public Object invokeInstance(CMPInstanceContext ctx, Object[] args) 
throws Exception {
  -        InTxCache cache = ctx.getTransactionContext().getInTxCache();
  -        if (flushCache) {
  -            cache.flush();
  -        }
  -
           Collection results = new ArrayList();
           try {
               ResultHandler handler = new 
CollectionResultHandler(resultAccessor);
  -            if (null != groupHandler) {
  -                PrefetchGroupHandler newHandler = new 
PrefetchGroupHandler(groupHandler, handler);
  -                newHandler.execute(cache, command, new Row(args), results);
  -            } else {
  -                command.execute(handler, new Row(args), results);
  -            }
  +            execute(ctx, handler, args, results);
           } catch (QueryException e) {
               throw (FinderException) new 
FinderException(e.getMessage()).initCause(e);
           }
  
  
  
  1.9       +7 -17     
openejb/modules/core/src/java/org/openejb/entity/cmp/EnumerationValuedFinder.java
  
  Index: EnumerationValuedFinder.java
  ===================================================================
  RCS file: 
/home/projects/openejb/scm/openejb/modules/core/src/java/org/openejb/entity/cmp/EnumerationValuedFinder.java,v
  retrieving revision 1.8
  retrieving revision 1.9
  diff -u -r1.8 -r1.9
  --- EnumerationValuedFinder.java      22 Jun 2005 11:27:17 -0000      1.8
  +++ EnumerationValuedFinder.java      5 Aug 2005 10:52:09 -0000       1.9
  @@ -55,13 +55,12 @@
   
   import org.apache.geronimo.core.service.InvocationResult;
   import org.openejb.EJBInvocation;
  -import org.tranql.cache.InTxCache;
   import org.tranql.field.FieldTransform;
  -import org.tranql.field.Row;
  +import org.tranql.identity.IdentityDefiner;
   import org.tranql.ql.QueryException;
   import org.tranql.query.CollectionResultHandler;
   import org.tranql.query.QueryCommand;
  -import org.tranql.sql.prefetch.PrefetchGroupHandler;
  +import org.tranql.query.ResultHandler;
   
   /**
    * 
  @@ -70,26 +69,17 @@
    */
   public class EnumerationValuedFinder extends CMPFinder {
   
  -    public EnumerationValuedFinder(QueryCommand localCommand, QueryCommand 
remoteCommand, boolean flushCache) {
  -        super(localCommand, remoteCommand, flushCache);
  +    public EnumerationValuedFinder(QueryCommand localCommand, QueryCommand 
remoteCommand, boolean flushCache, IdentityDefiner idDefiner, IdentityDefiner 
idInjector) {
  +        super(localCommand, remoteCommand, flushCache, idDefiner, 
idInjector);
       }
   
       public InvocationResult execute(EJBInvocation invocation) throws 
Throwable {
  -        InTxCache cache = flushCache(invocation);
  -        
           try {
               QueryCommand command = getCommand(invocation);
               List results = new ArrayList();
               FieldTransform resultAccessor = 
command.getQuery().getResultAccessors()[0];
  -            CollectionResultHandler handler = new 
CollectionResultHandler(resultAccessor);
  -            Row arguments = new Row(invocation.getArguments());
  -            PrefetchGroupHandler groupHandler = 
command.getQuery().getPrefetchGroupHandler();
  -            if (null != groupHandler) {
  -                groupHandler = new PrefetchGroupHandler(groupHandler, 
handler);
  -                groupHandler.execute(cache, command, arguments, results);
  -            } else {
  -                command.execute(handler, arguments, results);
  -            }
  +            ResultHandler handler = new 
CollectionResultHandler(resultAccessor);
  +            execute(invocation, handler, results);
               return invocation.createResult(Collections.enumeration(results));
           } catch (QueryException e) {
               return invocation.createExceptionResult((Exception)new 
FinderException(e.getMessage()).initCause(e));
  
  
  
  1.5       +7 -17     
openejb/modules/core/src/java/org/openejb/entity/cmp/SetValuedFinder.java
  
  Index: SetValuedFinder.java
  ===================================================================
  RCS file: 
/home/projects/openejb/scm/openejb/modules/core/src/java/org/openejb/entity/cmp/SetValuedFinder.java,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- SetValuedFinder.java      22 Jun 2005 11:27:17 -0000      1.4
  +++ SetValuedFinder.java      5 Aug 2005 10:52:09 -0000       1.5
  @@ -54,13 +54,12 @@
   
   import org.apache.geronimo.core.service.InvocationResult;
   import org.openejb.EJBInvocation;
  -import org.tranql.cache.InTxCache;
   import org.tranql.field.FieldTransform;
  -import org.tranql.field.Row;
  +import org.tranql.identity.IdentityDefiner;
   import org.tranql.ql.QueryException;
   import org.tranql.query.CollectionResultHandler;
   import org.tranql.query.QueryCommand;
  -import org.tranql.sql.prefetch.PrefetchGroupHandler;
  +import org.tranql.query.ResultHandler;
   
   /**
    * 
  @@ -69,26 +68,17 @@
    */
   public class SetValuedFinder extends CMPFinder {
   
  -    public SetValuedFinder(QueryCommand localCommand, QueryCommand 
remoteCommand, boolean flushCache) {
  -        super(localCommand, remoteCommand, flushCache);
  +    public SetValuedFinder(QueryCommand localCommand, QueryCommand 
remoteCommand, boolean flushCache, IdentityDefiner idDefiner, IdentityDefiner 
idInjector) {
  +        super(localCommand, remoteCommand, flushCache, idDefiner, 
idInjector);
       }
   
       public InvocationResult execute(EJBInvocation invocation) throws 
Throwable {
  -        InTxCache cache = flushCache(invocation);
  -        
           try {
               QueryCommand command = getCommand(invocation);
               Set results = new HashSet();
               FieldTransform resultAccessor = 
command.getQuery().getResultAccessors()[0];
  -            CollectionResultHandler handler = new 
CollectionResultHandler(resultAccessor);
  -            Row arguments = new Row(invocation.getArguments());
  -            PrefetchGroupHandler groupHandler = 
command.getQuery().getPrefetchGroupHandler();
  -            if (null != groupHandler) {
  -                groupHandler = new PrefetchGroupHandler(groupHandler, 
handler);
  -                groupHandler.execute(cache, command, arguments, results);
  -            } else {
  -                command.execute(handler, arguments, results);
  -            }
  +            ResultHandler handler = new 
CollectionResultHandler(resultAccessor);
  +            execute(invocation, handler, results);
               return invocation.createResult(results);
           } catch (QueryException e) {
               return invocation.createExceptionResult((Exception)new 
FinderException(e.getMessage()).initCause(e));
  
  
  
  1.6       +6 -29     
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.5
  retrieving revision 1.6
  diff -u -r1.5 -r1.6
  --- SetValuedSelect.java      22 Jun 2005 11:27:17 -0000      1.5
  +++ SetValuedSelect.java      5 Aug 2005 10:52:09 -0000       1.6
  @@ -52,11 +52,7 @@
   
   import javax.ejb.FinderException;
   
  -import org.tranql.cache.InTxCache;
  -import org.tranql.sql.prefetch.PrefetchGroupHandler;
  -import org.tranql.field.FieldTransform;
  -import org.tranql.field.Row;
  -import org.tranql.ql.Query;
  +import org.tranql.identity.IdentityDefiner;
   import org.tranql.ql.QueryException;
   import org.tranql.query.CollectionResultHandler;
   import org.tranql.query.QueryCommand;
  @@ -67,36 +63,17 @@
    * 
    * @version $Revision$ $Date$
    */
  -public class SetValuedSelect implements InstanceOperation {
  -    private final QueryCommand command;
  -    private final FieldTransform resultAccessor;
  -    private final PrefetchGroupHandler groupHandler;
  -    private final boolean flushCache;
  +public class SetValuedSelect extends CMPSelectMethod {
   
  -    public SetValuedSelect(QueryCommand command, boolean flushCache) {
  -        this.command = command;
  -        this.flushCache = flushCache;
  -        
  -        Query query = command.getQuery();
  -        resultAccessor = query.getResultAccessors()[0];
  -        groupHandler = query.getPrefetchGroupHandler();
  +    public SetValuedSelect(QueryCommand command, boolean flushCache, 
IdentityDefiner idDefiner, IdentityDefiner idInjector) {
  +        super(command, flushCache, idDefiner, idInjector);
       }
       
       public Object invokeInstance(CMPInstanceContext ctx, Object[] args) 
throws Exception {
  -        InTxCache cache = ctx.getTransactionContext().getInTxCache();
  -        if (flushCache) {
  -            cache.flush();
  -        }
  -
           Set results = new HashSet();
           try {
               ResultHandler handler = new 
CollectionResultHandler(resultAccessor);
  -            if (null != groupHandler) {
  -                PrefetchGroupHandler newHandler = new 
PrefetchGroupHandler(groupHandler, handler);
  -                newHandler.execute(cache, command, new Row(args), results);
  -            } else {
  -                command.execute(handler, new Row(args), results);
  -            }
  +            execute(ctx, handler, args, results);
           } catch (QueryException e) {
               throw (FinderException) new 
FinderException(e.getMessage()).initCause(e);
           }
  
  
  
  1.10      +9 -20     
openejb/modules/core/src/java/org/openejb/entity/cmp/SingleValuedFinder.java
  
  Index: SingleValuedFinder.java
  ===================================================================
  RCS file: 
/home/projects/openejb/scm/openejb/modules/core/src/java/org/openejb/entity/cmp/SingleValuedFinder.java,v
  retrieving revision 1.9
  retrieving revision 1.10
  diff -u -r1.9 -r1.10
  --- SingleValuedFinder.java   3 Jul 2005 10:08:33 -0000       1.9
  +++ SingleValuedFinder.java   5 Aug 2005 10:52:09 -0000       1.10
  @@ -52,14 +52,13 @@
   
   import org.apache.geronimo.core.service.InvocationResult;
   import org.openejb.EJBInvocation;
  -import org.tranql.cache.InTxCache;
   import org.tranql.field.FieldTransform;
   import org.tranql.field.FieldTransformException;
   import org.tranql.field.Row;
  +import org.tranql.identity.IdentityDefiner;
   import org.tranql.ql.QueryException;
   import org.tranql.query.QueryCommand;
   import org.tranql.query.ResultHandler;
  -import org.tranql.sql.prefetch.PrefetchGroupHandler;
   
   /**
    * 
  @@ -69,27 +68,17 @@
   public class SingleValuedFinder extends CMPFinder {
       private static final Object NODATA = new Object();
   
  -    public SingleValuedFinder(QueryCommand localCommand, QueryCommand 
remoteCommand, boolean flushCache) {
  -        super(localCommand, remoteCommand, flushCache);
  +    public SingleValuedFinder(QueryCommand localCommand, QueryCommand 
remoteCommand, boolean flushCache, IdentityDefiner idDefiner, IdentityDefiner 
idInjector) {
  +        super(localCommand, remoteCommand, flushCache, idDefiner, 
idInjector);
       }
   
       public InvocationResult execute(EJBInvocation invocation) throws 
Throwable {
  -        InTxCache cache = flushCache(invocation);
  -        
           try {
               QueryCommand command = getCommand(invocation);
               FieldTransform resultAccessor = 
command.getQuery().getResultAccessors()[0];
  -            SingleValuedResultHandler handler =new 
SingleValuedResultHandler(resultAccessor, invocation);
  -            Row arguments = new Row(invocation.getArguments());
  -            PrefetchGroupHandler groupHandler = 
command.getQuery().getPrefetchGroupHandler();
  -            Object o;
  -            if (null != groupHandler) {
  -                groupHandler = new PrefetchGroupHandler(groupHandler, 
handler);
  -                o = groupHandler.execute(cache, command, arguments, NODATA);
  -            } else {
  -                o = command.execute(handler, arguments, NODATA);
  -            }
  -            return o == NODATA ? 
invocation.createExceptionResult((Exception)new ObjectNotFoundException()) : 
(InvocationResult) o;
  +            SingleValuedResultHandler handler = new 
SingleValuedResultHandler(resultAccessor, invocation);
  +            Object o = execute(invocation, handler, NODATA);
  +            return o == NODATA ? invocation.createExceptionResult(new 
ObjectNotFoundException()) : (InvocationResult) o;
           } catch (QueryException e) {
               return invocation.createExceptionResult((Exception)new 
FinderException(e.getMessage()).initCause(e));
           }
  @@ -112,11 +101,11 @@
                       throw new QueryException(e);
                   }
               }
  -            return invocation.createExceptionResult((Exception)new 
FinderException("More than one row returned from single valued finder"));
  +            return invocation.createExceptionResult(new 
FinderException("More than one row returned from single valued finder"));
           }
           
           public Object endFetched(Object arg0) throws QueryException {
               return arg0;
           }
       }
  -}
  +}
  \ No newline at end of file
  
  
  
  1.7       +6 -28     
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.6
  retrieving revision 1.7
  diff -u -r1.6 -r1.7
  --- SingleValuedSelect.java   3 Jul 2005 10:08:34 -0000       1.6
  +++ SingleValuedSelect.java   5 Aug 2005 10:52:09 -0000       1.7
  @@ -50,12 +50,10 @@
   import javax.ejb.FinderException;
   import javax.ejb.ObjectNotFoundException;
   
  -import org.tranql.cache.InTxCache;
  -import org.tranql.sql.prefetch.PrefetchGroupHandler;
   import org.tranql.field.FieldTransform;
   import org.tranql.field.FieldTransformException;
   import org.tranql.field.Row;
  -import org.tranql.ql.Query;
  +import org.tranql.identity.IdentityDefiner;
   import org.tranql.ql.QueryException;
   import org.tranql.query.QueryCommand;
   import org.tranql.query.ResultHandler;
  @@ -65,38 +63,18 @@
    * 
    * @version $Revision$ $Date$
    */
  -public class SingleValuedSelect implements InstanceOperation {
  +public class SingleValuedSelect extends CMPSelectMethod {
       private static final Object NODATA = new Object();
   
  -    private final QueryCommand command;
  -    private final FieldTransform resultAccessor;
  -    private final PrefetchGroupHandler groupHandler;
  -    private final boolean flushCache;
  -    
  -    public SingleValuedSelect(QueryCommand command, boolean flushCache) {
  -        this.command = command;
  -        this.flushCache = flushCache;
  -        
  -        Query query = command.getQuery();
  -        resultAccessor = query.getResultAccessors()[0];
  -        groupHandler = query.getPrefetchGroupHandler();
  +    public SingleValuedSelect(QueryCommand command, boolean flushCache, 
IdentityDefiner idDefiner, IdentityDefiner idInjector) {
  +        super(command, flushCache, idDefiner, idInjector);
       }
   
       public Object invokeInstance(CMPInstanceContext ctx, Object[] args) 
throws Exception {
  -        InTxCache cache = ctx.getTransactionContext().getInTxCache();
  -        if (flushCache) {
  -            cache.flush();
  -        }
  -
           Object o;
           try {
               ResultHandler handler = new 
SingleValuedResultHandler(resultAccessor);
  -            if (null != groupHandler) {
  -                PrefetchGroupHandler newHandler = new 
PrefetchGroupHandler(groupHandler, handler);
  -                o = newHandler.execute(cache, command, new Row(args), 
NODATA);
  -            } else {
  -                o = command.execute(handler, new Row(args), NODATA);
  -            }
  +            o = execute(ctx, handler, args, NODATA);
           } catch (QueryException e) {
               throw (FinderException) new 
FinderException(e.getMessage()).initCause(e);
           }
  
  
  
  1.1                  
openejb/modules/core/src/java/org/openejb/entity/cmp/CacheFiller.java
  
  Index: CacheFiller.java
  ===================================================================
  /* ====================================================================
   * Redistribution and use of this software and associated documentation
   * ("Software"), with or without modification, are permitted provided
   * that the following conditions are met:
   *
   * 1. Redistributions of source code must retain copyright
   *    statements and notices.  Redistributions must also contain a
   *    copy of this document.
   *
   * 2. Redistributions in binary form must reproduce this list of
   *    conditions and the following disclaimer in the documentation
   *    and/or other materials provided with the distribution.
   *
   * 3. The name "OpenEJB" must not be used to endorse or promote
   *    products derived from this Software without prior written
   *    permission of The OpenEJB Group.  For written permission,
   *    please contact [EMAIL PROTECTED]
   *
   * 4. Products derived from this Software may not be called "OpenEJB"
   *    nor may "OpenEJB" appear in their names without prior written
   *    permission of The OpenEJB Group. OpenEJB is a registered
   *    trademark of The OpenEJB Group.
   *
   * 5. Due credit should be given to the OpenEJB Project
   *    (http://openejb.org/).
   *
   * THIS SOFTWARE IS PROVIDED BY THE OPENEJB GROUP AND CONTRIBUTORS
   * ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT
   * NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
   * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL
   * THE OPENEJB GROUP OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
   * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
   * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
   * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
   * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
   * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
   * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
   * OF THE POSSIBILITY OF SUCH DAMAGE.
   *
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the OpenEJB Project.  For more information
   * please see <http://openejb.org/>.
   *
   * ====================================================================
   */
  package org.openejb.entity.cmp;
  
  import org.tranql.cache.AlreadyAssociatedException;
  import org.tranql.cache.CacheRow;
  import org.tranql.cache.InTxCache;
  import org.tranql.field.Row;
  import org.tranql.identity.GlobalIdentity;
  import org.tranql.identity.IdentityDefiner;
  import org.tranql.identity.UndefinedIdentityException;
  import org.tranql.ql.QueryException;
  import org.tranql.query.ResultHandler;
  
  /**
   * 
   * 
   * @version $Revision: 1.1 $ $Date: 2005/08/05 10:52:09 $
   */
  class CacheFiller implements ResultHandler {
      private final ResultHandler delegate;
      private final IdentityDefiner idDefiner;
      private final IdentityDefiner idInjector;
      private final InTxCache cache;
      
      public CacheFiller(ResultHandler delegate, IdentityDefiner idDefiner, 
IdentityDefiner idInjector, InTxCache cache) {
          this.delegate = delegate;
          this.idDefiner = idDefiner;
          this.idInjector = idInjector;
          this.cache = cache;
      }
  
      public Object fetched(Row row, Object arg) throws QueryException {
          try {
              GlobalIdentity id = idDefiner.defineIdentity(row);
              if (null == cache.get(id)) {
                  CacheRow cacheRow = id.getTable().emptyRow(id);
                  idInjector.injectIdentity(cacheRow);
                  cache.add(cacheRow);
              }
          } catch (UndefinedIdentityException e) {
              throw new QueryException(e);
          } catch (AlreadyAssociatedException e) {
              throw new QueryException(e);
          }
          return delegate.fetched(row, arg);
      }
  
      public Object endFetched(Object arg) throws QueryException {
          return delegate.endFetched(arg);
      }
  
  }
  
  
  

Reply via email to