1 56 57 package org.objectstyle.cayenne.access.trans; 58 59 import java.util.ArrayList ; 60 import java.util.Iterator ; 61 import java.util.List ; 62 63 import org.objectstyle.cayenne.dba.DbAdapter; 64 import org.objectstyle.cayenne.map.DbAttribute; 65 import org.objectstyle.cayenne.query.BatchQuery; 66 import org.objectstyle.cayenne.query.UpdateBatchQuery; 67 68 71 public class LOBUpdateBatchQueryBuilder extends LOBBatchQueryBuilder { 72 73 public LOBUpdateBatchQueryBuilder(DbAdapter adapter) { 74 super(adapter); 75 } 76 77 public List getValuesForLOBUpdateParameters(BatchQuery query) { 78 int len = query.getDbAttributes().size(); 79 UpdateBatchQuery updateBatch = (UpdateBatchQuery) query; 80 81 List values = new ArrayList (len); 82 List qualifierAttributes = updateBatch.getQualifierAttributes(); 83 List updatedDbAttributes = updateBatch.getUpdatedAttributes(); 84 85 int updatedLen = updatedDbAttributes.size(); 86 int qualifierLen = qualifierAttributes.size(); 87 for (int i = 0; i < updatedLen; i++) { 88 DbAttribute attribute = (DbAttribute) updatedDbAttributes.get(i); 89 Object value = query.getValue(i); 90 if(isUpdateableColumn(value, attribute.getType())) { 91 values.add(value); 92 } 93 } 94 95 for (int i = 0; i < qualifierLen; i++) { 96 values.add(query.getValue(updatedLen + i)); 97 } 98 99 return values; 100 } 101 102 public String createSqlString(BatchQuery batch) { 103 UpdateBatchQuery updateBatch = (UpdateBatchQuery) batch; 104 String table = batch.getDbEntity().getFullyQualifiedName(); 105 List idDbAttributes = updateBatch.getQualifierAttributes(); 106 List updatedDbAttributes = updateBatch.getUpdatedAttributes(); 107 StringBuffer query = new StringBuffer ("UPDATE "); 108 query.append(table).append(" SET "); 109 110 int len = updatedDbAttributes.size(); 111 for (int i = 0; i < len; i++) { 112 if (i > 0) { 113 query.append(", "); 114 } 115 116 DbAttribute attribute = (DbAttribute) updatedDbAttributes.get(i); 117 query.append(attribute.getName()).append(" = "); 118 appendUpdatedParameter(query, attribute, batch.getValue(i)); 119 } 120 121 query.append(" WHERE "); 122 Iterator i = idDbAttributes.iterator(); 123 while (i.hasNext()) { 124 DbAttribute attribute = (DbAttribute) i.next(); 125 appendDbAttribute(query, attribute); 126 query.append(" = ?"); 127 if (i.hasNext()) { 128 query.append(" AND "); 129 } 130 } 131 return query.toString(); 132 } 133 } 134 | Popular Tags |