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, 31 Jan 2003 16:55:52 GMT
brj         2003/01/31 08:55:52

  Modified:    src/java/org/apache/ojb/broker/singlevm
                        PersistenceBrokerImpl.java
  Log:
  fixed getMtoNQuery: now uses addEqualToField
  
  Revision  Changes    Path
  1.119     +22 -83    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.118
  retrieving revision 1.119
  diff -u -r1.118 -r1.119
  --- PersistenceBrokerImpl.java	30 Jan 2003 15:16:51 -0000	1.118
  +++ PersistenceBrokerImpl.java	31 Jan 2003 16:55:52 -0000	1.119
  @@ -2003,90 +2003,29 @@
        * @param cld the ClassDescriptor for the owner
        * @param cod the CollectionDescriptor
        */
  -    private Query getMtoNQuery(Object obj, ClassDescriptor cld, CollectionDescriptor cod)
  -    {
  -        Object[] values = brokerHelper.getKeyValues(cld, obj);
  -        Object[] thisClassFks = cod.getFksToThisClass();
  -        Object[] itemClassFks = cod.getFksToItemClass();
  -        ClassDescriptor refCld = getClassDescriptor(cod.getItemClass());
  -        Criteria criteria = new Criteria();
  -        Query query;
  -
  -        for (int i = 0; i < thisClassFks.length; i++)
  -        {
  -            criteria.addEqualTo(cod.getIndirectionTable() + "." + thisClassFks[i], values[i]);
  -        }
  -        for (int i = 0; i < itemClassFks.length; i++)
  -        {
  -            criteria.addEqualToColumn(
  -                    cod.getIndirectionTable() + "." + itemClassFks[i].toString(),
  -                    refCld.getPkFields()[i].getAttributeName());
  -        }
  -
  -        query = QueryFactory.newQuery(refCld.getClassOfObject(), cod.getIndirectionTable(),
criteria);
  -        return query;
  -    }
  -
  -    /**
  -     * Get Foreign key query for m:n <br>
  -     * uses inverse relationship, does NOT work with unidirectional m:n <br>
  -     * THIS METHOD IS NOT YET USED
  -     * @return org.apache.ojb.broker.query.Query
  -     * @param obj the owner of the relationship
  -     * @param cld the ClassDescriptor for the owner
  -     * @param cod the CollectionDescriptor
  -     * @throws PersistenceBrokerException if no inverse relationship defined
  -     */
  -    private Query getMtoNQuery_inverse(Object obj, ClassDescriptor cld, CollectionDescriptor
cod)
  -    {
  -        Object[] values = brokerHelper.getKeyValues(cld, obj);
  -        ClassDescriptor refCld = getClassDescriptor(cod.getItemClass());
  -        FieldDescriptor[] pks = cld.getPkFields();
  -        CollectionDescriptor inverseCod = null;
  -        CollectionDescriptor icod;
  -        Class itemClass = cld.getClassOfObject();
  -        Class baseClass = getTopLevelClass(itemClass);
  -        Criteria criteria = new Criteria();
  -        QueryByCriteria query;
  -
  -        //
  -        // find the inverse relationship of m:n
  -        //
  -        Vector v = refCld.getCollectionDescriptors();
  -        for (int i = 0; i < v.size(); i++)
  -        {
  -            icod = (CollectionDescriptor) v.elementAt(i);
  -            if (icod.getItemClass() == baseClass)
  -            {
  -                inverseCod = icod;
  -                break;
  -            }
  -        }
  -
  -        if (inverseCod == null)
  -        {
  -            throw new PersistenceBrokerException("No inverse relationship found for :"
+ cod.getAttributeName());
  -        }
  -
  -        //
  -        // build the criteria using inverse relationship
  -        //
  -        for (int i = 0; i < pks.length; i++)
  -        {
  -            criteria.addEqualTo(inverseCod.getAttributeName() + "." + pks[i].getAttributeName(),
values[i]);
  -        }
  -
  -        query = new QueryByCriteria(refCld.getClassOfObject(), criteria);
  -        if (baseClass != itemClass)
  -        {
  -            query.addPathClass(inverseCod.getAttributeName(), itemClass);
  -            // Set the hint
  -        }
  -
  -        return query;
  -    }
  -
  -
  +	private Query getMtoNQuery(Object obj, ClassDescriptor cld, CollectionDescriptor cod)
  +	{
  +		Object[] values = brokerHelper.getKeyValues(cld, obj);
  +		Object[] thisClassFks = cod.getFksToThisClass();
  +		Object[] itemClassFks = cod.getFksToItemClass();
  +		ClassDescriptor refCld = getClassDescriptor(cod.getItemClass());
  +		Criteria criteria = new Criteria();
  +		Query query;
  +
  +		for (int i = 0; i < thisClassFks.length; i++)
  +		{
  +			criteria.addEqualTo(cod.getIndirectionTable() + "." + thisClassFks[i], values[i]);
  +		}
  +		for (int i = 0; i < itemClassFks.length; i++)
  +		{
  +			criteria.addEqualToField(
  +				cod.getIndirectionTable() + "." + itemClassFks[i].toString(),
  +				refCld.getPkFields()[i].getAttributeName());
  +		}
  +
  +		query = QueryFactory.newQuery(refCld.getClassOfObject(), cod.getIndirectionTable(), criteria);
  +		return query;
  +	}
   
       /**
        * removes the objects obj from the brokers internal cache.
  
  
  

Mime
View raw message