1 19 20 21 package org.apache.cayenne.access.trans; 22 23 import java.util.ArrayList ; 24 import java.util.Iterator ; 25 import java.util.List ; 26 27 import org.apache.cayenne.dba.DbAdapter; 28 import org.apache.cayenne.map.DbAttribute; 29 import org.apache.cayenne.query.BatchQuery; 30 import org.apache.cayenne.query.UpdateBatchQuery; 31 32 35 public class LOBUpdateBatchQueryBuilder extends LOBBatchQueryBuilder { 36 37 public LOBUpdateBatchQueryBuilder(DbAdapter adapter) { 38 super(adapter); 39 } 40 41 public List getValuesForLOBUpdateParameters(BatchQuery query) { 42 int len = query.getDbAttributes().size(); 43 UpdateBatchQuery updateBatch = (UpdateBatchQuery) query; 44 45 List values = new ArrayList (len); 46 List qualifierAttributes = updateBatch.getQualifierAttributes(); 47 List updatedDbAttributes = updateBatch.getUpdatedAttributes(); 48 49 int updatedLen = updatedDbAttributes.size(); 50 int qualifierLen = qualifierAttributes.size(); 51 for (int i = 0; i < updatedLen; i++) { 52 DbAttribute attribute = (DbAttribute) updatedDbAttributes.get(i); 53 Object value = query.getValue(i); 54 if(isUpdateableColumn(value, attribute.getType())) { 55 values.add(value); 56 } 57 } 58 59 for (int i = 0; i < qualifierLen; i++) { 60 values.add(query.getValue(updatedLen + i)); 61 } 62 63 return values; 64 } 65 66 public String createSqlString(BatchQuery batch) { 67 UpdateBatchQuery updateBatch = (UpdateBatchQuery) batch; 68 String table = batch.getDbEntity().getFullyQualifiedName(); 69 List idDbAttributes = updateBatch.getQualifierAttributes(); 70 List updatedDbAttributes = updateBatch.getUpdatedAttributes(); 71 StringBuffer query = new StringBuffer ("UPDATE "); 72 query.append(table).append(" SET "); 73 74 int len = updatedDbAttributes.size(); 75 for (int i = 0; i < len; i++) { 76 if (i > 0) { 77 query.append(", "); 78 } 79 80 DbAttribute attribute = (DbAttribute) updatedDbAttributes.get(i); 81 query.append(attribute.getName()).append(" = "); 82 appendUpdatedParameter(query, attribute, batch.getValue(i)); 83 } 84 85 query.append(" WHERE "); 86 Iterator i = idDbAttributes.iterator(); 87 while (i.hasNext()) { 88 DbAttribute attribute = (DbAttribute) i.next(); 89 appendDbAttribute(query, attribute); 90 query.append(" = ?"); 91 if (i.hasNext()) { 92 query.append(" AND "); 93 } 94 } 95 return query.toString(); 96 } 97 } 98 | Popular Tags |