You are viewing a plain text version of this content. The canonical link for it is here.
Posted to ojb-dev@db.apache.org by ar...@apache.org on 2003/08/06 02:20:13 UTC

cvs commit: db-ojb/src/test/org/apache/ojb OJB.properties

arminw      2003/08/05 17:20:13

  Modified:    src/java/org/apache/ojb/odmg OJB.java
               src/test/org/apache/ojb/odmg DListTest.java
                        OdmgExamples.java ODMGGourmet.java
               src/test/org/apache/ojb OJB.properties
  Added:       src/java/org/apache/ojb/odmg/collections
                        DCollectionFactory.java DListEntry_2.java
                        DListImpl_2.java DListIterator_2.java
  Log:
  - make odmg collection implementations
  pluggable via OJB.properties
  - add new DList implementation
  
  Revision  Changes    Path
  1.1                  db-ojb/src/java/org/apache/ojb/odmg/collections/DCollectionFactory.java
  
  Index: DCollectionFactory.java
  ===================================================================
  package org.apache.ojb.odmg.collections;
  
  import org.odmg.DList;
  import org.odmg.DBag;
  import org.odmg.DSet;
  import org.odmg.DArray;
  import org.odmg.DMap;
  import org.apache.ojb.broker.util.factory.ConfigurableFactory;
  import org.apache.ojb.broker.PBKey;
  
  /**
   * Factory for ODMG DCollection (DList, DBag, ...) and DMap instances.
   *
   * @author <a href="mailto:armin@codeAuLait.de">Armin Waibel</a>
   * @version $Id: DCollectionFactory.java,v 1.1 2003/08/06 00:20:13 arminw Exp $
   */
  public class DCollectionFactory
  {
      private static final DCollectionFactory singleton;
  
      static
      {
          singleton = new DCollectionFactory();
      }
  
      private DCollectionFactory()
      {
      }
  
      public static DCollectionFactory getInstance()
      {
          return singleton;
      }
  
      public DList createDList()
      {
          return (DList) DListFactory.singleton.createCollectionOrMap();
      }
  
      public DList createDList(PBKey key)
      {
          return (DList) DListFactory.singleton.createCollectionOrMap(key);
      }
  
      public DBag createDBag()
      {
          return (DBag) DBagFactory.singleton.createCollectionOrMap();
      }
  
      public DBag createDBag(PBKey key)
      {
          return (DBag) DBagFactory.singleton.createCollectionOrMap(key);
      }
  
      public DSet createDSet()
      {
          return (DSet) DSetFactory.singleton.createCollectionOrMap();
      }
  
      public DSet createDSet(PBKey key)
      {
          return (DSet) DSetFactory.singleton.createCollectionOrMap(key);
      }
  
      public DArray createDArray()
      {
          return (DArray) DArrayFactory.singleton.createCollectionOrMap();
      }
  
      public DArray createDArray(PBKey key)
      {
          return (DArray) DArrayFactory.singleton.createCollectionOrMap(key);
      }
  
      public DMap createDMap()
      {
          return (DMap) DMapFactory.singleton.createCollectionOrMap();
      }
  
      public DMap createDMap(PBKey key)
      {
          return (DMap) DMapFactory.singleton.createCollectionOrMap(key);
      }
  
      //*****************************************************
      // inner classes
      //*****************************************************
  
      abstract static class BaseFactory extends ConfigurableFactory
      {
          Object createCollectionOrMap()
          {
              return this.createNewInstance();
          }
  
          Object createCollectionOrMap(PBKey key)
          {
              return createNewInstance(PBKey.class, key);
          }
      }
  
      static final class DListFactory extends BaseFactory
      {
          static final BaseFactory singleton = new DListFactory();
          protected String getConfigurationKey()
          {
              return "DListClass";
          }
      }
  
      static final class DArrayFactory extends BaseFactory
      {
          static final BaseFactory singleton = new DArrayFactory();
          protected String getConfigurationKey()
          {
              return "DArrayClass";
          }
      }
  
      static final class DBagFactory extends BaseFactory
      {
          static final BaseFactory singleton = new DBagFactory();
          protected String getConfigurationKey()
          {
              return "DBagClass";
          }
      }
  
      static final class DSetFactory extends BaseFactory
      {
          static final BaseFactory singleton = new DSetFactory();
          protected String getConfigurationKey()
          {
              return "DSetClass";
          }
      }
  
      static final class DMapFactory extends BaseFactory
      {
          static final BaseFactory singleton = new DMapFactory();
          protected String getConfigurationKey()
          {
              return "DMapClass";
          }
      }
  }
  
  
  
  1.1                  db-ojb/src/java/org/apache/ojb/odmg/collections/DListEntry_2.java
  
  Index: DListEntry_2.java
  ===================================================================
  package org.apache.ojb.odmg.collections;
  
  /* ====================================================================
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 2001 The Apache Software Foundation.  All rights
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   *    notice, this list of conditions and the following disclaimer.
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in
   *    the documentation and/or other materials provided with the
   *    distribution.
   *
   * 3. The end-user documentation included with the redistribution,
   *    if any, must include the following acknowledgment:
   *       "This product includes software developed by the
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowledgment may appear in the software itself,
   *    if and wherever such third-party acknowledgments normally appear.
   *
   * 4. The names "Apache" and "Apache Software Foundation" and
   *    "Apache ObjectRelationalBridge" must not be used to endorse or promote products
   *    derived from this software without prior written permission. For
   *    written permission, please contact apache@apache.org.
   *
   * 5. Products derived from this software may not be called "Apache",
   *    "Apache ObjectRelationalBridge", nor may "Apache" appear in their name, without
   *    prior written permission of the Apache Software Foundation.
   *
   * THIS SOFTWARE IS PROVIDED ``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 APACHE SOFTWARE FOUNDATION 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 Apache Software Foundation.  For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   */
  
  import org.apache.commons.lang.builder.ToStringBuilder;
  import org.apache.ojb.broker.Identity;
  import org.apache.ojb.broker.OJBRuntimeException;
  import org.apache.ojb.broker.PBKey;
  import org.apache.ojb.broker.PersistenceBroker;
  import org.apache.ojb.odmg.TransactionExt;
  import org.apache.ojb.odmg.TxManagerFactory;
  
  import java.io.Serializable;
  
  /**
   * Insert the type's description here.
   * Creation date: (28.01.2001 21:23:26)
   * @author Thomas Mahler
   * @author <a href="mailto:armin@codeAuLait.de">Armin Waibel</a>
   * @version $Id: DListEntry_2.java,v 1.1 2003/08/06 00:20:13 arminw Exp $
   */
  public class DListEntry_2 implements Serializable
  {
      /*
      declare transient or do we adopt persistent object is serialzable?
      */
      protected Object realSubject;
      protected DListImpl_2 dList;
  
      protected Integer id;
      protected Integer dlistId;
      protected Identity oid;
      protected int position;
  
      /**
       * Used to instantiate persistent DLists from DB
       */
      public DListEntry_2()
      {
          super();
      }
  
      /**
       * Standard way to instantiate new entries
       */
      public DListEntry_2(DListImpl_2 dList, Object theObject)
      {
          this.dList = dList;
          this.dlistId = dList.getId();
          this.position = dList.size();
          this.realSubject = theObject;
      }
  
      protected void prepareForPersistency(PersistenceBroker broker)
      {
          if (oid == null)
          {
              if (realSubject == null)
              {
                  throw new OJBRuntimeException("Identity and real object are 'null' - Can not persist empty entry");
              }
              else
              {
                  oid = new Identity(realSubject, broker);
              }
          }
      }
  
      public PBKey getPBKey()
      {
          return dList != null ? dList.getPBKey() : null;
      }
  
      /**
       * Insert the method's description here.
       * Creation date: (06.02.2001 22:06:55)
       * @return int
       */
      public int getPosition()
      {
          return position;
      }
  
      /**
       * Insert the method's description here.
       * Creation date: (30.01.2001 22:32:10)
       * @return java.lang.Object
       */
      protected void prepareRealSubject(PersistenceBroker broker)
      {
          if (realSubject == null)
          {
              if (oid == null)
              {
                  throw new OJBRuntimeException("can not return real object, real object and Identity is null");
              }
              realSubject = broker.getObjectByIdentity(oid);
          }
      }
  
      public Object getRealSubject()
      {
          if (realSubject != null)
          {
              return realSubject;
          }
          else
          {
              TransactionExt tx = (TransactionExt) TxManagerFactory.instance().getTransaction();
              if (tx != null && tx.isOpen())
              {
                  prepareRealSubject(tx.getBroker());
              }
          }
          return realSubject;
      }
  
  
      /**
       * Insert the method's description here.
       * Creation date: (06.02.2001 22:06:55)
       * @param newPosition int
       */
      public void setPosition(int newPosition)
      {
          position = newPosition;
      }
  
      /**
       * Insert the method's description here.
       * Creation date: (10.02.2001 17:58:45)
       * @param realSubject java.lang.Object
       */
      void setRealSubject(Object realSubject)
      {
          this.realSubject = realSubject;
      }
  
      /**
       * Gets the dlistId.
       * @return Returns a int
       */
      public Integer getDlistId()
      {
          return dlistId;
      }
  
      /**
       * Sets the dlistId.
       * @param dlistId The dlistId to set
       */
      public void setDlistId(Integer dlistId)
      {
          this.dlistId = dlistId;
      }
  
      /**
       * Gets the id.
       * @return Returns a int
       */
      public Integer getId()
      {
          return id;
      }
  
      /**
       * Sets the id.
       * @param id The id to set
       */
      public void setId(Integer id)
      {
          this.id = id;
      }
  
      public Identity getOid()
      {
          return oid;
      }
  
      public void setOid(Identity oid)
      {
          this.oid = oid;
      }
  
      /**
       * return String representation.
       */
      public String toString()
      {
          ToStringBuilder buf = new ToStringBuilder(this);
          buf.append("id", id);
          buf.append("dListId", dlistId);
          buf.append("position", position);
          buf.append("identity", oid);
          buf.append("realSubject", realSubject);
          return buf.toString();
      }
  }
  
  
  
  1.1                  db-ojb/src/java/org/apache/ojb/odmg/collections/DListImpl_2.java
  
  Index: DListImpl_2.java
  ===================================================================
  package org.apache.ojb.odmg.collections;
  
  /* ====================================================================
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 2001 The Apache Software Foundation.  All rights
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   *    notice, this list of conditions and the following disclaimer.
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in
   *    the documentation and/or other materials provided with the
   *    distribution.
   *
   * 3. The end-user documentation included with the redistribution,
   *    if any, must include the following acknowledgment:
   *       "This product includes software developed by the
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowledgment may appear in the software itself,
   *    if and wherever such third-party acknowledgments normally appear.
   *
   * 4. The names "Apache" and "Apache Software Foundation" and
   *    "Apache ObjectRelationalBridge" must not be used to endorse or promote products
   *    derived from this software without prior written permission. For
   *    written permission, please contact apache@apache.org.
   *
   * 5. Products derived from this software may not be called "Apache",
   *    "Apache ObjectRelationalBridge", nor may "Apache" appear in their name, without
   *    prior written permission of the Apache Software Foundation.
   *
   * THIS SOFTWARE IS PROVIDED ``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 APACHE SOFTWARE FOUNDATION 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 Apache Software Foundation.  For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   */
  
  import org.apache.commons.lang.builder.ToStringBuilder;
  import org.apache.ojb.broker.ManageableCollection;
  import org.apache.ojb.broker.OJBRuntimeException;
  import org.apache.ojb.broker.PBKey;
  import org.apache.ojb.broker.PersistenceBroker;
  import org.apache.ojb.broker.PersistenceBrokerAware;
  import org.apache.ojb.broker.PersistenceBrokerException;
  import org.apache.ojb.broker.metadata.ClassDescriptor;
  import org.apache.ojb.broker.metadata.FieldDescriptor;
  import org.apache.ojb.broker.query.Criteria;
  import org.apache.ojb.broker.query.Query;
  import org.apache.ojb.broker.query.QueryByCriteria;
  import org.apache.ojb.broker.util.logging.Logger;
  import org.apache.ojb.broker.util.logging.LoggerFactory;
  import org.apache.ojb.odmg.PBCapsule;
  import org.apache.ojb.odmg.TransactionImpl;
  import org.apache.ojb.odmg.TxManagerFactory;
  import org.apache.ojb.odmg.oql.OQLQueryImpl;
  import org.odmg.DArray;
  import org.odmg.DCollection;
  import org.odmg.DList;
  import org.odmg.ODMGRuntimeException;
  import org.odmg.OQLQuery;
  import org.odmg.QueryInvalidException;
  import org.odmg.Transaction;
  
  import java.util.AbstractList;
  import java.util.ArrayList;
  import java.util.Iterator;
  import java.util.List;
  import java.util.ListIterator;
  import java.util.Vector;
  
  
  /**
   *
   * @author Thomas Mahler
   * @author <a href="mailto:armin@codeAuLait.de">Armin Waibel</a>
   * @version $Id: DListImpl_2.java,v 1.1 2003/08/06 00:20:13 arminw Exp $
   */
  public class DListImpl_2 extends AbstractList implements DList, DArray,
          ManageableCollection, PersistenceBrokerAware
  {
      /*
       * declare transient, because ManageableCollection is {@link java.io.Serializable}.
       */
      private transient Logger log;
      private Integer id;
      private List elements;
      private int size;
      /**
       * PBKey this DList belongs to.
       */
      private PBKey pbKey;
  
      /**
       * Used by PB-Kernel to instantiate ManageableCollections
       */
      public DListImpl_2()
      {
          super();
          elements = new ArrayList();
          this.size = 0;
      }
  
      /**
       * Used on odmg-level
       */
      public DListImpl_2(PBKey pbKey)
      {
          this();
          this.pbKey = pbKey;
      }
  
      protected Logger getLog()
      {
          if (log == null)
          {
              log = LoggerFactory.getLogger(DListImpl_2.class);
          }
          return log;
      }
  
      private DListEntry_2 prepareEntry(Object obj)
      {
          return new DListEntry_2(this, obj);
      }
  
      public PBKey getPBKey()
      {
          return pbKey;
      }
  
      public void setPBKey(PBKey pbKey)
      {
          this.pbKey = pbKey;
      }
  
      public int hashCode()
      {
          int hashCode = 1;
          Iterator it = elements.iterator();
          while (it.hasNext())
          {
              Object obj = it.next();
              hashCode = 31 * hashCode + (obj == null ? 0 : obj.hashCode());
          }
          return hashCode;
      }
  
      public String toString()
      {
          ToStringBuilder buf = new ToStringBuilder(this);
          buf.append("id", id);
          buf.append("pbKey", pbKey);
          buf.append("size", size);
          buf.append("[containing elements: ");
          Iterator it = elements.iterator();
          while (it.hasNext())
          {
              Object obj = it.next();
              buf.append(obj != null ? obj.toString() : null);
          }
          buf.append("]");
          return buf.toString();
      }
  
      /**
       * Inserts the specified element at the specified position in this list
       * (optional operation).  Shifts the element currently at that position
       * (if any) and any subsequent elements to the right (adds one to their
       * indices).
       *
       * @param index index at which the specified element is to be inserted.
       * @param element element to be inserted.
       *
       * @throws UnsupportedOperationException if the <tt>add</tt> method is not
       * supported by this list.
       * @throws    ClassCastException if the class of the specified element
       * prevents it from being added to this list.
       * @throws    IllegalArgumentException if some aspect of the specified
       * element prevents it from being added to this list.
       * @throws    IndexOutOfBoundsException if the index is out of range
       * (index &lt; 0 || index &gt; size()).
       */
      public void add(int index, Object element)
      {
          DListEntry_2 entry = prepareEntry(element);
          elements.add(index, entry);
          this.size++;
          // if we are in a transaction: acquire locks !
          TransactionImpl tx = TxManagerFactory.instance().getTransaction();
          if ((tx != null) && (tx.isOpen()))
          {
              tx.lock(this, Transaction.WRITE);
              tx.lock(entry, Transaction.WRITE);
              tx.lock(element, Transaction.READ);
              entry.prepareForPersistency(tx.getBroker());
          }
  
          // changing the position markers of entries:
          int offset = 0;
          try
          {
              offset = ((DListEntry_2) elements.get(index - 1)).getPosition();
          }
          catch (Exception ignored)
          {
          }
          for (int i = offset; i < elements.size(); i++)
          {
              entry = (DListEntry_2) elements.get(i);
              entry.setPosition(i);
          }
      }
  
      /**
       * Removes the element at the specified position in this list (optional
       * operation).  Shifts any subsequent elements to the left (subtracts one
       * from their indices).  Returns the element that was removed from the
       * list.<p>
       *
       * This implementation always throws an
       * <tt>UnsupportedOperationException</tt>.
       *
       * @param index the index of the element to remove.
       * @return the element previously at the specified position.
       *
       * @throws UnsupportedOperationException if the <tt>remove</tt> method is
       *		  not supported by this list.
       * @throws IndexOutOfBoundsException if the specified index is out of
       * 		  range (<tt>index &lt; 0 || index &gt;= size()</tt>).
       */
      public Object remove(int index)
      {
          DListEntry_2 entry = (DListEntry_2) elements.get(index);
          // if we are in a transaction: acquire locks !
          TransactionImpl tx = TxManagerFactory.instance().getTransaction();
          if ((tx != null) && (tx.isOpen()))
          {
              tx.markDelete(entry);
          }
          this.size--;
          elements.remove(index);
          // changing the position markers of entries:
          int offset = 0;
          try
          {
              offset = ((DListEntry_2) elements.get(index)).getPosition();
          }
          catch (Exception ignored)
          {
          }
          for (int i = offset; i < elements.size(); i++)
          {
              entry = (DListEntry_2) elements.get(i);
              entry.setPosition(i);
          }
  
          return entry.getRealSubject();
      }
  
      /**
       * Creates a new <code>DList</code> object that contains the contents of this
       * <code>DList</code> object concatenated
       * with the contents of the <code>otherList</code> object.
       * @param	otherList	The list whose elements are placed at the end of the list
       * returned by this method.
       * @return	A new <code>DList</code> that is the concatenation of this list and
       * the list referenced by <code>otherList</code>.
       */
      public DList concat(DList otherList)
      {
          DListImpl_2 result = new DListImpl_2(pbKey);
          result.addAll(this);
          result.addAll(otherList);
          return result;
      }
  
      /**
       * Determines whether there is an element of the collection that evaluates to true
       * for the predicate.
       * @param	predicate	An OQL boolean query predicate.
       * @return	True if there is an element of the collection that evaluates to true
       * for the predicate, otherwise false.
       * @exception	org.odmg.QueryInvalidException	The query predicate is invalid.
       */
      public boolean existsElement(String predicate) throws org.odmg.QueryInvalidException
      {
          DList results = (DList) this.query(predicate);
          if (results == null || results.size() == 0)
              return false;
          else
              return true;
  
      }
  
      /**
       * Returns the element at the specified position in this list.
       *
       * @param index index of element to return.
       * @return the element at the specified position in this list.
       *
       * @throws IndexOutOfBoundsException if the index is out of range (index
       * &lt; 0 || index &gt;= size()).
       */
      public Object get(int index)
      {
          DListEntry_2 entry = (DListEntry_2) elements.get(index);
          return entry.getRealSubject();
      }
  
      /**
       * Insert the method's description here.
       * Creation date: (10.02.2001 20:53:01)
       * @return java.util.Vector
       */
      public List getElements()
      {
          return elements;
      }
  
      /**
       * Lazily return the Id, no point in precomputing it.
       * @return int
       */
      public Integer getId()
      {
          return id;
      }
  
      /**
       * Returns an iterator over the elements in this collection.  There are no
       * guarantees concerning the order in which the elements are returned
       * (unless this collection is an instance of some class that provides a
       * guarantee).
       *
       * @return an <tt>Iterator</tt> over the elements in this collection
       */
      public Iterator iterator()
      {
          return new DListIterator_2(this);
      }
  
      /**
       * Returns a list iterator of the elements in this list (in proper
       * sequence).
       *
       * @return a list iterator of the elements in this list (in proper
       * sequence).
       */
      public ListIterator listIterator()
      {
          return new DListIterator_2(this);
      }
  
      /**
       * Returns a list iterator of the elements in this list (in proper
       * sequence), starting at the specified position in this list.  The
       * specified index indicates the first element that would be returned by
       * an initial call to the <tt>next</tt> method.  An initial call to
       * the <tt>previous</tt> method would return the element with the
       * specified index minus one.
       *
       * @param index index of first element to be returned from the
       * list iterator (by a call to the <tt>next</tt> method).
       * @return a list iterator of the elements in this list (in proper
       * sequence), starting at the specified position in this list.
       * @throws IndexOutOfBoundsException if the index is out of range (index
       * &lt; 0 || index &gt; size()).
       */
      public ListIterator listIterator(int index)
      {
          return new DListIterator_2(this, index);
      }
  
      private Criteria getPkCriteriaForAllElements(PersistenceBroker brokerForClass)
      {
          try
          {
              Criteria crit = null;
              for (int i = 0; i < elements.size(); i++)
              {
                  DListEntry_2 entry = (DListEntry_2) elements.get(i);
                  Object obj = entry.getRealSubject();
                  ClassDescriptor cld = brokerForClass.getClassDescriptor(obj.getClass());
  
                  FieldDescriptor[] pkFields = cld.getPkFields();
                  Object[] pkValues = brokerForClass.serviceBrokerHelper().getKeyValues(cld, obj);
  
                  Criteria criteria = new Criteria();
                  for (int j = 0; j < pkFields.length; j++)
                  {
                      FieldDescriptor fld = pkFields[j];
                      criteria.addEqualTo(fld.getPersistentField().getName(), pkValues[j]);
                  }
  
                  if (crit == null)
                      crit = criteria;
                  else
                      crit.addOrCriteria(criteria);
              }
              return crit;
          }
          catch (PersistenceBrokerException e)
          {
              return null;
          }
      }
  
      private Class getElementsExtentClass(PersistenceBroker brokerForClass) throws PersistenceBrokerException
      {
          // we ll have to compute the most general extent class here !!!
          DListEntry_2 entry = (DListEntry_2) elements.get(0);
          Class elementsClass = entry.getRealSubject().getClass();
          Class extentClass = brokerForClass.getTopLevelClass(elementsClass);
          return extentClass;
      }
  
      /**
       * Evaluate the boolean query predicate for each element of the collection and
       * return a new collection that contains each element that evaluated to true.
       * @param	predicate	An OQL boolean query predicate.
       * @return	A new collection containing the elements that evaluated true for the predicate.
       * @exception	org.odmg.QueryInvalidException	The query predicate is invalid.
       */
      public DCollection query(String predicate) throws QueryInvalidException
      {
          // 1.build complete OQL statement
          String oql = "select all from java.lang.Object where " + predicate;
          /*TODO: Use a ObjectFactory to instantiate OQLQuery? */
          OQLQuery predicateQuery = new OQLQueryImpl(pbKey);
          predicateQuery.create(oql);
          Query pQ = ((OQLQueryImpl) predicateQuery).getQuery();
          Criteria pCrit = pQ.getCriteria();
  
          Transaction tx = TxManagerFactory.instance().getTransaction();
          if (tx == null) throw new QueryInvalidException("Need running transaction to do query");
          PBCapsule handle = new PBCapsule(pbKey, tx);
          DList result;
          try
          {
              PersistenceBroker broker = handle.getBroker();
              Criteria allElementsCriteria = this.getPkCriteriaForAllElements(broker);
              // join selection of elements with predicate criteria:
              allElementsCriteria.addAndCriteria(pCrit);
  
              Class clazz = null;
              try
              {
                  clazz = this.getElementsExtentClass(broker);
              }
              catch (PersistenceBrokerException e)
              {
                  throw new ODMGRuntimeException(e.getMessage());
              }
              Query q = new QueryByCriteria(clazz, allElementsCriteria);
              if (getLog().isDebugEnabled()) getLog().debug(q.toString());
  
              result = null;
              try
              {
                  result = (DList) broker.getCollectionByQuery(DListImpl_2.class, q);
              }
              catch (PersistenceBrokerException e)
              {
                  getLog().error("Query failed", e);
                  throw new OJBRuntimeException(e);
              }
          }
          finally
          {
              // cleanup stuff
              if (handle != null) handle.destroy();
          }
  
          // 3. return resulting collection
          return result;
  
      }
  
      /**
       * Access all of the elements of the collection that evaluate to true for the
       * provided query predicate.
       * @param	predicate	An OQL boolean query predicate.
       * @return	An iterator used to iterate over the elements that evaluated true for the predicate.
       * @exception	org.odmg.QueryInvalidException	The query predicate is invalid.
       */
      public Iterator select(String predicate) throws org.odmg.QueryInvalidException
      {
          return this.query(predicate).iterator();
      }
  
      /**
       * Selects the single element of the collection for which the provided OQL query
       * predicate is true.
       * @param	predicate	An OQL boolean query predicate.
       * @return The element that evaluates to true for the predicate. If no element
       * evaluates to true, null is returned.
       * @exception	org.odmg.QueryInvalidException	The query predicate is invalid.
       */
      public Object selectElement(String predicate) throws org.odmg.QueryInvalidException
      {
          return ((DList) this.query(predicate)).get(0);
      }
  
      /**
       * Returns the number of elements in this collection.  If this collection
       * contains more than <tt>Integer.MAX_VALUE</tt> elements, returns
       * <tt>Integer.MAX_VALUE</tt>.
       *
       * @return the number of elements in this collection
       */
      public int size()
      {
          return elements.size();
      }
  
      /**
       * add a single Object to the Collection. This method is used during reading Collection elements
       * from the database. Thus it is is save to cast anObject to the underlying element type of the
       * collection.
       */
      public void ojbAdd(Object anObject)
      {
          this.size++;
          DListEntry_2 entry = prepareEntry(anObject);
          entry.setPosition(elements.size());
          elements.add(entry);
      }
  
      /**
       * adds a Collection to this collection. Used in reading Extents from the Database.
       * Thus it is save to cast otherCollection to this.getClass().
       */
      public void ojbAddAll(ManageableCollection otherCollection)
      {
          // don't use this to avoid locking
          // this.addAll((DListImpl_2) otherCollection);
          Iterator it = otherCollection.ojbIterator();
          while (it.hasNext())
          {
              ojbAdd(it.next());
          }
      }
  
      public void afterStore(PersistenceBroker broker) throws PersistenceBrokerException
      {
      }
  
      /**
       * returns an Iterator over all elements in the collection. Used during store and delete Operations.
       * If the implementor does not return an iterator over ALL elements, OJB cannot store and delete all elements properly.
       */
      public Iterator ojbIterator()
      {
          return this.iterator();
      }
  
      /**
       * Resize the array to have <code>newSize</code> elements.
       * @param	newSize	The new size of the array.
       */
      public void resize(int newSize)
      {
      }
  
      /**
       * Sets the elements.
       * @param elements The elements to set
       */
      public void setElements(Vector elements)
      {
          this.elements = elements;
      }
  
      /**
       * Sets the id.
       * @param id The id to set
       */
      public void setId(Integer id)
      {
          this.id = id;
      }
  
      /**
       * Gets the size.
       * @return Returns a int
       */
      public int getSize()
      {
          return size;
      }
  
      /**
       * Sets the size.
       * @param size The size to set
       */
      public void setSize(int size)
      {
          this.size = size;
      }
  
  
      //***************************************************************
      // PersistenceBrokerAware interface
      //***************************************************************
  
      /**
       * prepare itself for persistence. Each DList entry generates an
       * {@link org.apache.ojb.broker.Identity} for the wrapped persistent
       * object.
       */
      public void beforeInsert(PersistenceBroker broker) throws PersistenceBrokerException
      {
          Iterator it = elements.iterator();
          DListEntry_2 entry;
          while (it.hasNext())
          {
              entry = (DListEntry_2) it.next();
              entry.prepareForPersistency(broker);
          }
      }
  
      /**
       * noop
       */
      public void beforeUpdate(PersistenceBroker broker) throws PersistenceBrokerException
      {
      }
  
      /**
       * noop
       */
      public void beforeDelete(PersistenceBroker broker) throws PersistenceBrokerException
      {
      }
  
      /**
       * noop
       */
      public void afterUpdate(PersistenceBroker broker) throws PersistenceBrokerException
      {
      }
  
      /**
       * noop
       */
      public void afterInsert(PersistenceBroker broker) throws PersistenceBrokerException
      {
      }
  
      /**
       * noop
       */
      public void afterDelete(PersistenceBroker broker) throws PersistenceBrokerException
      {
      }
  
      /**
       * noop
       */
      public void afterLookup(PersistenceBroker broker) throws PersistenceBrokerException
      {
      }
  }
  
  
  
  1.1                  db-ojb/src/java/org/apache/ojb/odmg/collections/DListIterator_2.java
  
  Index: DListIterator_2.java
  ===================================================================
  package org.apache.ojb.odmg.collections;
  
  /* ====================================================================
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 2001 The Apache Software Foundation.  All rights
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   *    notice, this list of conditions and the following disclaimer.
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in
   *    the documentation and/or other materials provided with the
   *    distribution.
   *
   * 3. The end-user documentation included with the redistribution,
   *    if any, must include the following acknowledgment:
   *       "This product includes software developed by the
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowledgment may appear in the software itself,
   *    if and wherever such third-party acknowledgments normally appear.
   *
   * 4. The names "Apache" and "Apache Software Foundation" and
   *    "Apache ObjectRelationalBridge" must not be used to endorse or promote products
   *    derived from this software without prior written permission. For
   *    written permission, please contact apache@apache.org.
   *
   * 5. Products derived from this software may not be called "Apache",
   *    "Apache ObjectRelationalBridge", nor may "Apache" appear in their name, without
   *    prior written permission of the Apache Software Foundation.
   *
   * THIS SOFTWARE IS PROVIDED ``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 APACHE SOFTWARE FOUNDATION 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 Apache Software Foundation.  For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   */
  
  import org.apache.ojb.odmg.TransactionImpl;
  import org.apache.ojb.odmg.TxManagerFactory;
  import org.odmg.Transaction;
  
  import java.util.ListIterator;
  
  /**
   * Insert the type's description here.
   * Creation date: (09.02.2001 15:49:39)
   * @author Thomas Mahler
   * @author <a href="mailto:armin@codeAuLait.de">Armin Waibel</a>
   * @version $Id: DListIterator_2.java,v 1.1 2003/08/06 00:20:13 arminw Exp $
   */
  class DListIterator_2 implements ListIterator
  {
      protected ListIterator iter;
      private DListImpl_2 dlist;
      private DListEntry_2 currentEntry = null;
  
      /**
       * DListIterator constructor comment.
       */
      public DListIterator_2(DListImpl_2 list)
      {
          this.dlist = list;
          this.iter = list.getElements().listIterator();
      }
  
      /**
       * DListIterator constructor comment.
       */
      public DListIterator_2(DListImpl_2 list, int index)
      {
          this.dlist = list;
          this.iter = list.getElements().listIterator(index);
      }
  
      /**
       * Inserts the specified element into the list (optional operation).  The
       * element is inserted immediately before the next element that would be
       * returned by <tt>next</tt>, if any, and after the next element that
       * would be returned by <tt>previous</tt>, if any.  (If the list contains
       * no elements, the new element becomes the sole element on the list.)
       * The new element is inserted before the implicit cursor: a subsequent
       * call to <tt>next</tt> would be unaffected, and a subsequent call to
       * <tt>previous</tt> would return the new element.  (This call increases
       * by one the value that would be returned by a call to <tt>nextIndex</tt>
       * or <tt>previousIndex</tt>.)
       *
       * @exception UnsupportedOperationException if the <tt>add</tt> method is
       * not supported by this list iterator.
       *
       * @exception ClassCastException if the class of the specified element
       * prevents it from being added to this Set.
       *
       * @exception IllegalArgumentException if some aspect of this element
       * prevents it from being added to this Collection.
       */
      public void add(Object obj)
      {
          DListEntry_2 entry = new DListEntry_2(this.dlist, obj);
          entry.setPosition(this.nextIndex() - 1);
          iter.add(entry);
  
          TransactionImpl tx = TxManagerFactory.instance().getTransaction();
          if (tx != null)
          {
              tx.lock(entry, Transaction.WRITE);
              entry.prepareForPersistency(tx.getBroker());
          }
      }
  
      /**
       * Returns <tt>true</tt> if the iteration has more elements. (In other
       * words, returns <tt>true</tt> if <tt>next</tt> would return an element
       * rather than throwing an exception.)
       *
       * @return <tt>true</tt> if the iterator has more elements.
       */
      public boolean hasNext()
      {
          return iter.hasNext();
      }
  
      /**
       * Returns <tt>true</tt> if this list iterator has more elements when
       * traversing the list in the reverse direction.  (In other words, returns
       * <tt>true</tt> if <tt>previous</tt> would return an element rather than
       * throwing an exception.)
       *
       * @return <tt>true</tt> if the list iterator has more elements when
       * traversing the list in the reverse direction.
       */
      public boolean hasPrevious()
      {
          return iter.hasPrevious();
      }
  
      /**
       * Returns the next element in the interation.
       *
       * @return the next element in the interation.
       * @exception NoSuchElementException iteration has no more elements.
       */
      public Object next()
      {
          currentEntry = ((DListEntry_2) iter.next());
          return currentEntry.getRealSubject();
      }
  
      /**
       * Returns the index of the element that would be returned by a subsequent
       * call to <tt>next</tt>. (Returns list size if the list iterator is at the
       * end of the list.)
       *
       * @return the index of the element that would be returned by a subsequent
       * call to <tt>next</tt>, or list size if list iterator is at end
       * of list.
       */
      public int nextIndex()
      {
          return iter.nextIndex();
      }
  
      /**
       * Returns the previous element in the list.  This method may be called
       * repeatedly to iterate through the list backwards, or intermixed with
       * calls to <tt>next</tt> to go back and forth.  (Note that alternating
       * calls to <tt>next</tt> and <tt>previous</tt> will return the same
       * element repeatedly.)
       *
       * @return the previous element in the list.
       *
       * @exception NoSuchElementException if the iteration has no previous
       * element.
       */
      public Object previous()
      {
          currentEntry = ((DListEntry_2) iter.previous());
          return currentEntry.getRealSubject();
      }
  
      /**
       * Returns the index of the element that would be returned by a subsequent
       * call to <tt>previous</tt>. (Returns -1 if the list iterator is at the
       * beginning of the list.)
       *
       * @return the index of the element that would be returned by a subsequent
       * call to <tt>previous</tt>, or -1 if list iterator is at
       * beginning of list.
       */
      public int previousIndex()
      {
          return iter.previousIndex();
      }
  
      /**
       *
       * Removes from the underlying collection the last element returned by the
       * iterator (optional operation).  This method can be called only once per
       * call to <tt>next</tt>.  The behavior of an iterator is unspecified if
       * the underlying collection is modified while the iteration is in
       * progress in any way other than by calling this method.
       *
       * @exception UnsupportedOperationException if the <tt>remove</tt>
       * operation is not supported by this Iterator.
       *
       * @exception IllegalStateException if the <tt>next</tt> method has not
       * yet been called, or the <tt>remove</tt> method has already
       * been called after the last call to the <tt>next</tt>
       * method.
       */
      public void remove()
      {
          iter.remove();
          TransactionImpl tx = TxManagerFactory.instance().getTransaction();
          if (tx != null)
          {
              tx.markDelete(currentEntry);
          }
          currentEntry = null;
      }
  
      /**
       * Replaces the last element returned by <tt>next</tt> or
       * <tt>previous</tt> with the specified element (optional operation).
       * This call can be made only if neither <tt>ListIterator.remove</tt> nor
       * <tt>ListIterator.add</tt> have been called after the last call to
       * <tt>next</tt> or <tt>previous</tt>.
       *
       * @exception UnsupportedOperationException if the <tt>set</tt> operation
       * is not supported by this list iterator.
       * @exception ClassCastException if the class of the specified element
       * prevents it from being added to this list.
       * @exception IllegalArgumentException if some aspect of the specified
       * element prevents it from being added to this list.
       * @exception IllegalStateException if neither <tt>next</tt> nor
       * <tt>previous</tt> have been called, or <tt>remove</tt> or
       * <tt>add</tt> have been called after the last call to
       * <tt>next</tt> or <tt>previous</tt>.
       */
      public void set(Object o)
      {
          throw new UnsupportedOperationException("Method is not supported");
          // currentEntry.setRealSubject(o);
      }
  
  }
  
  
  
  1.13      +9 -12     db-ojb/src/java/org/apache/ojb/odmg/OJB.java
  
  Index: OJB.java
  ===================================================================
  RCS file: /home/cvs/db-ojb/src/java/org/apache/ojb/odmg/OJB.java,v
  retrieving revision 1.12
  retrieving revision 1.13
  diff -u -r1.12 -r1.13
  --- OJB.java	6 Feb 2003 20:58:23 -0000	1.12
  +++ OJB.java	6 Aug 2003 00:20:13 -0000	1.13
  @@ -62,10 +62,7 @@
   import org.apache.ojb.broker.util.configuration.Configurator;
   import org.apache.ojb.broker.util.logging.Logger;
   import org.apache.ojb.broker.util.logging.LoggerFactory;
  -import org.apache.ojb.odmg.collections.DBagImpl;
  -import org.apache.ojb.odmg.collections.DListImpl;
  -import org.apache.ojb.odmg.collections.DMapImpl;
  -import org.apache.ojb.odmg.collections.DSetImpl;
  +import org.apache.ojb.odmg.collections.DCollectionFactory;
   import org.apache.ojb.odmg.oql.EnhancedOQLQuery;
   import org.apache.ojb.odmg.oql.OQLQueryImpl;
   import org.odmg.DArray;
  @@ -239,7 +236,7 @@
           {
               throw new DatabaseClosedException("Database is NULL, cannot create a DList with a null database.");
           }
  -        return new DListImpl(getCurrentPBKey());
  +        return DCollectionFactory.getInstance().createDList(getCurrentPBKey());
       }
   
       /**
  @@ -253,7 +250,7 @@
           {
               throw new DatabaseClosedException("Database is NULL, cannot create a DBag with a null database.");
           }
  -        return new DBagImpl(getCurrentPBKey());
  +        return DCollectionFactory.getInstance().createDBag(getCurrentPBKey());
       }
   
       /**
  @@ -267,7 +264,7 @@
           {
               throw new DatabaseClosedException("Database is NULL, cannot create a DSet with a null database.");
           }
  -        return new DSetImpl(getCurrentPBKey());
  +        return DCollectionFactory.getInstance().createDSet(getCurrentPBKey());
       }
   
       /**
  @@ -281,7 +278,7 @@
           {
               throw new DatabaseClosedException("Database is NULL, cannot create a DArray with a null database.");
           }
  -        return new DListImpl(getCurrentPBKey());
  +        return DCollectionFactory.getInstance().createDArray(getCurrentPBKey());
       }
   
       /**
  @@ -295,7 +292,7 @@
           {
               throw new DatabaseClosedException("Database is NULL, cannot create a DMap with a null database.");
           }
  -        return new DMapImpl(getCurrentPBKey());
  +        return DCollectionFactory.getInstance().createDMap(getCurrentPBKey());
       }
   
       /**
  @@ -308,7 +305,7 @@
       {
           Identity oid = null;
           PersistenceBroker broker;
  -        
  +
           if (getCurrentDatabase() != null)
           {
               /**
  @@ -323,7 +320,7 @@
                */
               broker = PersistenceBrokerFactory.defaultPersistenceBroker();
           }
  -        
  +
           oid = new Identity(obj, broker);
           return new String(oid.serialize());
       }
  
  
  
  1.16      +61 -118   db-ojb/src/test/org/apache/ojb/odmg/DListTest.java
  
  Index: DListTest.java
  ===================================================================
  RCS file: /home/cvs/db-ojb/src/test/org/apache/ojb/odmg/DListTest.java,v
  retrieving revision 1.15
  retrieving revision 1.16
  diff -u -r1.15 -r1.16
  --- DListTest.java	8 Mar 2003 19:22:56 -0000	1.15
  +++ DListTest.java	6 Aug 2003 00:20:13 -0000	1.16
  @@ -1,21 +1,18 @@
   package org.apache.ojb.odmg;
   
  -import java.util.Iterator;
  -
   import junit.framework.TestCase;
  -import org.apache.ojb.broker.PersistenceBroker;
   import org.apache.ojb.broker.TestHelper;
  -import org.apache.ojb.broker.metadata.FieldDescriptor;
  -import org.apache.ojb.broker.util.GUID;
   import org.odmg.DBag;
   import org.odmg.DList;
   import org.odmg.DSet;
   import org.odmg.Database;
   import org.odmg.Implementation;
  -import org.odmg.ODMGException;
   import org.odmg.Transaction;
   
  -/** Demo Application that shows basic concepts for Applications using the OJB ODMG
  +import java.util.Iterator;
  +
  +/**
  + * Demo Application that shows basic concepts for Applications using the OJB ODMG
    * implementation as an transactional object server.
    */
   public class DListTest extends TestCase
  @@ -29,10 +26,6 @@
       private static Class CLASS = DListTest.class;
       private String databaseName;
   
  -    /**
  -     * Insert the method's description here.
  -     * Creation date: (24.12.2000 00:33:40)
  -     */
       public DListTest(String name)
   
       {
  @@ -43,11 +36,6 @@
       {
   
           Article a = new Article();
  -        PersistenceBroker broker = ((HasBroker) implementation.currentTransaction()).getBroker();
  -        FieldDescriptor fld = broker.getClassDescriptor(Article.class).getFieldDescriptorByName("articleId");
  -        Integer seq = (Integer) broker.serviceSequenceManager().getUniqueValue(fld);
  -        
  -        a.setArticleId(seq.intValue());
           a.setArticleName("New Funny Article " + a.getArticleId());
           a.setStock(234);
           a.setProductGroupId(7);
  @@ -56,46 +44,21 @@
   
       }
   
  -    protected void printDList(DList list)
  -    {
  -        Iterator iter = list.iterator();
  -        while (iter.hasNext())
  -        {
  -            Article a = (Article) iter.next();
  -            //System.out.print(a.getArticleId() + ", ");
  -        }
  -        //System.out.println();
  -    }
  -
  -    /**
  -     * Insert the method's description here.
  -     * Creation date: (06.12.2000 21:58:53)
  -     */
       public void setUp()
       {
           databaseName = TestHelper.DEF_DATABASE_NAME;
       }
   
  -    /**
  -     * Insert the method's description here.
  -     * Creation date: (06.12.2000 21:59:14)
  -     */
       public void tearDown()
       {
  -        try
  -        {
  -//            OJB.getInstance().currentTransaction().abort();
  -//            OJB.getInstance().getDatabase(null).close();
  -            databaseName = null;
  -
  -        }
  -        catch (Throwable t)
  -        {
  -        }
  +        databaseName = null;
       }
   
       public void testAdding() throws Exception
       {
  +        // create a unique name:
  +        String name = "testAdding_" + System.currentTimeMillis();
  +
           // get facade instance
           Implementation odmg = OJB.getInstance();
           Database db = odmg.newDatabase();
  @@ -105,32 +68,29 @@
           Transaction tx = odmg.newTransaction();
           tx.begin();
           DList list = odmg.newDList();
  -        // create a unique name:
  -        String name = new GUID().toString();
  -        try
  -        {
  -            db.bind(list, name);
  -        }
  -        finally
  -        {
  -            tx.commit();
  -        }
  +        db.bind(list, name);
  +        tx.commit();
  +
  +        tx = odmg.newTransaction();
  +        tx.begin();
  +        Object obj = db.lookup(name);
  +        tx.commit();
  +        assertNotNull("binded DList not found", obj);
   
           tx = odmg.newTransaction();
           tx.begin();
           for (int i = 0; i < 5; i++)
           {
  -
               Article a = createArticle(odmg);
               list.add(a);
           }
           tx.commit();
  -        //System.out.println("sequence of items in list:");
  +
           Iterator iter = list.iterator();
           while (iter.hasNext())
           {
               Article a = (Article) iter.next();
  -            //System.out.print(a.getArticleId() + ", ");
  +            assertNotNull(a);
           }
   
           tx = odmg.newTransaction();
  @@ -138,6 +98,8 @@
           ((HasBroker) odmg.currentTransaction()).getBroker().clearCache();
   
           DList lookedUp = (DList) db.lookup(name);
  +        assertNotNull("binded DList not found", lookedUp);
  +
           //System.out.println("sequence of items in lookedup list:");
           iter = lookedUp.iterator();
           Iterator iter1 = list.iterator();
  @@ -145,7 +107,8 @@
           {
               Article a = (Article) iter.next();
               Article b = (Article) iter1.next();
  -
  +            assertNotNull(a);
  +            assertNotNull(b);
               assertEquals(a.getArticleId(), b.getArticleId());
   
               //System.out.print(a.getArticleId() + ", ");
  @@ -160,19 +123,18 @@
        */
       public void testRemoving() throws Exception
       {
  +        // create a unique name:
  +        String name = "testRemoving_" + System.currentTimeMillis();
  +
           // get facade instance
           Implementation odmg = OJB.getInstance();
           Database db = odmg.newDatabase();
           //open database
           db.open(databaseName, Database.OPEN_READ_WRITE);
  -
  -        // create a unique name:
  -        String name = new GUID().toString();
  -
           Transaction tx = odmg.newTransaction();
  +
           tx.begin();
           DList list = odmg.newDList();
  -
           // bind the list to the name:
           db.bind(list, name);
   
  @@ -181,6 +143,7 @@
               Article a = createArticle(odmg);
               list.add(a);
           }
  +        assertEquals(5, list.size());
           tx.commit();
   
           // delete two items
  @@ -188,10 +151,8 @@
           tx.begin();
           ((HasBroker) odmg.currentTransaction()).getBroker().clearCache();
           DList lookedUp = (DList) db.lookup(name);
  -        if (lookedUp == null)
  -        {
  -            fail("database lookup does not find the named DList");
  -        }
  +        assertNotNull("database lookup does not find the named DList", lookedUp);
  +        assertEquals("Wrong number of list entries", 5, lookedUp.size());
           lookedUp.remove(2);
           lookedUp.remove(1);
           tx.commit();
  @@ -209,87 +170,67 @@
   
       public void testAddingWithIndex() throws Exception
       {
  +        // create a unique name:
  +        String name = "testAddingWithIndex_" + System.currentTimeMillis();
  +
           // get facade instance
           Implementation odmg = OJB.getInstance();
           Database db = odmg.newDatabase();
           //open database
  -        try
  -        {
  -            db.open(databaseName, Database.OPEN_READ_WRITE);
  -        }
  -        catch (ODMGException ex)
  -        {
  -            fail("ODMGException: " + ex.getMessage());
  -        }
  +        db.open(databaseName, Database.OPEN_READ_WRITE);
           Transaction tx = odmg.newTransaction();
  +
           tx.begin();
           DList list = odmg.newDList();
  -        PersistenceBroker broker = ((HasBroker) tx).getBroker();
  -
  -        // create a unique name:
  -        String name = new GUID().toString();
  +        db.bind(list, name);
  +        tx.commit();
   
  -        try
  -        {
  -            db.bind(list, name);
  -            tx.commit();
  -        }
  -        catch (Exception ignored)
  -        {
  -            ignored.printStackTrace();
  -            fail("NRM problem: " + ignored.getMessage());
  -        }
           tx = odmg.newTransaction();
           tx.begin();
           for (int i = 0; i < 5; i++)
           {
  -
               Article a = createArticle(odmg);
               list.add(a);
           }
   
  -        printDList(list);
  -
           Article a = createArticle(odmg);
           list.add(2, a);
  -        printDList(list);
  -
  +        // printDList(list);
           a = createArticle(odmg);
           list.add(0, a);
  -        printDList(list);
  -
  +        // printDList(list);
           a = createArticle(odmg);
           list.add(7, a);
  -        printDList(list);
  +        // printDList(list);
  +        tx.commit();
   
  +        tx.begin();
  +        ((TransactionImpl) tx).getBroker().clearCache();
  +        // System.out.println("list: " + list);
  +        // System.out.println("lookup list: " + db.lookup(name));
           tx.commit();
  +
           //System.out.println("sequence of items in list:");
           Iterator iter = list.iterator();
           while (iter.hasNext())
           {
               a = (Article) iter.next();
  +            assertNotNull(a);
               //System.out.print(a.getArticleId() + ", ");
           }
  +
  +
           tx = odmg.newTransaction();
           tx.begin();
           ((TransactionImpl) tx).getBroker().clearCache();
  -        try
  -        {
  -            DList lookedUp = (DList) db.lookup(name);
  -            //System.out.println("sequence of items in lookedup list:");
  -            iter = lookedUp.iterator();
  -            while (iter.hasNext())
  -            {
  -                a = (Article) iter.next();
  -                //System.out.print(a.getArticleId() + ", ");
  -            }
  -            //System.out.println();
  -        }
  -        catch (Throwable ignored)
  +        DList lookedUp = (DList) db.lookup(name);
  +        // System.out.println("lookup list: " + lookedUp);
  +        assertNotNull("database lookup does not find DList", lookedUp);
  +        assertEquals(8, lookedUp.size());
  +        iter = lookedUp.iterator();
  +        while (iter.hasNext())
           {
  -            System.out.println(ignored.getMessage());
  -            ignored.printStackTrace();
  -            fail();
  +            a = (Article) iter.next();
           }
           tx.commit();
       }
  @@ -329,6 +270,8 @@
   
       public void testDSet() throws Exception
       {
  +        String name_1 = "set_1_" + System.currentTimeMillis();
  +        String name_2 = "set_2_" + System.currentTimeMillis();
           // get facade instance
           Implementation odmg = OJB.getInstance();
           Database db = odmg.newDatabase();
  @@ -354,16 +297,16 @@
           set2.add(d);
           set2.add(e);
   
  -        db.bind(set1, "set1");
  -        db.bind(set2, "set2");
  +        db.bind(set1, name_1);
  +        db.bind(set2, name_2);
           tx.commit();
   
           // low lookup both sets
           tx = odmg.newTransaction();
           tx.begin();
           ((HasBroker) tx).getBroker().clearCache();
  -        DSet set1a = (DSet) db.lookup("set1");
  -        DSet set2a = (DSet) db.lookup("set2");
  +        DSet set1a = (DSet) db.lookup(name_1);
  +        DSet set2a = (DSet) db.lookup(name_2);
   
           // check looked up sets
           assertTrue(set1a.containsAll(set1));
  
  
  
  1.12      +14 -10    db-ojb/src/test/org/apache/ojb/odmg/OdmgExamples.java
  
  Index: OdmgExamples.java
  ===================================================================
  RCS file: /home/cvs/db-ojb/src/test/org/apache/ojb/odmg/OdmgExamples.java,v
  retrieving revision 1.11
  retrieving revision 1.12
  diff -u -r1.11 -r1.12
  --- OdmgExamples.java	5 Feb 2003 20:04:40 -0000	1.11
  +++ OdmgExamples.java	6 Aug 2003 00:20:13 -0000	1.12
  @@ -1,7 +1,5 @@
   package org.apache.ojb.odmg;
   
  -import java.util.List;
  -
   import junit.framework.TestCase;
   import org.apache.ojb.broker.Identity;
   import org.apache.ojb.broker.PersistenceBroker;
  @@ -18,6 +16,8 @@
   import org.odmg.OQLQuery;
   import org.odmg.Transaction;
   
  +import java.util.List;
  +
   /** Demo Application that shows basic concepts for Applications using the OJB ODMG
    * implementation as an transactional object server.
    */
  @@ -234,8 +234,9 @@
           query = odmg.newOQLQuery();
           query.create("select aPG from " + ProductGroup.class.getName() + " where groupName like \"Fruit*\"");
           List check = (List) query.execute();
  -        if(check.size() < 1) fail("Could not found ProductGroup's for: "+
  -                "select aPG from " + ProductGroup.class.getName() + " where groupName like \"Fruit*\"");
  +        if (check.size() < 1)
  +            fail("Could not found ProductGroup's for: " +
  +                    "select aPG from " + ProductGroup.class.getName() + " where groupName like \"Fruit*\"");
           ProductGroup pg = (ProductGroup) check.get(0);
   
           assertEquals(pg.getAllArticlesInGroup().size(), results.size());
  @@ -244,12 +245,12 @@
           tx.commit();
   
   
  -    // close database
  +        // close database
   
           db.close();
       }
   
  -    public void testNrmAndDlists()
  +    public void testNrmAndDlists() throws Exception
       {
           // get facade instance
           Implementation odmg = OJB.getInstance();
  @@ -275,10 +276,11 @@
               DList results = (DList) query.execute();
   
               int originalSize = results.size();
  +            assertTrue("result count have to be > 0", originalSize > 0);
   
   //            OJB.getLogger().debug(results);
   
  -            String name = "gimme fruits !";
  +            String name = "gimme fruits_" + System.currentTimeMillis();
   
               db.bind(results, name);
               tx.commit();
  @@ -292,16 +294,18 @@
               DList newResults = (DList) db.lookup(name);
   
               assertEquals(originalSize, newResults.size());
  +            Article art = (Article) newResults.get(0);
  +            assertNotNull(art);
   //            OJB.getLogger().info(results);
   
               tx.commit();
   
           }
  -        catch (Throwable t)
  +        catch (Exception e)
   
           {
               tx.abort();
  -            fail("ODMGException: " + t.getMessage());
  +            throw e;
           }
   
           // close database
  @@ -348,7 +352,7 @@
               // 1. get OID
               Article example = new Article();
               example.setArticleId(30);
  -            Identity oid = new Identity(example,((TransactionImpl) tx).getBroker());
  +            Identity oid = new Identity(example, ((TransactionImpl) tx).getBroker());
   
               // 2. lookup object by OID
               PersistenceBroker broker = ((TransactionImpl) tx).getBroker();
  
  
  
  1.3       +22 -18    db-ojb/src/test/org/apache/ojb/odmg/ODMGGourmet.java
  
  Index: ODMGGourmet.java
  ===================================================================
  RCS file: /home/cvs/db-ojb/src/test/org/apache/ojb/odmg/ODMGGourmet.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- ODMGGourmet.java	2 May 2003 08:39:04 -0000	1.2
  +++ ODMGGourmet.java	6 Aug 2003 00:20:13 -0000	1.3
  @@ -1,7 +1,9 @@
   package org.apache.ojb.odmg;
   
   import org.apache.ojb.broker.Gourmet;
  -import org.apache.ojb.odmg.collections.DListImpl;
  +import org.apache.ojb.broker.TestHelper;
  +import org.apache.ojb.odmg.collections.DCollectionFactory;
  +import org.odmg.DList;
   
   /**
    * class used to test polymorphic m:n collections (ODMG-variant)
  @@ -11,23 +13,25 @@
   public class ODMGGourmet extends Gourmet
   {
   
  -	/**
  -	 * Constructor for ODMGGourmet.
  -	 */
  -	public ODMGGourmet()
  -	{
  -		super();
  -		this.setFavoriteFood(new DListImpl());
  -	}
  +    /**
  +     * Constructor for ODMGGourmet.
  +     */
  +    public ODMGGourmet()
  +    {
  +        super();
  +        DList list = DCollectionFactory.getInstance().createDList(TestHelper.DEF_KEY);
  +        this.setFavoriteFood(list);
  +    }
   
  -	/**
  -	 * Constructor for ODMGGourmet.
  -	 * @param name
  -	 */
  -	public ODMGGourmet(String name)
  -	{
  -		super(name);
  -		this.setFavoriteFood(new DListImpl());
  -	}
  +    /**
  +     * Constructor for ODMGGourmet.
  +     * @param name
  +     */
  +    public ODMGGourmet(String name)
  +    {
  +        super(name);
  +        DList list = DCollectionFactory.getInstance().createDList(TestHelper.DEF_KEY);
  +        this.setFavoriteFood(list);
  +    }
   
   }
  
  
  
  1.56      +27 -2     db-ojb/src/test/org/apache/ojb/OJB.properties
  
  Index: OJB.properties
  ===================================================================
  RCS file: /home/cvs/db-ojb/src/test/org/apache/ojb/OJB.properties,v
  retrieving revision 1.55
  retrieving revision 1.56
  diff -u -r1.55 -r1.56
  --- OJB.properties	29 Jul 2003 10:37:20 -0000	1.55
  +++ OJB.properties	6 Aug 2003 00:20:13 -0000	1.56
  @@ -2,6 +2,7 @@
   # Version: 1.0
   # (c) 2001, 2002, 2003 Apache Software Foundation
   # Author: Thomas Mahler and many others
  +# @version $Id$
   #
   #----------------------------------------------------------------------------------------
   # repository file settings
  @@ -290,19 +291,43 @@
   # The OqlCollectionClass entry defines the collection type returned
   # from OQL queries. By default this value is set to DListImpl.
   # This will be good for most situations as DList allows maximum flexibility
  -# in a ODMG environment.
  +# in a ODMG environment. See also section 'ODMG settings'.
   # Using DLists for large resultsets may be bad for application performance.
   # For these scenarios you can use ArrayLists or Vectors.
   # Important note: the collections class to be used MUST implement the
   # interface org.apache.ojb.broker.ManageableCollection.
   #
  -OqlCollectionClass=org.apache.ojb.odmg.collections.DListImpl
  +OqlCollectionClass=org.apache.ojb.odmg.collections.DListImpl_2
   # OqlCollectionClass=org.apache.ojb.broker.util.collections.ManageableArrayList
   # OqlCollectionClass=org.apache.ojb.broker.util.ManageableVector
   #
   # The SqlInLimit entry limits the number of values in IN-sql statement,
   # -1 for no limits. This hint is used in Criteria.
   SqlInLimit=200
  +#
  +#
  +#----------------------------------------------------------------------------------------
  +# ODMG settings
  +#----------------------------------------------------------------------------------------
  +# Used ODMG collection implementation classes
  +# (e.g. when do a Implementation#newDlist() call)
  +#
  +# org.odmg.DList implementation class
  +DListClass=org.apache.ojb.odmg.collections.DListImpl_2
  +#DListClass=org.apache.ojb.odmg.collections.DListImpl
  +#
  +# org.odmg.DArray implementation class
  +DArrayClass=org.apache.ojb.odmg.collections.DListImpl_2
  +#DArrayClass=org.apache.ojb.odmg.collections.DListImpl
  +#
  +# org.odmg.DMap implementation class
  +DMapClass=org.apache.ojb.odmg.collections.DMapImpl
  +#
  +# org.odmg.DBag implementation class
  +DBagClass=org.apache.ojb.odmg.collections.DBagImpl
  +#
  +# org.odmg.DSet implementation class
  +DSetClass=org.apache.ojb.odmg.collections.DSetImpl
   #
   #
   #----------------------------------------------------------------------------------------
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: ojb-dev-unsubscribe@db.apache.org
For additional commands, e-mail: ojb-dev-help@db.apache.org