dain        2004/04/11 22:23:56

  Modified:    modules/core/src/java/org/openejb/entity/cmp
                        CMPContainerBuilder.java CMPFinder.java
  Added:       modules/core/src/java/org/openejb/entity/cmp
                        CollectionResults.java QueryResultsFactory.java
                        SetResults.java
                        SingleValuedQueryResultsFactory.java
  Log:

  Added tests that work through the remote interface and fixed related bugs
  
  Revision  Changes    Path
  1.7       +36 -12    
openejb/modules/core/src/java/org/openejb/entity/cmp/CMPContainerBuilder.java
  
  Index: CMPContainerBuilder.java
  ===================================================================
  RCS file: 
/home/projects/openejb/scm/openejb/modules/core/src/java/org/openejb/entity/cmp/CMPContainerBuilder.java,v
  retrieving revision 1.6
  retrieving revision 1.7
  diff -u -r1.6 -r1.7
  --- CMPContainerBuilder.java  11 Apr 2004 16:58:04 -0000      1.6
  +++ CMPContainerBuilder.java  12 Apr 2004 02:23:56 -0000      1.7
  @@ -58,6 +58,8 @@
   import javax.ejb.EJBObject;
   import javax.sql.DataSource;
   
  +import org.apache.geronimo.deployment.DeploymentException;
  +
   import org.openejb.AbstractContainerBuilder;
   import org.openejb.EJBComponentType;
   import org.openejb.InstanceContextFactory;
  @@ -149,7 +151,17 @@
           CacheTable cacheTable = createCacheTable(ejb, queryTransformer, dataSource);
   
           // identity definer
  -        IdentityDefiner identityDefiner = new UserDefinedIdentity(cacheTable, 0);
  +        int pkSlot = -1;
  +        for (int index = 0; index < ejb.getAttributes().size(); index++) {
  +            Attribute attribute = (Attribute) ejb.getAttributes().get(index);
  +            if(attribute.isIdentity()) {
  +                if (pkSlot > 0) {
  +                    throw new DeploymentException("User defined pks are not 
currently supported");
  +                }
  +                pkSlot = index;
  +            }
  +        }
  +        IdentityDefiner identityDefiner = new UserDefinedIdentity(cacheTable, 
pkSlot);
   
           // the load all by primary key command
           QueryCommand loadCommand = createLoadAllCommand(ejb, queryTransformer, 
identityDefiner, dataSource);
  @@ -246,29 +258,41 @@
           SQLQuery updateSQLQuery = (SQLQuery) 
queryTransformer.transform(updateQuery);
           InputBinding[] updateBindings = 
BindingFactory.getInputBindings(updateSQLQuery.getParamTypes());
           UpdateCommand updateCommand = new JDBCUpdateCommand(ds, 
updateSQLQuery.getSQLText(), updateBindings);
  +
           // todo shouldn't query builder do this transform?
           List attributes = ejb.getAttributes();
  -        List updateTransformList = new ArrayList(attributes.size() * 2 + 1);
  +        List updateParamsList = new ArrayList(attributes.size() * 2);
  +        List pkParamsList = new ArrayList(1);
           for (int i = 0; i < attributes.size(); i++) {
               Attribute attribute = (Attribute) attributes.get(i);
  -            if(!attribute.isIdentity()) {
  -                updateTransformList.add(new ModifiedSlotDetector(i));
  -                updateTransformList.add(new ModifiedSlotAccessor(i));
  +            if(attribute.isIdentity()) {
  +                pkParamsList.add(new FieldAccessor(i));
  +            } else {
  +                updateParamsList.add(new ModifiedSlotDetector(i));
  +                updateParamsList.add(new ModifiedSlotAccessor(i));
               }
           }
  -
  -        // todo I'd bet this is wrong
  -        updateTransformList.add(new FieldAccessor(0));
  -        FieldTransform[] updateTransforms = (FieldTransform[]) 
updateTransformList.toArray(new FieldTransform[updateTransformList.size()]);
  +        updateParamsList.addAll(pkParamsList);
  +        FieldTransform[] updateTransforms = (FieldTransform[]) 
updateParamsList.toArray(new FieldTransform[updateParamsList.size()]);
           updateCommand = new ParamRemapper(updateCommand, updateTransforms);
   
  -
           // DELETE
           Query removeQuery = QueryBuilder.buildDelete(ejb).getQuery();
           SQLQuery removeSQLQuery = (SQLQuery) 
queryTransformer.transform(removeQuery);
           InputBinding[] removeBindings = 
BindingFactory.getInputBindings(removeSQLQuery.getParamTypes());
           UpdateCommand removeCommand = new JDBCUpdateCommand(ds, 
removeSQLQuery.getSQLText(), removeBindings);
   
  +        // todo shouldn't query builder do this transform?
  +        List removeParamsList = new ArrayList(1);
  +        for (int i = 0; i < attributes.size(); i++) {
  +            Attribute attribute = (Attribute) attributes.get(i);
  +            if(attribute.isIdentity()) {
  +                removeParamsList.add(new FieldAccessor(i));
  +            }
  +        }
  +        FieldTransform[] removeTransforms = (FieldTransform[]) 
removeParamsList.toArray(new FieldTransform[removeParamsList.size()]);
  +        removeCommand = new ParamRemapper(removeCommand, removeTransforms);
  +
           // defaults
           Object[] defaults = createDefaults(ejb);
   
  @@ -451,7 +475,7 @@
               Map.Entry entry = (Map.Entry) iterator.next();
               InterfaceMethodSignature signature = 
(InterfaceMethodSignature)entry.getKey();
               QueryCommand[] queryCommands = (QueryCommand[])entry.getValue();
  -            vopMap.put(signature, new CMPFinder(queryCommands[0], 
queryCommands[1]));
  +            vopMap.put(signature, new CMPFinder(queryCommands[0], queryCommands[1], 
new SingleValuedQueryResultsFactory()));
           }
           return vopMap;
       }
  
  
  
  1.5       +15 -11    
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.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- CMPFinder.java    11 Apr 2004 16:58:04 -0000      1.4
  +++ CMPFinder.java    12 Apr 2004 02:23:56 -0000      1.5
  @@ -48,6 +48,7 @@
   package org.openejb.entity.cmp;
   
   import java.io.Serializable;
  +import java.util.LinkedList;
   import javax.ejb.FinderException;
   import javax.ejb.ObjectNotFoundException;
   
  @@ -63,31 +64,34 @@
   import org.tranql.field.Row;
   
   /**
  - *
  - *
    * @version $Revision$ $Date$
    */
   public class CMPFinder implements VirtualOperation, Serializable {
       private final QueryCommand localQuery;
       private final QueryCommand remoteQuery;
  +    private final QueryResultsFactory resultsFactory;
   
  -    public CMPFinder(QueryCommand localQuery, QueryCommand remoteQuery) {
  +    public CMPFinder(QueryCommand localQuery, QueryCommand remoteQuery, 
QueryResultsFactory resultsFactory) {
           this.localQuery = localQuery;
           this.remoteQuery = remoteQuery;
  +        this.resultsFactory = resultsFactory;
       }
   
       public InvocationResult execute(EJBInvocation invocation) throws Throwable {
           InTxCache inTxCache = invocation.getTransactionContext().getInTxCache();
           try {
  +            QueryResult result;
               if (invocation.getType().isLocal()) {
  -                QueryResult result = localQuery.execute(inTxCache, new 
Row(invocation.getArguments()));
  -                if(result.next()) {
  -                    return new SimpleInvocationResult(true, 
result.getValues().get(0));
  -                } else {
  -                    return new SimpleInvocationResult(false, new 
ObjectNotFoundException());
  -                }
  +                result = localQuery.execute(inTxCache, new 
Row(invocation.getArguments()));
               } else {
  -                return new SimpleInvocationResult(true, 
remoteQuery.execute(inTxCache, new Row(invocation.getArguments())));
  +                result = remoteQuery.execute(inTxCache, new 
Row(invocation.getArguments()));
  +            }
  +
  +            Object returnValue = resultsFactory.createQueryResults(result);
  +            if (returnValue != null) {
  +                return new SimpleInvocationResult(true, result.getValues().get(0));
  +            } else {
  +                return new SimpleInvocationResult(false, new 
ObjectNotFoundException());
               }
           } catch (QueryException e) {
               return new SimpleInvocationResult(false, new 
FinderException().initCause(e));
  
  
  
  1.1                  
openejb/modules/core/src/java/org/openejb/entity/cmp/CollectionResults.java
  
  Index: CollectionResults.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 java.util.Collection;
  import java.util.Iterator;
  import java.util.LinkedList;
  
  import org.tranql.query.QueryResult;
  import org.tranql.ql.QueryException;
  
  /**
   * @version $Revision: 1.1 $ $Date: 2004/04/12 02:23:56 $
   */
  public class CollectionResults implements Collection {
      public static class Factory implements QueryResultsFactory {
          public Object createQueryResults(QueryResult result) throws QueryException {
              LinkedList list = new LinkedList();
              while(result.next()) {
                  list.add(result.getValues().get(0));
              }
              return new CollectionResults(list);
          }
      }
  
      private final Collection delegate;
  
      public CollectionResults(Collection delegate) {
          this.delegate = delegate;
      }
  
      public int size() {
          return delegate.size();
      }
  
      public boolean isEmpty() {
          return delegate.isEmpty();
      }
  
      public boolean contains(Object o) {
          return delegate.contains(o);
      }
  
      public Iterator iterator() {
          return new Iterator() {
              private Iterator iterator = delegate.iterator();
  
              public boolean hasNext() {
                  return iterator.hasNext();
              }
  
              public Object next() {
                  return iterator.next();
              }
  
              public void remove() {
                  iterator.remove();
              }
          };
      }
  
      public Object[] toArray() {
          return delegate.toArray();
      }
  
      public Object[] toArray(Object a[]) {
          return delegate.toArray(a);
      }
  
      public boolean add(Object o) {
          return delegate.add(o);
      }
  
      public boolean remove(Object o) {
          return delegate.remove(o);
      }
  
      public boolean containsAll(Collection c) {
          return delegate.containsAll(c);
      }
  
      public boolean addAll(Collection c) {
          return delegate.addAll(c);
      }
  
      public boolean removeAll(Collection c) {
          return delegate.removeAll(c);
      }
  
      public boolean retainAll(Collection c) {
          return delegate.retainAll(c);
      }
  
      public void clear() {
          delegate.clear();
      }
  
      public boolean equals(Object o) {
          return delegate.equals(o);
      }
  
      public int hashCode() {
          return delegate.hashCode();
      }
  
      public String toString() {
          return delegate.toString();
      }
  }
  
  
  
  1.1                  
openejb/modules/core/src/java/org/openejb/entity/cmp/QueryResultsFactory.java
  
  Index: QueryResultsFactory.java
  ===================================================================
  /**
   *
   * Copyright 2004 The Apache Software Foundation
   *
   *  Licensed under the Apache License, Version 2.0 (the "License");
   *  you may not use this file except in compliance with the License.
   *  You may obtain a copy of the License at
   *
   *     http://www.apache.org/licenses/LICENSE-2.0
   *
   *  Unless required by applicable law or agreed to in writing, software
   *  distributed under the License is distributed on an "AS IS" BASIS,
   *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   *  See the License for the specific language governing permissions and
   *  limitations under the License.
   */
  package org.openejb.entity.cmp;
  
  import org.tranql.query.QueryResult;
  import org.tranql.ql.QueryException;
  
  /**
   * 
   * 
   * @version $Revision: 1.1 $ $Date: 2004/04/12 02:23:56 $
   */
  public interface QueryResultsFactory {
      public Object createQueryResults(QueryResult result) throws QueryException;
  }
  
  
  
  1.1                  
openejb/modules/core/src/java/org/openejb/entity/cmp/SetResults.java
  
  Index: SetResults.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 java.util.Collection;
  import java.util.LinkedList;
  
  import org.tranql.query.QueryResult;
  import org.tranql.ql.QueryException;
  
  /**
   * @version $Revision: 1.1 $ $Date: 2004/04/12 02:23:56 $
   */
  public class SetResults extends CollectionResults {
      public static class Factory implements QueryResultsFactory {
          public Object createQueryResults(QueryResult result) throws QueryException {
              LinkedList list = new LinkedList();
              while(result.next()) {
                  list.add(result.getValues().get(0));
              }
              return new SetResults(list);
          }
      }
  
      public SetResults(Collection delegate) {
          super(delegate);
      }
  }
  
  
  
  1.1                  
openejb/modules/core/src/java/org/openejb/entity/cmp/SingleValuedQueryResultsFactory.java
  
  Index: SingleValuedQueryResultsFactory.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.ql.QueryException;
  import org.tranql.query.QueryResult;
  
  /**
   * 
   * 
   * @version $Revision: 1.1 $ $Date: 2004/04/12 02:23:56 $
   */
  public class SingleValuedQueryResultsFactory implements QueryResultsFactory {
      public Object createQueryResults(QueryResult result) throws QueryException {
          if(result.next()) {
              return result.getValues().get(0);
          }
          return null;
      }
  }
  
  
  

Reply via email to