db-ojb-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From t...@apache.org
Subject cvs commit: db-ojb/src/java/org/apache/ojb/broker/singlevm PersistenceBrokerImpl.java
Date Thu, 24 Apr 2003 20:36:28 GMT
thma        2003/04/24 13:36:27

  Modified:    src/java/org/apache/ojb/broker/singlevm
                        PersistenceBrokerImpl.java
  Log:
  allow PB to use QueryByIdentity for PB.deleteByQuery(...)
  
  Revision  Changes    Path
  1.158     +35 -1     db-ojb/src/java/org/apache/ojb/broker/singlevm/PersistenceBrokerImpl.java
  
  Index: PersistenceBrokerImpl.java
  ===================================================================
  RCS file: /home/cvs/db-ojb/src/java/org/apache/ojb/broker/singlevm/PersistenceBrokerImpl.java,v
  retrieving revision 1.157
  retrieving revision 1.158
  diff -u -r1.157 -r1.158
  --- PersistenceBrokerImpl.java	18 Apr 2003 13:04:33 -0000	1.157
  +++ PersistenceBrokerImpl.java	24 Apr 2003 20:36:27 -0000	1.158
  @@ -456,6 +456,19 @@
           }
           else
           {
  +        	// if query is Identity based transform it to a criteria based query first
  +	        if (query instanceof QueryByIdentity)
  +	        {
  +	        	QueryByIdentity qbi = (QueryByIdentity) query;
  +	        	Object oid = qbi.getExampleObject();
  +	        	// make sure it's an Identity
  +	        	if (! (oid instanceof Identity))
  +	        	{
  +	        		oid = new Identity(oid, this);	
  +	        	}      	
  +	        	query = this.getPKQuery((Identity)oid);	
  +	        }        	
  +        	
               // if class is an extent, we have to delete all extent classes too
               String lastUsedTable = cld.getFullTableName();
               if (cld.isExtent())
  @@ -1121,6 +1134,27 @@
   		}
   
   		return fkQuery;
  +	}
  +
  +    /**
  +     * Answer the primary key query to retrieve an Object
  +     *
  +     * @param oid the Identity of the Object to retrieve
  +     * @return The resulting query
  +     */
  +	private Query getPKQuery(Identity oid)
  +	{
  +        Object[] values = oid.getPrimaryKeyValues();
  +        ClassDescriptor cld = getClassDescriptor(oid.getObjectsClass());
  +        FieldDescriptor[] fields = cld.getPkFields();
  +        Criteria criteria = new Criteria();
  +
  +        for (int i = 0; i < fields.length; i++)
  +        {
  +            FieldDescriptor fld = fields[i];
  +            criteria.addEqualTo(fld.getAttributeName(), values[i]);
  +        }
  +        return QueryFactory.newQuery(cld.getClassOfObject(), criteria);
   	}
   
       /**
  
  
  

Mime
View raw message