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 31 34 public class LOBInsertBatchQueryBuilder extends LOBBatchQueryBuilder { 35 36 public LOBInsertBatchQueryBuilder(DbAdapter adapter) { 37 super(adapter); 38 } 39 40 public List getValuesForLOBUpdateParameters(BatchQuery query) { 41 List dbAttributes = query.getDbAttributes(); 42 int len = dbAttributes.size(); 43 44 List values = new ArrayList (len); 45 for (int i = 0; i < len; i++) { 46 Object value = query.getValue(i); 47 DbAttribute attribute = (DbAttribute) dbAttributes.get(i); 48 if (isUpdateableColumn(value, attribute.getType())) { 49 values.add(value); 50 } 51 } 52 53 return values; 54 } 55 56 public String createSqlString(BatchQuery batch) { 57 String table = batch.getDbEntity().getFullyQualifiedName(); 58 List dbAttributes = batch.getDbAttributes(); 59 StringBuffer query = new StringBuffer ("INSERT INTO "); 60 query.append(table).append(" ("); 61 for (Iterator i = dbAttributes.iterator(); i.hasNext();) { 62 DbAttribute attribute = (DbAttribute) i.next(); 63 query.append(attribute.getName()); 64 if (i.hasNext()) { 65 query.append(", "); 66 } 67 } 68 query.append(") VALUES ("); 69 for (int i = 0; i < dbAttributes.size(); i++) { 70 if (i > 0) { 71 query.append(", "); 72 } 73 74 appendUpdatedParameter( 75 query, 76 (DbAttribute) dbAttributes.get(i), 77 batch.getValue(i)); 78 } 79 query.append(')'); 80 return query.toString(); 81 } 82 } 83 | Popular Tags |