use of org.apache.cayenne.map.DbAttribute in project cayenne by apache.
the class DeleteBatchTranslator method applyQualifier.
/**
* Appends WHERE clause to SQL string
*/
protected void applyQualifier(StringBuilder buffer) {
buffer.append(" WHERE ");
DeleteBatchQuery deleteBatch = (DeleteBatchQuery) query;
Iterator<DbAttribute> i = deleteBatch.getDbAttributes().iterator();
while (i.hasNext()) {
DbAttribute attribute = i.next();
appendDbAttribute(buffer, attribute);
buffer.append(deleteBatch.isNull(attribute) ? " IS NULL" : " = ?");
if (i.hasNext()) {
buffer.append(" AND ");
}
}
}
use of org.apache.cayenne.map.DbAttribute in project cayenne by apache.
the class SoftDeleteBatchTranslator method createBindings.
@Override
protected DbAttributeBinding[] createBindings() {
DbAttributeBinding[] superBindings = super.createBindings();
int slen = superBindings.length;
DbAttributeBinding[] bindings = new DbAttributeBinding[slen + 1];
DbAttribute deleteAttribute = query.getDbEntity().getAttribute(deletedFieldName);
String typeName = TypesMapping.getJavaBySqlType(deleteAttribute.getType());
ExtendedType extendedType = adapter.getExtendedTypes().getRegisteredType(typeName);
bindings[0] = new DbAttributeBinding(deleteAttribute);
bindings[0].include(1, true, extendedType);
System.arraycopy(superBindings, 0, bindings, 1, slen);
return bindings;
}
use of org.apache.cayenne.map.DbAttribute in project cayenne by apache.
the class UpdateBatchTranslator method createSql.
@Override
protected String createSql() {
UpdateBatchQuery updateBatch = (UpdateBatchQuery) query;
QuotingStrategy strategy = adapter.getQuotingStrategy();
List<DbAttribute> qualifierAttributes = updateBatch.getQualifierAttributes();
List<DbAttribute> updatedDbAttributes = updateBatch.getUpdatedAttributes();
StringBuilder buffer = new StringBuilder("UPDATE ");
buffer.append(strategy.quotedFullyQualifiedName(query.getDbEntity()));
buffer.append(" SET ");
int len = updatedDbAttributes.size();
for (int i = 0; i < len; i++) {
if (i > 0) {
buffer.append(", ");
}
DbAttribute attribute = updatedDbAttributes.get(i);
buffer.append(strategy.quotedName(attribute));
buffer.append(" = ?");
}
buffer.append(" WHERE ");
Iterator<DbAttribute> i = qualifierAttributes.iterator();
while (i.hasNext()) {
DbAttribute attribute = i.next();
appendDbAttribute(buffer, attribute);
buffer.append(updateBatch.isNull(attribute) ? " IS NULL" : " = ?");
if (i.hasNext()) {
buffer.append(" AND ");
}
}
return buffer.toString();
}
use of org.apache.cayenne.map.DbAttribute in project cayenne by apache.
the class UpdateBatchTranslator method doUpdateBindings.
@Override
protected DbAttributeBinding[] doUpdateBindings(BatchQueryRow row) {
UpdateBatchQuery updateBatch = (UpdateBatchQuery) query;
List<DbAttribute> updatedDbAttributes = updateBatch.getUpdatedAttributes();
List<DbAttribute> qualifierAttributes = updateBatch.getQualifierAttributes();
int ul = updatedDbAttributes.size();
int ql = qualifierAttributes.size();
int j = 1;
for (int i = 0; i < ul; i++) {
Object value = row.getValue(i);
ExtendedType extendedType = value != null ? adapter.getExtendedTypes().getRegisteredType(value.getClass()) : adapter.getExtendedTypes().getDefaultType();
bindings[i].include(j++, value, extendedType);
}
for (int i = 0; i < ql; i++) {
DbAttribute a = qualifierAttributes.get(i);
// skip null attributes... they are translated as "IS NULL"
if (updateBatch.isNull(a)) {
continue;
}
Object value = row.getValue(ul + i);
ExtendedType extendedType = value != null ? adapter.getExtendedTypes().getRegisteredType(value.getClass()) : adapter.getExtendedTypes().getDefaultType();
bindings[ul + i].include(j++, value, extendedType);
}
return bindings;
}
use of org.apache.cayenne.map.DbAttribute in project cayenne by apache.
the class UpdateBatchTranslator method createBindings.
@Override
protected DbAttributeBinding[] createBindings() {
UpdateBatchQuery updateBatch = (UpdateBatchQuery) query;
List<DbAttribute> updatedDbAttributes = updateBatch.getUpdatedAttributes();
List<DbAttribute> qualifierAttributes = updateBatch.getQualifierAttributes();
int ul = updatedDbAttributes.size();
int ql = qualifierAttributes.size();
DbAttributeBinding[] bindings = new DbAttributeBinding[ul + ql];
for (int i = 0; i < ul; i++) {
bindings[i] = new DbAttributeBinding(updatedDbAttributes.get(i));
}
for (int i = 0; i < ql; i++) {
bindings[ul + i] = new DbAttributeBinding(qualifierAttributes.get(i));
}
return bindings;
}
Aggregations