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 Fri, 20 Dec 2002 20:37:39 GMT
brj         2002/12/20 12:37:39

  Modified:    src/java/org/apache/ojb/broker/singlevm
                        PersistenceBrokerImpl.java
  Log:
  getRsIteratorFromQueryExtentAware()
  - added fix by Alan Olmanson
  
  Revision  Changes    Path
  1.95      +113 -103  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.94
  retrieving revision 1.95
  diff -u -r1.94 -r1.95
  --- PersistenceBrokerImpl.java	20 Dec 2002 18:55:20 -0000	1.94
  +++ PersistenceBrokerImpl.java	20 Dec 2002 20:37:38 -0000	1.95
  @@ -1575,116 +1575,126 @@
        * <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
  -                pathElementPresent = true;
  -                String pathElement = ClassDescriptor.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);
  -
  +	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 = ClassDescriptor.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");
  -                    }
  -                    
  -                    // 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);
  -        }
  -    }
  +
  +					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);
  +		}
  +	}
   
       /**
        * Helper method that analyses que pathElement of a query to see if we need to
  
  
  

Mime
View raw message