db-ojb-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From b..@apache.org
Subject cvs commit: jakarta-ojb/src/java/org/apache/ojb/broker/singlevm PersistenceBrokerImpl.java
Date Sun, 19 Jan 2003 11:51:25 GMT
brj         2003/01/19 03:51:25

  Modified:    src/java/org/apache/ojb/broker/singlevm
                        PersistenceBrokerImpl.java
  Log:
  enhancements for extent aware path expressions
  
  Revision  Changes    Path
  1.114     +8 -182    jakarta-ojb/src/java/org/apache/ojb/broker/singlevm/PersistenceBrokerImpl.java
  
  Index: PersistenceBrokerImpl.java
  ===================================================================
  RCS file: /home/cvs/jakarta-ojb/src/java/org/apache/ojb/broker/singlevm/PersistenceBrokerImpl.java,v
  retrieving revision 1.113
  retrieving revision 1.114
  diff -u -r1.113 -r1.114
  --- PersistenceBrokerImpl.java	16 Jan 2003 23:31:40 -0000	1.113
  +++ PersistenceBrokerImpl.java	19 Jan 2003 11:51:24 -0000	1.114
  @@ -55,6 +55,7 @@
    */
   
   import java.lang.reflect.Array;
  +import java.lang.reflect.Proxy;
   import java.util.ArrayList;
   import java.util.Collection;
   import java.util.Enumeration;
  @@ -63,11 +64,10 @@
   import java.util.List;
   import java.util.Map;
   import java.util.Vector;
  -import java.util.HashSet;
   
  -import org.apache.commons.beanutils.BeanUtils;
   import org.apache.ojb.broker.Identity;
   import org.apache.ojb.broker.ManageableCollection;
  +import org.apache.ojb.broker.OJBRuntimeException;
   import org.apache.ojb.broker.PBKey;
   import org.apache.ojb.broker.PBState;
   import org.apache.ojb.broker.PersistenceBrokerException;
  @@ -75,7 +75,6 @@
   import org.apache.ojb.broker.TransactionInProgressException;
   import org.apache.ojb.broker.TransactionNotInProgressException;
   import org.apache.ojb.broker.VirtualProxy;
  -import org.apache.ojb.broker.OJBRuntimeException;
   import org.apache.ojb.broker.accesslayer.*;
   import org.apache.ojb.broker.accesslayer.sql.SqlGenerator;
   import org.apache.ojb.broker.accesslayer.sql.SqlGeneratorFactory;
  @@ -86,9 +85,9 @@
   import org.apache.ojb.broker.metadata.CollectionDescriptor;
   import org.apache.ojb.broker.metadata.DescriptorRepository;
   import org.apache.ojb.broker.metadata.FieldDescriptor;
  -import org.apache.ojb.broker.metadata.ObjectReferenceDescriptor;
  -import org.apache.ojb.broker.metadata.MetadataManager;
   import org.apache.ojb.broker.metadata.FieldHelper;
  +import org.apache.ojb.broker.metadata.MetadataManager;
  +import org.apache.ojb.broker.metadata.ObjectReferenceDescriptor;
   import org.apache.ojb.broker.metadata.auto.AutoCreatorDb;
   import org.apache.ojb.broker.metadata.fieldaccess.PersistentField;
   import org.apache.ojb.broker.query.Criteria;
  @@ -100,17 +99,14 @@
   import org.apache.ojb.broker.query.QueryFactory;
   import org.apache.ojb.broker.query.ReportQueryByCriteria;
   import org.apache.ojb.broker.query.ReportQueryByMtoNCriteria;
  -import org.apache.ojb.broker.query.SelectionCriteria;
   import org.apache.ojb.broker.server.PersistenceBrokerClient;
   import org.apache.ojb.broker.server.ServerEntry;
   import org.apache.ojb.broker.server.ServerPool;
   import org.apache.ojb.broker.ta.PersistenceBrokerFactoryIF;
   import org.apache.ojb.broker.util.ArrayIterator;
  -import org.apache.ojb.broker.util.ObjectModification;
  -import org.apache.ojb.broker.util.SqlHelper;
   import org.apache.ojb.broker.util.BrokerHelper;
  +import org.apache.ojb.broker.util.ObjectModification;
   import org.apache.ojb.broker.util.ProxyHelper;
  -import org.apache.ojb.broker.util.collections.ManageableArrayList;
   import org.apache.ojb.broker.util.collections.ManageableVector;
   import org.apache.ojb.broker.util.configuration.Configuration;
   import org.apache.ojb.broker.util.configuration.ConfigurationException;
  @@ -119,9 +115,6 @@
   import org.apache.ojb.broker.util.sequence.SequenceManager;
   import org.apache.ojb.broker.util.sequence.SequenceManagerException;
   import org.apache.ojb.broker.util.sequence.SequenceManagerFactory;
  -
  -//#ifdef JDK13
  -import java.lang.reflect.Proxy;
   //#else
   /*
   import com.develop.java.lang.reflect.Proxy;
  @@ -1569,159 +1562,7 @@
       {
           RsIteratorFactory factory = RsIteratorFactoryImpl.getInstance();
   
  -        // BRJ: MtoNQueries can't be extent aware
  -        if (query instanceof MtoNQuery)
  -        {
  -            return getRsIteratorFromQuery(query, cld, factory);
  -        }
  -        else
  -        {
  -            return getRsIteratorFromQueryExtentAware(query, cld, factory);
  -        }
  -
  -    }
  -
  -    /**
  -     * This method retrieves a extent aware Iterator based on all criteria elements present
in Query query. <br>
  -     * Example: <br>
  -     * Suppose you have a reference descriptor from class B ( which is abstract ) to class
A
  -     * and a collection descriptor from A to B that uses the list called 'b_list'<br>
  -     * Now if you want to build a Criteria like this : <br>
  -     * <blockquote><br>
  -     *     Criteria crit = new Criteria(); <br>
  -     *     crit.addEqualTo("b_list.name","SOME_VALUE_OF_B_NAME"); <br>
  -     *     QueryByCriteria query = new QueryByCriteria(AConcreteSubClass.class,crit); <br>
  -     * </b></blockquote>
  -     * The result of a broker.getCollectionByQuery(query) would include all subclasses
of B which are not abstract. <br>
  -     * If you don't want to include all subclasses you can set a predefined concrete subclass
using :
  -     * <blockquote><b>
  -     *    query.addPathClass("b_list",BConcreteSubClass.class);
  -     *</b></blockquote>
  -     * <b>TODO</b> : handle nested Criteria element <br>
  -     * <b>pre-condition</b> : query must be an instance of QueryByCriteria
  -     */
  -    private OJBIterator getRsIteratorFromQueryExtentAware(Query query,
  -                                                          ClassDescriptor cld,
  -                                                          RsIteratorFactory factory)
  -    {
  -        if (logger.isDebugEnabled())
  -        {
  -            logger.debug("-> Looking for objects of type [" + cld.getClassNameOfObject()+"]");
  -        }
  -
  -        /*
  -         * PRE CONDITIONS
  -         */
  -
  -        /* We must use a criteria object */
  -        if(!(query instanceof QueryByCriteria))
  -        {
  -            return getRsIteratorFromQuery(query,cld,factory);
  -        }
  -
  -        Criteria criteria = query.getCriteria();
  -        if(criteria == null)
  -        {
  -            return getRsIteratorFromQuery(query,cld,factory);
  -        }
  -
  -        Enumeration enum = criteria.getElements();
  -        if(enum == null)
  -        {
  -            return getRsIteratorFromQuery(query,cld,factory);
  -        }
  -
  -        /*
  -         * Ok, we have some criteria elements to traverse
  -         */
  -        ChainingIterator chainingIterator = new ChainingIterator();
  -        boolean pathElementPresent = false;
  -        HashSet processedClasses = new HashSet();
  -
  -        while(enum.hasMoreElements())
  -        {
  -            Object criteriaElement = enum.nextElement();
  -            logger.debug("  --# Criteria element ["+criteriaElement+"] class "+criteriaElement.getClass().getName());
  -            if (criteriaElement instanceof Criteria)
  -            {
  -                // TODO : nested criteria
  -                //logger.debug("  --# Nested Criteria ["+criteriaElement+"]");
  -                continue;
  -            }
  -
  -            SelectionCriteria selectionCriteria = (SelectionCriteria) criteriaElement;
  -			String attribute = selectionCriteria.getAttribute();
  -			int dotPos = attribute.lastIndexOf(".");
  -
  -			if (dotPos >= 0)
  -			{
  -				//We are dealing with a path expression, include iterators for all concrete subclasses
  -
  -				String pathElement = SqlHelper.cleanPath(attribute).substring(0, dotPos);
  -				logger.debug("  --# Looking for concrete classes on pathElement [" + pathElement +
"]");
  -
  -				//TODO revise this cast
  -				Class hintClass = ((QueryByCriteria) query).getClassForPath(pathElement);
  -				if (hintClass != null)
  -				{
  -					// BRJ: do the same class only once
  -					if (processedClasses.contains(hintClass))
  -					{
  -						continue;
  -					}
  -					processedClasses.add(hintClass);
  -					pathElementPresent = true;
  -                    //preserve user supplied hint
  -
  -
  -					chainingIterator.addIterator(getRsIteratorFromQuery(query, cld, factory));
  -				}
  -				else
  -				{
  -					List concreteClasses = getClassObjectsForPathElement(cld, pathElement);
  -					if (concreteClasses == null)
  -					{
  -						throw new NullPointerException("Path element [" + pathElement + "] refers abstract
classes only");
  -					}
  -
  -					if (concreteClasses.size() > 0)
  -					{
  -						pathElementPresent = true;
  -
  -                        // BRJ: do the same class only once
  -						if (processedClasses.contains(concreteClasses.get(0)))
  -						{
  -							continue;
  -						}
  -						processedClasses.add(concreteClasses.get(0));
  -
  -						Iterator it = concreteClasses.iterator();
  -						while (it.hasNext())
  -						{
  -							Class extentClass = (Class) it.next();
  -							logger.debug(
  -								"  --# Modifying Query to include class ["
  -									+ extentClass.getName()
  -									+ "] for path element ["
  -									+ pathElement
  -									+ "]");
  -
  -							((QueryByCriteria) query).addPathClass(pathElement, extentClass);
  -							chainingIterator.addIterator(getRsIteratorFromQuery(query, cld, factory));
  -						}
  -					}
  -				}
  -			}
  -		}
  -
  -        if(pathElementPresent)
  -        {
  -            return chainingIterator;
  -        }
  -        else
  -        {
  -            return getRsIteratorFromQuery(query,cld,factory);
  -        }
  +        return getRsIteratorFromQuery(query, cld, factory);       
       }
   
       /**
  @@ -1740,7 +1581,6 @@
   
           if (!descriptors.isEmpty())
           {
  -
           	// BRJ: we need only the last segment of the path
   	        ord = (ObjectReferenceDescriptor)descriptors.get(descriptors.size() - 1);
   
  @@ -1756,8 +1596,6 @@
   			}
   
               concreteClasses.addAll(descriptorRepository.getConcreteSubclassesOf(referencedClass));
  -
  -            //logger.debug("  --* Possible targets " + concreteSubclasses);
           }
   
           return concreteClasses;
  @@ -2439,15 +2277,12 @@
               return factory.createRsIterator(sql, cld, this);
           }
   
  -
           if (!cld.isExtent())
           {
               // no extents just use the plain vanilla RsIterator
               return factory.createRsIterator(query, cld, this);
           }
   
  -
  -
           OJBIterator iter = null;
           String lastUsedTable = cld.getFullTableName();
           logger.debug("Creating one RsIterator per extent class of ["+cld.getClassNameOfObject()+"]");
  @@ -2493,16 +2328,7 @@
       {
           RsIteratorFactory factory = ReportRsIteratorFactoryImpl.getInstance();
   
  -        // BRJ MtoNQueries can't be extent aware
  -        if (query instanceof MtoNQuery)
  -        {
  -            return getRsIteratorFromQuery(query, cld, factory);
  -        }
  -        else
  -        {
  -            return getRsIteratorFromQueryExtentAware(query, cld, factory);
  -        }
  -
  +        return getRsIteratorFromQuery(query, cld, factory);
       }
   
       /*
  
  
  

Mime
View raw message