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 br...@apache.org on 2004/12/02 22:37:46 UTC

cvs commit: db-ojb/src/java/org/apache/ojb/broker/util BrokerHelper.java

brj         2004/12/02 13:37:46

  Modified:    src/java/org/apache/ojb/broker/core
                        PersistenceBrokerImpl.java
               src/java/org/apache/ojb/broker/query Criteria.java
                        InCriteria.java ValueCriteria.java
               src/java/org/apache/ojb/broker/accesslayer/sql
                        SqlGeneratorDefaultImpl.java SqlQueryStatement.java
                        TableAliasHandler.java
               src/java/org/apache/ojb/broker/accesslayer
                        StatementManager.java
               src/java/org/apache/ojb/broker/util BrokerHelper.java
  Added:       src/java/org/apache/ojb/broker/query InCriterion.java
                        IdentityCriteria.java
  Removed:     src/java/org/apache/ojb/broker/query
                        CompositeSelectionCriterion.java
                        IdentityCriterion.java
  Log:
  Identity- and InCriteria are converted to a list of Criterions when the query is preprocessed.
  both classes extend Criteria and thus need no special treatment during sql-generation.
  
  Revision  Changes    Path
  1.102     +3 -3      db-ojb/src/java/org/apache/ojb/broker/core/PersistenceBrokerImpl.java
  
  Index: PersistenceBrokerImpl.java
  ===================================================================
  RCS file: /home/cvs/db-ojb/src/java/org/apache/ojb/broker/core/PersistenceBrokerImpl.java,v
  retrieving revision 1.101
  retrieving revision 1.102
  diff -u -r1.101 -r1.102
  --- PersistenceBrokerImpl.java	1 Dec 2004 22:15:01 -0000	1.101
  +++ PersistenceBrokerImpl.java	2 Dec 2004 21:37:45 -0000	1.102
  @@ -2037,7 +2037,7 @@
               // no extents just use the plain vanilla RsIterator
               if(logger.isDebugEnabled()) logger.debug("Creating RsIterator for class ["+cld.getClassNameOfObject()+"]");
   
  -            Query theQuery = serviceBrokerHelper().setConcreteClassCriteria((QueryByCriteria)query, cld);
  +            Query theQuery = serviceBrokerHelper().setConcreteClassCriteria(this, (QueryByCriteria)query, cld);
               return factory.createRsIterator(theQuery, cld, this);
           }
   
  @@ -2050,7 +2050,7 @@
           while (extents.hasNext())
           {
               BrokerHelper.CldInfo cldInfo = (BrokerHelper.CldInfo) extents.next();
  -            Query theQuery = serviceBrokerHelper().setConcreteClassCriteria((QueryByCriteria)query, cldInfo);
  +            Query theQuery = serviceBrokerHelper().setConcreteClassCriteria(this, (QueryByCriteria)query, cldInfo);
               
               if(logger.isDebugEnabled()) logger.debug("Adding RsIterator of class ["+ cldInfo.cld.getClassNameOfObject()+"] to ChainingIterator");
   
  
  
  
  1.56      +13 -127   db-ojb/src/java/org/apache/ojb/broker/query/Criteria.java
  
  Index: Criteria.java
  ===================================================================
  RCS file: /home/cvs/db-ojb/src/java/org/apache/ojb/broker/query/Criteria.java,v
  retrieving revision 1.55
  retrieving revision 1.56
  diff -u -r1.55 -r1.56
  --- Criteria.java	1 Dec 2004 20:08:27 -0000	1.55
  +++ Criteria.java	2 Dec 2004 21:37:46 -0000	1.56
  @@ -26,9 +26,8 @@
   import java.util.StringTokenizer;
   import java.util.Vector;
   
  -import org.apache.ojb.broker.PersistenceBrokerFactory;
  +import org.apache.ojb.broker.Identity;
   import org.apache.ojb.broker.PersistenceBrokerInternal;
  -import org.apache.ojb.broker.core.PersistenceBrokerImpl;
   import org.apache.ojb.broker.metadata.FieldHelper;
   
   /**
  @@ -74,9 +73,6 @@
       private List m_groupby = null;
       private List m_prefetchedRelationships = null;
   
  -	/** the max. number of parameters in a IN-statement */
  -    protected static final int IN_LIMIT = getSqlInLimit();
  -
       private QueryByCriteria m_query;
   
   	// hint classes for paths of this criteria
  @@ -171,59 +167,6 @@
       }
   
       /**
  -     * Answer a List of InCriteria based on values, each InCriteria
  -     * contains only inLimit values
  -     * @param attribute
  -     * @param values
  -     * @param negative
  -     * @param inLimit the maximum number of values for IN (-1 for no limit)
  -     * @return
  -     */
  -    protected List splitInCriteria(Object attribute, Collection values, boolean negative, int inLimit)
  -    {
  -        List result = new ArrayList();
  -        Collection inCollection = new ArrayList();
  -
  -        if (values == null || values.isEmpty())
  -        {
  -            // OQL creates empty Criteria for late binding
  -            result.add(buildInCriteria(attribute, negative, values));
  -        }
  -        else
  -        {
  -            Iterator iter = values.iterator();
  -
  -            while (iter.hasNext())
  -            {
  -                inCollection.add(iter.next());
  -                if (inCollection.size() == inLimit || !iter.hasNext())
  -                {
  -                    result.add(buildInCriteria(attribute, negative, inCollection));
  -                    inCollection = new ArrayList();
  -                }
  -            }
  -        }
  -        return result;
  -    }
  -
  -    private InCriteria buildInCriteria(Object attribute, boolean negative, Collection values)
  -    {
  -        InCriteria result;
  -        
  -        if (negative)
  -        {
  -			result = ValueCriteria.buildNotInCriteria(attribute, values);
  -        }
  -        else
  -        {
  -			result = ValueCriteria.buildInCriteria(attribute, values);
  -        }
  -        
  -        updateUserAlias(attribute);
  -        return result;
  -    }
  -
  -    /**
        * Get an Enumeration with all sub criteria
        * @return Enumeration
        */
  @@ -752,21 +695,7 @@
        */
       public Criteria addIn(String attribute, Collection values)
       {
  -        List list = splitInCriteria(attribute, values, false, IN_LIMIT);
  -        int index = 0;
  -        InCriteria inCrit;
  -        Criteria allInCritaria;
  -
  -        inCrit = (InCriteria) list.get(index);
  -        allInCritaria = new Criteria(inCrit);
  -
  -        for (index = 1; index < list.size(); index++)
  -        {
  -            inCrit = (InCriteria) list.get(index);
  -            allInCritaria.addOrCriteria(new Criteria(inCrit));
  -        }
  -
  -        addAndCriteria(allInCritaria);
  +        addAndCriteria(InCriteria.buildInCriteria(attribute, values));
           return this;
       }
   
  @@ -782,26 +711,11 @@
        */
       public Criteria addColumnIn(String column, Collection values)
       {
  -        List list = splitInCriteria(column, values, false, IN_LIMIT);
  -        int index = 0;
  -        InCriteria inCrit;
  -        Criteria allInCritaria;
  -
  -        inCrit = (InCriteria) list.get(index);
  -        inCrit.setTranslateAttribute(false);
  -        allInCritaria = new Criteria(inCrit);
  -
  -        for (index = 1; index < list.size(); index++)
  -        {
  -            inCrit = (InCriteria) list.get(index);
  -            inCrit.setTranslateAttribute(false);
  -            allInCritaria.addOrCriteria(new Criteria(inCrit));
  -        }
  -
  -        addAndCriteria(allInCritaria);
  +        addAndCriteria(InCriteria.buildColumnInCriteria(column, values));
           return this;
       }
  -    
  +
  +
       /**
        * Adds NOT IN criteria,
        * customer_id not in(1,10,33,44)
  @@ -813,15 +727,7 @@
        */
       public Criteria addNotIn(String attribute, Collection values)
       {
  -        List list = splitInCriteria(attribute, values, true, IN_LIMIT);
  -        int index = 0;
  -        InCriteria inCrit;
  -
  -        for (index = 0; index < list.size(); index++)
  -        {
  -            inCrit = (InCriteria) list.get(index);
  -            addSelectionCriteria(inCrit);
  -        }
  +        addAndCriteria(InCriteria.buildNotInCriteria(attribute, values));
           return this;
       }
   
  @@ -911,11 +817,11 @@
        * customer = Identity()
        *
        * @param  attribute   The field name to be used
  -     * @param  value       An object representing the value of the field
  +     * @param  identity    An identity representing an Object
        */
  -    public Criteria addIdentityEqualTo(String attribute, Object value)
  +    public Criteria addIdentityEqualTo(String attribute, Identity identity)
       {
  -		addSelectionCriteria(IdentityCriterion.buildEqualToCriteria(attribute, value));
  +		addAndCriteria(IdentityCriteria.buildEqualToCriteria(attribute, identity));
           return this;
       }
   
  @@ -924,11 +830,11 @@
        * customer != Identity()
        *
        * @param  attribute   The field name to be used
  -     * @param  value       An object representing the value of the field
  +     * @param  identity    An identity representing an Object
        */
  -    public Criteria addIdentityNotEqualTo(String attribute, Object value)
  +    public Criteria addIdentityNotEqualTo(String attribute, Identity identity)
       {
  -		addSelectionCriteria(IdentityCriterion.buildNotEqualToCriteria(attribute, value));
  +        addAndCriteria(IdentityCriteria.buildNotEqualToCriteria(attribute, identity));
           return this;
       }
       
  @@ -1033,26 +939,6 @@
       }
   
       /**
  -     * read the prefetchInLimit from Config based on OJB.properties
  -     */
  -    private static int getSqlInLimit()
  -    {
  -        // TODO: This is an ugly hack; the Criteria should not be dependant
  -        //       upon the OJB instance
  -        String limit = (String)PersistenceBrokerFactory.getOjb().getComponentContainer().getProperty(
  -                           PersistenceBrokerImpl.class, "prefetchInLimit");
  -
  -        if (limit != null)
  -        {
  -            return Integer.parseInt(limit);
  -        }
  -        else
  -        {
  -            return 200;
  -        }
  -    }
  -
  -	/**
   	 * Retrieves the user alias to be used by a child criteria.
   	 * The attribute is added to the user alias
   	 * @param attribute 
  
  
  
  1.14      +171 -26   db-ojb/src/java/org/apache/ojb/broker/query/InCriteria.java
  
  Index: InCriteria.java
  ===================================================================
  RCS file: /home/cvs/db-ojb/src/java/org/apache/ojb/broker/query/InCriteria.java,v
  retrieving revision 1.13
  retrieving revision 1.14
  diff -u -r1.13 -r1.14
  --- InCriteria.java	25 Sep 2004 14:54:56 -0000	1.13
  +++ InCriteria.java	2 Dec 2004 21:37:46 -0000	1.14
  @@ -1,6 +1,5 @@
  -package org.apache.ojb.broker.query;
   
  -import java.util.Collection;
  +package org.apache.ojb.broker.query;
   
   /* Copyright 2002-2004 The Apache Software Foundation
    *
  @@ -17,38 +16,184 @@
    * limitations under the License.
    */
   
  +import java.util.ArrayList;
  +import java.util.Collection;
  +import java.util.Iterator;
  +import java.util.List;
  +
  +import org.apache.ojb.broker.PersistenceBrokerInternal;
  +
   /**
  - * SelectionCriteria for 'in (a,b,c..)'
  - * 
  + * Criteria for IN-Clause holding a list of InCriterion.
  + * The IN is translated into a list of ordinary InCriterion according to SQL-IN-LIMIT.
  + *
    * @author <a href="mailto:jbraeuchi@gmx.ch">Jakob Braeuchi</a>
    * @version $Id$
    */
  -public class InCriteria extends ValueCriteria
  +public class InCriteria extends Criteria
   {
  -    private static final long serialVersionUID = 6583090573034862381L;
  +    private static final long serialVersionUID = -2349356771591660674L;
   
  -    InCriteria(Object anAttribute, Object aValue, String aClause)
  +    /**
  +     * Build InCriteria with IN clause
  +     * @param anAttribute the name of the attribute
  +     * @param aValue an Identity
  +     */
  +    static InCriteria buildInCriteria(Object anAttribute, Collection values)
   	{
  -		super(anAttribute, aValue, aClause);
  +		return new InCriteria(anAttribute, values, false, true);
   	}
  - 
  - 
  -	/**
  -	 * @see org.apache.ojb.broker.query.SelectionCriteria#isBindable()
  -	 * BRJ: empty Collection is bindable
  -	 */
  -	protected boolean isBindable()
  +
  +    /**
  +     * Build InCriteria with IN clause
  +     * @param aColumn the name of the column (do not translate)
  +     * @param aValue an Identity
  +     */
  +    static InCriteria buildColumnInCriteria(Object aColumn, Collection values)
   	{
  -		if (getValue() instanceof Collection)
  -		{
  -			Collection coll = (Collection)getValue();
  -			return coll.isEmpty();
  -		}	
  -		else
  -		{
  -			return true;
  -		}	
  +		return new InCriteria(aColumn, values, false, false);
   	}
   
  -}
  +    /**
  +     * Build InCriteria with NOT IN clause
  +     * @param anAttribute the name of the attribute
  +     * @param aValue an Identity
  +     */
  +	static InCriteria buildNotInCriteria(Object anAttribute, Collection values)
  +	{
  +		return new InCriteria(anAttribute, values, true, true);
  +	}
  +	
  +	private Object m_attribute;
  +	private Collection m_values;
  +	private boolean m_translateAttribute;
  +	private boolean m_preprocessed = false;
   
  +	/**
  +	 * Constructor.
  +	 * 
  +	 * @param anAttribute the name of the attribute
  +	 * @param values the Collection 
  +	 * @param negative clause-indicator : true=NOT IN, false=IN
  +	 * @param translate if false the attribute name is not translated into column name
  +	 */
  +    InCriteria(Object anAttribute, Collection values, boolean negative, boolean translate)
  +    {
  +        m_attribute = anAttribute;
  +        m_values = values;
  +        m_translateAttribute = translate;
  +        setNegative(negative);
  +    }
  +
  +    private InCriterion buildInCriterion(Collection values)
  +    {
  +        InCriterion crit;
  +        
  +        if (isNegative())
  +        {
  +			crit = ValueCriteria.buildNotInCriteria(m_attribute, values);
  +        }
  +        else
  +        {
  +			crit = ValueCriteria.buildInCriteria(m_attribute, values);
  +        }
  +        
  +        crit.setTranslateAttribute(m_translateAttribute);
  +        return crit;
  +    }
  +
  +    /**
  +     * Answer a List of InCriterion based on values, each InCriteria
  +     * contains only inLimit values.
  +     * @return
  +     */
  +    private List buildList(PersistenceBrokerInternal aPb)
  +    {
  +        List result = new ArrayList();
  +        Collection inCollection = new ArrayList();
  +        int inLimit = aPb.getSqlInLimit();
  +
  +        if (m_values == null || m_values.isEmpty())
  +        {
  +            // OQL creates empty Criteria for late binding
  +            result.add(buildInCriterion(m_values));
  +        }
  +        else
  +        {
  +            Iterator iter = m_values.iterator();
  +
  +            while (iter.hasNext())
  +            {
  +                inCollection.add(iter.next());
  +                if (inCollection.size() == inLimit || !iter.hasNext())
  +                {
  +                    result.add(buildInCriterion(inCollection));
  +                    inCollection = new ArrayList();
  +                }
  +            }
  +        }
  +        return result;
  +    }
  +    
  +    private void buildInCriteria(PersistenceBrokerInternal aPb)
  +    {
  +        List list = buildList(aPb);
  +        int index = 0;
  +        InCriterion inCrit;
  +
  +        // add the first InCriterion (to be ANDed)
  +        inCrit = (InCriterion) list.get(index);
  +        addSelectionCriteria(inCrit);
  +
  +        // add the other InCriterion (to be ORed)
  +        for (index = 1; index < list.size(); index++)
  +        {
  +            inCrit = (InCriterion) list.get(index);
  +            addOrCriteria(new Criteria(inCrit));
  +        }
  +    }
  +
  +    private void buildNotInCriteria(PersistenceBrokerInternal aPb)
  +    {
  +        List list = buildList(aPb);
  +        int index = 0;
  +        InCriterion inCrit;
  +
  +        for (index = 0; index < list.size(); index++)
  +        {
  +            inCrit = (InCriterion) list.get(index);
  +            addSelectionCriteria(inCrit);
  +        }
  +    }
  +
  +    /**
  +     * Preprocess the Criteria using a PersistenceBroker.
  +     * Build list of InCriterion based on SQL-IN-LIMIT.
  +     * 
  +     * @param aPb the PersistenceBroker
  +     */
  +    public void preprocess(PersistenceBrokerInternal aPb)
  +    {
  +        if (!m_preprocessed)
  +        {
  +            if (isNegative())
  +            {
  +                buildNotInCriteria(aPb);
  +            }
  +            else
  +            {
  +                buildInCriteria(aPb);
  +            }
  +            m_preprocessed = true;
  +        }
  +    }
  +
  +    /**
  +     * @see java.lang.Object#toString()
  +     */
  +    public String toString()
  +    {
  +        String clause = isNegative() ? SelectionCriteria.NOT_IN : SelectionCriteria.IN;
  +        return "InCriteria:" + m_attribute + clause + super.toString();
  +    }
  +}
  
  
  
  1.14      +5 -5      db-ojb/src/java/org/apache/ojb/broker/query/ValueCriteria.java
  
  Index: ValueCriteria.java
  ===================================================================
  RCS file: /home/cvs/db-ojb/src/java/org/apache/ojb/broker/query/ValueCriteria.java,v
  retrieving revision 1.13
  retrieving revision 1.14
  diff -u -r1.13 -r1.14
  --- ValueCriteria.java	13 Oct 2004 17:28:39 -0000	1.13
  +++ ValueCriteria.java	2 Dec 2004 21:37:46 -0000	1.14
  @@ -66,14 +66,14 @@
   		return new LikeCriteria(anAttribute, aValue, NOT_LIKE);
   	}
   
  -	static InCriteria buildInCriteria(Object anAttribute, Object aValue)
  +	static InCriterion buildInCriteria(Object anAttribute, Object aValue)
   	{
  -		return new InCriteria(anAttribute, aValue, IN);
  +		return new InCriterion(anAttribute, aValue, IN);
   	}
   
  -	static InCriteria buildNotInCriteria(Object anAttribute, Object aValue)
  +	static InCriterion buildNotInCriteria(Object anAttribute, Object aValue)
   	{
  -		return new InCriteria(anAttribute, aValue, NOT_IN);
  +		return new InCriterion(anAttribute, aValue, NOT_IN);
   	}
   
   	static NullCriteria buildNullCriteria(String anAttribute)
  
  
  
  1.1                  db-ojb/src/java/org/apache/ojb/broker/query/InCriterion.java
  
  Index: InCriterion.java
  ===================================================================
  package org.apache.ojb.broker.query;
  
  import java.util.Collection;
  
  /* Copyright 2002-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.
   */
  
  /**
   * SelectionCriterion for 'in (a,b,c..)'
   * 
   * @author <a href="mailto:jbraeuchi@gmx.ch">Jakob Braeuchi</a>
   * @version $Id: InCriterion.java,v 1.1 2004/12/02 21:37:46 brj Exp $
   */
  public class InCriterion extends ValueCriteria
  {
      private static final long serialVersionUID = 6583090573034862381L;
  
      InCriterion(Object anAttribute, Object aValue, String aClause)
  	{
  		super(anAttribute, aValue, aClause);
  	}
   
   
  	/**
  	 * @see org.apache.ojb.broker.query.SelectionCriteria#isBindable()
  	 * BRJ: empty Collection is bindable
  	 */
  	protected boolean isBindable()
  	{
  		if (getValue() instanceof Collection)
  		{
  			Collection coll = (Collection)getValue();
  			return coll.isEmpty();
  		}	
  		else
  		{
  			return true;
  		}	
  	}
  
  }
  
  
  
  
  1.1                  db-ojb/src/java/org/apache/ojb/broker/query/IdentityCriteria.java
  
  Index: IdentityCriteria.java
  ===================================================================
  
  package org.apache.ojb.broker.query;
  
  /* Copyright 2002-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.
   */
  
  import org.apache.ojb.broker.Identity;
  import org.apache.ojb.broker.PersistenceBrokerInternal;
  import org.apache.ojb.broker.metadata.ClassDescriptor;
  import org.apache.ojb.broker.metadata.DescriptorRepository;
  import org.apache.ojb.broker.metadata.FieldDescriptor;
  
  /**
   * Criteria for Identity. 
   * The Identity is translated into a list of ordinary SelectionCriteria reflecting the primary key.
   *
   * @author <a href="mailto:jbraeuchi@gmx.ch">Jakob Braeuchi</a>
   * @version $Id: IdentityCriteria.java,v 1.1 2004/12/02 21:37:46 brj Exp $
   */
  public class IdentityCriteria extends Criteria
  {
      private static final long serialVersionUID = -2349356771591660674L;
  
      /**
       * Build IdentityCriteria with EQUAL clause
       * @param anAttribute the name of the attribute
       * @param aValue an Identity
       */
      static IdentityCriteria buildEqualToCriteria(Object anAttribute, Identity anIdentity)
  	{
  		return new IdentityCriteria(anAttribute, anIdentity, false);
  	}
  
      /**
       * Build IdentityCriteria with NOT EQUAL clause
       * @param anAttribute the name of the attribute
       * @param aValue an Identity
       */
  	static IdentityCriteria buildNotEqualToCriteria(Object anAttribute, Identity anIdentity)
  	{
  		return new IdentityCriteria(anAttribute, anIdentity, true);
  	}
  	
  	private Object m_attribute;
  	private Identity m_identity;
  	private boolean m_preprocessed = false;
      
      /**
       * Constructor.
       * 
       * @param anAttribute the name of the attribute
       * @param aValue an Identity
       * @param negative clause-indicator : true=NOT EQUAL, false=EQUAL
       */
      IdentityCriteria(Object anAttribute, Identity identity, boolean negative)
      {
          m_attribute = anAttribute;
          m_identity = identity;
          setNegative(negative);
      }
      
      
      /**
       * Build SelectionCriteria based on Identity.
       * 
       * @param aPb the Broker used to access the repository
       */
      protected void buildCriteria(PersistenceBrokerInternal aPb)
      {
          DescriptorRepository repository = aPb.getConfiguration().getModel();
          ClassDescriptor cld = repository.getDescriptorFor(m_identity.getObjectsRealClass());
          FieldDescriptor[] pkFields = cld.getPkFields();
          Object[] pkValues = m_identity.getPrimaryKeyValues();
          String attribute = ((String) m_attribute).trim();
          boolean negative = isNegative();
  
          if (attribute != null && attribute.length() > 0)
          {
              attribute = attribute + ".";
          }
          
          for (int i = 0;i < pkFields.length; i++)
          {
              String pkAttribute = attribute + pkFields[i].getAttributeName();
      		ValueCriteria c;
      		if (!negative)
      		{
      		    c = ValueCriteria.buildEqualToCriteria(pkAttribute, pkValues[i]);
      		}
      		else
      		{
      		    c = ValueCriteria.buildNotEqualToCriteria(pkAttribute, pkValues[i]);
      		}
      		addSelectionCriteria(c);
          }       
      }
  
      /**
       * Preprocess the Criteria using a PersistenceBroker.
       * 
       * @param aPb the PersistenceBroker
       */
      public void preprocess(PersistenceBrokerInternal aPb)
      {
          if (!m_preprocessed)
          {
              buildCriteria(aPb);
              m_preprocessed = true;
          }    
      }
  
      /**
       * @see java.lang.Object#toString()
       */
      public String toString()
      {
          String clause = isNegative() ? SelectionCriteria.NOT_EQUAL : SelectionCriteria.EQUAL;
          return "IdentityCriterion:" + m_attribute + clause + super.toString();
      }
  }
  
  
  
  1.28      +4 -4      db-ojb/src/java/org/apache/ojb/broker/accesslayer/sql/SqlGeneratorDefaultImpl.java
  
  Index: SqlGeneratorDefaultImpl.java
  ===================================================================
  RCS file: /home/cvs/db-ojb/src/java/org/apache/ojb/broker/accesslayer/sql/SqlGeneratorDefaultImpl.java,v
  retrieving revision 1.27
  retrieving revision 1.28
  diff -u -r1.27 -r1.28
  --- SqlGeneratorDefaultImpl.java	25 Nov 2004 20:40:11 -0000	1.27
  +++ SqlGeneratorDefaultImpl.java	2 Dec 2004 21:37:46 -0000	1.28
  @@ -25,7 +25,7 @@
   import org.apache.ojb.broker.query.Criteria;
   import org.apache.ojb.broker.query.ExistsCriteria;
   import org.apache.ojb.broker.query.FieldCriteria;
  -import org.apache.ojb.broker.query.InCriteria;
  +import org.apache.ojb.broker.query.InCriterion;
   import org.apache.ojb.broker.query.NullCriteria;
   import org.apache.ojb.broker.query.Query;
   import org.apache.ojb.broker.query.SelectionCriteria;
  @@ -369,8 +369,8 @@
           if (c instanceof BetweenCriteria)
               return toSQLClause((BetweenCriteria) c, cld);
   
  -        if (c instanceof InCriteria)
  -            return toSQLClause((InCriteria) c, cld);
  +        if (c instanceof InCriterion)
  +            return toSQLClause((InCriterion) c, cld);
   
           if (c instanceof SqlCriteria)
               return toSQLClause((SqlCriteria) c, cld);
  
  
  
  1.92      +6 -28     db-ojb/src/java/org/apache/ojb/broker/accesslayer/sql/SqlQueryStatement.java
  
  Index: SqlQueryStatement.java
  ===================================================================
  RCS file: /home/cvs/db-ojb/src/java/org/apache/ojb/broker/accesslayer/sql/SqlQueryStatement.java,v
  retrieving revision 1.91
  retrieving revision 1.92
  diff -u -r1.91 -r1.92
  --- SqlQueryStatement.java	25 Nov 2004 17:31:34 -0000	1.91
  +++ SqlQueryStatement.java	2 Dec 2004 21:37:46 -0000	1.92
  @@ -33,8 +33,7 @@
   import org.apache.ojb.broker.query.Criteria;
   import org.apache.ojb.broker.query.ExistsCriteria;
   import org.apache.ojb.broker.query.FieldCriteria;
  -import org.apache.ojb.broker.query.IdentityCriterion;
  -import org.apache.ojb.broker.query.InCriteria;
  +import org.apache.ojb.broker.query.InCriterion;
   import org.apache.ojb.broker.query.LikeCriteria;
   import org.apache.ojb.broker.query.MtoNQuery;
   import org.apache.ojb.broker.query.NullCriteria;
  @@ -752,7 +751,7 @@
        * @param c InCriteria
        * @param buf
        */
  -    private void appendInCriteria(TableAlias alias, PathInfo pathInfo, InCriteria c, StringBuffer buf)
  +    private void appendInCriteria(TableAlias alias, PathInfo pathInfo, InCriterion c, StringBuffer buf)
       {
           appendAttribute(alias, pathInfo, c.isTranslateAttribute(), buf);
           buf.append(c.getClause());
  @@ -853,9 +852,9 @@
           {
               appendBetweenCriteria(alias, pathInfo, (BetweenCriteria) c, buf);
           }
  -        else if (c instanceof InCriteria)
  +        else if (c instanceof InCriterion)
           {
  -            appendInCriteria(alias, pathInfo, (InCriteria) c, buf);
  +            appendInCriteria(alias, pathInfo, (InCriterion) c, buf);
           }
           else if (c instanceof SqlCriteria)
           {
  @@ -898,20 +897,6 @@
       }
   
       /**
  -     * Answer the SQL-Clause for a IdentityCriterion
  -     * @param c IdentityCriterion
  -     */
  -    private void appendSQLClause(IdentityCriterion c, StringBuffer buf)
  -    {
  -        Iterator iter = c.getCriteriaList().iterator();
  -        
  -        while (iter.hasNext())
  -        {
  -            asSQLStatement((SelectionCriteria)iter.next(), buf);              
  -        }
  -    }
  -
  -    /**
        * Answer the SQL-Clause for a SelectionCriteria
        * If the Criteria references a class with extents an OR-Clause is
        * added for each extent
  @@ -932,14 +917,7 @@
               appendSQLClause((Query) c.getAttribute(), c, buf);
               return;
           }
  -
  -        // BRJ : handle IdentityCriteria
  -        if (c instanceof IdentityCriterion)
  -        {
  -            appendSQLClause((IdentityCriterion) c, buf);
  -            return;
  -        }
  -        
  +       
   		AttributeInfo attrInfo = getAttributeInfo((String) c.getAttribute(), false, c.getUserAlias(), c.getPathClasses());
           TableAlias alias = attrInfo.tableAlias;
   
  
  
  
  1.6       +2 -17     db-ojb/src/java/org/apache/ojb/broker/accesslayer/sql/TableAliasHandler.java
  
  Index: TableAliasHandler.java
  ===================================================================
  RCS file: /home/cvs/db-ojb/src/java/org/apache/ojb/broker/accesslayer/sql/TableAliasHandler.java,v
  retrieving revision 1.5
  retrieving revision 1.6
  diff -u -r1.5 -r1.6
  --- TableAliasHandler.java	27 Oct 2004 19:36:09 -0000	1.5
  +++ TableAliasHandler.java	2 Dec 2004 21:37:46 -0000	1.6
  @@ -31,7 +31,6 @@
   import org.apache.ojb.broker.metadata.fieldaccess.AnonymousPersistentFieldForInheritance;
   import org.apache.ojb.broker.query.Criteria;
   import org.apache.ojb.broker.query.FieldCriteria;
  -import org.apache.ojb.broker.query.IdentityCriterion;
   import org.apache.ojb.broker.query.QueryByCriteria;
   import org.apache.ojb.broker.query.SelectionCriteria;
   import org.apache.ojb.broker.query.SqlCriteria;
  @@ -620,21 +619,7 @@
           {
               return;
           }
  -
  -        // handle IdentityCriteria as a collection of SelectionCriteria
  -        if (crit instanceof IdentityCriterion)
  -        {
  -            IdentityCriterion idc = (IdentityCriterion) crit;
  -            Iterator idIter = idc.getCriteriaList().iterator();
  -            
  -            while (idIter.hasNext())
  -            {
  -                buildJoinTree((SelectionCriteria) idIter.next(), useOuterJoin);
  -            }
  -            
  -            return;
  -        }
  -        
  +       
           // do not build join tree for subQuery attribute                  
           if (crit.getAttribute() != null && crit.getAttribute() instanceof String)
           {
  
  
  
  1.53      +7 -31     db-ojb/src/java/org/apache/ojb/broker/accesslayer/StatementManager.java
  
  Index: StatementManager.java
  ===================================================================
  RCS file: /home/cvs/db-ojb/src/java/org/apache/ojb/broker/accesslayer/StatementManager.java,v
  retrieving revision 1.52
  retrieving revision 1.53
  diff -u -r1.52 -r1.53
  --- StatementManager.java	14 Nov 2004 09:33:38 -0000	1.52
  +++ StatementManager.java	2 Dec 2004 21:37:46 -0000	1.53
  @@ -39,8 +39,8 @@
   import org.apache.ojb.broker.query.Criteria;
   import org.apache.ojb.broker.query.ExistsCriteria;
   import org.apache.ojb.broker.query.FieldCriteria;
  -import org.apache.ojb.broker.query.IdentityCriterion;
  -import org.apache.ojb.broker.query.InCriteria;
  +import org.apache.ojb.broker.query.IdentityCriteria;
  +import org.apache.ojb.broker.query.InCriterion;
   import org.apache.ojb.broker.query.NullCriteria;
   import org.apache.ojb.broker.query.Query;
   import org.apache.ojb.broker.query.SelectionCriteria;
  @@ -292,7 +292,7 @@
        * @param cld the ClassDescriptor
        * @return next index for PreparedStatement
        */
  -    private int bindStatement(PreparedStatement stmt, int index, InCriteria crit, ClassDescriptor cld) throws SQLException
  +    private int bindStatement(PreparedStatement stmt, int index, InCriterion crit, ClassDescriptor cld) throws SQLException
       {
           if (crit.getValue() instanceof Collection)
           {
  @@ -311,27 +311,7 @@
           
           return index;
       }
  -
  -    /**
  -     * bind IdentityCriteria by binding the enclosed Criteria
  -     * @param stmt the PreparedStatement
  -     * @param index the position of the parameter to bind
  -     * @param crit the Criteria containing the parameter
  -     * @param cld the ClassDescriptor
  -     * @return next index for PreparedStatement
  -     */
  -    private int bindStatement(PreparedStatement stmt, int index, IdentityCriterion crit, ClassDescriptor cld) throws SQLException
  -    {
  -        Iterator iter = crit.getCriteriaList().iterator();
  -        
  -        while (iter.hasNext())
  -        {
  -            SelectionCriteria selCrit = (SelectionCriteria) iter.next();
  -            index = bindSelectionCriteriaWithExtents(stmt, index, selCrit, cld);
  -        }
  -        return index;
  -    }
  -    
  +   
       /**
        * bind ExistsCriteria
        * @param stmt the PreparedStatement
  @@ -439,9 +419,9 @@
           {
               index = bindStatement(stmt, index, (BetweenCriteria) crit, cld);
           }
  -        else if (crit instanceof InCriteria)
  +        else if (crit instanceof InCriterion)
           {
  -            index = bindStatement(stmt, index, (InCriteria) crit, cld);
  +            index = bindStatement(stmt, index, (InCriterion) crit, cld);
           }
           else if (crit instanceof SqlCriteria)
           {
  @@ -454,10 +434,6 @@
           else if (crit instanceof ExistsCriteria)
           {
               index = bindStatement(stmt, index, (ExistsCriteria) crit, cld);
  -        }
  -        else if (crit instanceof IdentityCriterion)
  -        {
  -            index = bindStatement(stmt, index, (IdentityCriterion) crit, cld);
           }
           else
           {
  
  
  
  1.72      +11 -4     db-ojb/src/java/org/apache/ojb/broker/util/BrokerHelper.java
  
  Index: BrokerHelper.java
  ===================================================================
  RCS file: /home/cvs/db-ojb/src/java/org/apache/ojb/broker/util/BrokerHelper.java,v
  retrieving revision 1.71
  retrieving revision 1.72
  diff -u -r1.71 -r1.72
  --- BrokerHelper.java	21 Nov 2004 09:38:45 -0000	1.71
  +++ BrokerHelper.java	2 Dec 2004 21:37:46 -0000	1.72
  @@ -29,6 +29,7 @@
   import org.apache.ojb.broker.OJBRuntimeException;
   import org.apache.ojb.broker.PBKey;
   import org.apache.ojb.broker.PersistenceBrokerException;
  +import org.apache.ojb.broker.PersistenceBrokerInternal;
   import org.apache.ojb.broker.core.PersistenceBrokerImpl;
   import org.apache.ojb.broker.core.ValueContainer;
   import org.apache.ojb.broker.core.proxy.IndirectionHandler;
  @@ -819,11 +820,12 @@
       
       /**
        * Add a Criteria for Concrete Class to the copied Query.
  +     * @param aPb the broker
        * @param aQuery
        * @param aCld
        * @return a copy of the Query
        */
  -    public Query setConcreteClassCriteria(QueryByCriteria aQuery, ClassDescriptor aCld)
  +    public Query setConcreteClassCriteria(PersistenceBrokerInternal aPb, QueryByCriteria aQuery, ClassDescriptor aCld)
       {
           Query result = aQuery;
           FieldDescriptor fd = aCld.getDiscriminatorField();
  @@ -832,7 +834,10 @@
           {
               String discriminator = aCld.getDiscriminatorValue();
               QueryByCriteria copyQuery = QueryFactory.copyQuery(aQuery);
  +            
               copyQuery.getCriteria().addColumnEqualTo(fd.getColumnName(), discriminator);
  +            copyQuery.preprocess(aPb);
  +            
               result = copyQuery;
           }
           
  @@ -842,11 +847,12 @@
       /**
        * Add a criteria for concrete classes to the copied query.<br>
        * use addEqualTo() if the list contains only 1 element, addIn() if it contains more elements  
  +     * @param aPb the broker
        * @param aQuery
        * @param cldinfo
        * @return a copy of the qery including the additional criteria
        */
  -    public Query setConcreteClassCriteria(QueryByCriteria aQuery, CldInfo cldinfo)
  +    public Query setConcreteClassCriteria(PersistenceBrokerInternal aPb, QueryByCriteria aQuery, CldInfo cldinfo)
       {
           Query result = aQuery;
           List concreteClasses = cldinfo.concreteClasses;
  @@ -865,7 +871,8 @@
                   copyQuery.getCriteria().addColumnEqualTo(fd.getColumnName(), concreteClasses.get(0));                
               }
               
  -            result = copyQuery;
  +            copyQuery.preprocess(aPb);
  +            result = copyQuery;            
           }
           
           return result;
  
  
  

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