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 67 70 public class LOBInsertBatchQueryBuilder extends LOBBatchQueryBuilder { 71 72 public LOBInsertBatchQueryBuilder(DbAdapter adapter) { 73 super(adapter); 74 } 75 76 public List getValuesForLOBUpdateParameters(BatchQuery query) { 77 List dbAttributes = query.getDbAttributes(); 78 int len = dbAttributes.size(); 79 80 List values = new ArrayList (len); 81 for (int i = 0; i < len; i++) { 82 Object value = query.getValue(i); 83 DbAttribute attribute = (DbAttribute) dbAttributes.get(i); 84 if (isUpdateableColumn(value, attribute.getType())) { 85 values.add(value); 86 } 87 } 88 89 return values; 90 } 91 92 public String createSqlString(BatchQuery batch) { 93 String table = batch.getDbEntity().getFullyQualifiedName(); 94 List dbAttributes = batch.getDbAttributes(); 95 StringBuffer query = new StringBuffer ("INSERT INTO "); 96 query.append(table).append(" ("); 97 for (Iterator i = dbAttributes.iterator(); i.hasNext();) { 98 DbAttribute attribute = (DbAttribute) i.next(); 99 query.append(attribute.getName()); 100 if (i.hasNext()) { 101 query.append(", "); 102 } 103 } 104 query.append(") VALUES ("); 105 for (int i = 0; i < dbAttributes.size(); i++) { 106 if (i > 0) { 107 query.append(", "); 108 } 109 110 appendUpdatedParameter( 111 query, 112 (DbAttribute) dbAttributes.get(i), 113 batch.getValue(i)); 114 } 115 query.append(')'); 116 return query.toString(); 117 } 118 } 119 | Popular Tags |