db-ojb-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From b..@apache.org
Subject cvs commit: db-ojb/src/java/org/apache/ojb/broker/accesslayer/sql SqlDeleteByPkStatement.java
Date Mon, 16 Aug 2004 19:06:21 GMT
brj         2004/08/16 12:06:20

  Modified:    src/java/org/apache/ojb/broker/accesslayer
                        StatementManager.java
               src/java/org/apache/ojb/broker/accesslayer/sql
                        SqlDeleteByPkStatement.java
  Log:
  delete uses discriminator column in the where clause (if it's not already part of the pk)
  
  Revision  Changes    Path
  1.49      +9 -2      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.48
  retrieving revision 1.49
  diff -u -r1.48 -r1.49
  --- StatementManager.java	11 Aug 2004 00:42:53 -0000	1.48
  +++ StatementManager.java	16 Aug 2004 19:06:07 -0000	1.49
  @@ -120,7 +120,7 @@
       }
   
       /**
  -     * binds the objects primary key and locking values to the statement, BRJ
  +     * binds the objects primary key class-discriminator and locking values to the statement,
BRJ
        */
       public void bindDelete(PreparedStatement stmt, ClassDescriptor cld, Object obj) throws
SQLException
       {
  @@ -132,6 +132,7 @@
           {
               int index = 1;
               ValueContainer[] values, currentLockingValues;
  +            FieldDescriptor discriminatorFd = cld.getDiscriminatorField();
   
               currentLockingValues = cld.getCurrentLockingValues(obj);
               // parameters for WHERE-clause pk
  @@ -141,6 +142,12 @@
                   m_platform.setObjectForStatement(stmt, index, values[i].getValue(), values[i].getJdbcType().getType());
                   index++;
               }
  +            
  +    		if (discriminatorFd != null && !discriminatorFd.isPrimaryKey())
  +    		{
  +                m_platform.setObjectForStatement(stmt, index, cld.getDiscriminatorValue(),
discriminatorFd.getJdbcType().getType());
  +                index++;
  +    		}
   
               // parameters for WHERE-clause locking
               values = currentLockingValues;
  
  
  
  1.7       +41 -1     db-ojb/src/java/org/apache/ojb/broker/accesslayer/sql/SqlDeleteByPkStatement.java
  
  Index: SqlDeleteByPkStatement.java
  ===================================================================
  RCS file: /home/cvs/db-ojb/src/java/org/apache/ojb/broker/accesslayer/sql/SqlDeleteByPkStatement.java,v
  retrieving revision 1.6
  retrieving revision 1.7
  diff -u -r1.6 -r1.7
  --- SqlDeleteByPkStatement.java	4 Apr 2004 23:53:32 -0000	1.6
  +++ SqlDeleteByPkStatement.java	16 Aug 2004 19:06:20 -0000	1.7
  @@ -15,7 +15,12 @@
    * limitations under the License.
    */
   
  +import java.util.ArrayList;
  +import java.util.Collection;
  +
  +import org.apache.commons.collections.CollectionUtils;
   import org.apache.ojb.broker.metadata.ClassDescriptor;
  +import org.apache.ojb.broker.metadata.FieldDescriptor;
   import org.apache.ojb.broker.util.logging.Logger;
   
   /**
  @@ -50,6 +55,41 @@
           appendWhereClause(cld, true, stmt); //use Locking
   
           return stmt.toString();
  +	}
  +
  +	/**
  +	 * Generate a where clause for a prepared Statement.
  +	 * Only primary key, the class-discriminator (if not part of the pk) 
  +	 * and the locking fields are used in this where clause.
  +	 * @param cld the ClassDescriptor
  +	 * @param useLocking true if locking fields should be included
  +	 * @param stmt the StatementBuffer
  +	 */
  +	protected void appendWhereClause(ClassDescriptor cld, boolean useLocking, StringBuffer
stmt)
  +	{
  +		FieldDescriptor[] pkFields = cld.getPkFields();
  +		FieldDescriptor discriminatorFd = cld.getDiscriminatorField();
  +		
  +		Collection fldColl = new ArrayList();
  +		CollectionUtils.addAll(fldColl, pkFields);
  +		
  +		if (discriminatorFd != null && !discriminatorFd.isPrimaryKey())
  +		{
  +		    fldColl.add(discriminatorFd);
  +		}
  +		
  +		if (useLocking)
  +		{
  +			FieldDescriptor[] lockingFields = cld.getLockingFields();
  +			if (lockingFields.length > 0)
  +			{
  +				CollectionUtils.addAll(fldColl, cld.getLockingFields());
  +			}
  +		}
  +
  +		FieldDescriptor[] fields = new FieldDescriptor[fldColl.size()];
  +		fldColl.toArray(fields);
  +		appendWhereClause(fields, stmt);
   	}
   
   }
  
  
  

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


Mime
View raw message