1 56 57 package org.objectstyle.cayenne.access.trans; 58 59 import java.sql.PreparedStatement ; 60 import java.sql.SQLException ; 61 import java.util.Iterator ; 62 import java.util.List ; 63 64 import org.objectstyle.cayenne.dba.DbAdapter; 65 import org.objectstyle.cayenne.map.DbAttribute; 66 import org.objectstyle.cayenne.query.BatchQuery; 67 import org.objectstyle.cayenne.query.DeleteBatchQuery; 68 69 74 75 public class DeleteBatchQueryBuilder extends BatchQueryBuilder { 76 public DeleteBatchQueryBuilder(DbAdapter adapter) { 77 super(adapter); 78 } 79 80 public String createSqlString(BatchQuery batch) { 81 DeleteBatchQuery deleteBatch = (DeleteBatchQuery) batch; 82 String table = batch.getDbEntity().getFullyQualifiedName(); 83 List qualifierAttributes = deleteBatch.getQualifierAttributes(); 84 85 StringBuffer query = new StringBuffer ("DELETE FROM "); 86 query.append(table).append(" WHERE "); 87 88 Iterator i = qualifierAttributes.iterator(); 89 while (i.hasNext()) { 90 DbAttribute attribute = (DbAttribute) i.next(); 91 appendDbAttribute(query, attribute); 92 query.append(deleteBatch.isNull(attribute) ? " IS NULL" : " = ?"); 93 94 if (i.hasNext()) { 95 query.append(" AND "); 96 } 97 } 98 99 return query.toString(); 100 } 101 102 105 public void bindParameters(PreparedStatement statement, BatchQuery query) 106 throws SQLException , Exception { 107 108 DeleteBatchQuery deleteBatch = (DeleteBatchQuery) query; 109 List qualifierAttributes = deleteBatch.getQualifierAttributes(); 110 111 int parameterIndex = 1; 112 113 for (int i = 0; i < qualifierAttributes.size(); i++) { 114 Object value = query.getValue(i); 115 116 if (null == value) 118 continue; 119 120 DbAttribute attribute = (DbAttribute) qualifierAttributes.get(i); 121 adapter.bindParameter( 122 statement, 123 value, 124 parameterIndex++, 125 attribute.getType(), 126 attribute.getPrecision()); 127 } 128 }} | Popular Tags |