Search in sources :

Example 1 with UpdateBuilder

use of org.apache.cayenne.access.sqlbuilder.UpdateBuilder in project cayenne by apache.

the class SoftDeleteBatchTranslator method getSql.

@Override
public String getSql() {
    DeleteBatchQuery query = context.getQuery();
    DbAttribute deleteAttribute = query.getDbEntity().getAttribute(deletedFieldName);
    UpdateBuilder updateBuilder = update(context.getRootDbEntity()).set(column(deletedFieldName).attribute(deleteAttribute).eq(SQLBuilder.value(true).attribute(deleteAttribute))).where(buildQualifier(query.getDbAttributes()));
    String sql = doTranslate(updateBuilder);
    String typeName = TypesMapping.getJavaBySqlType(deleteAttribute.getType());
    ExtendedType<?> extendedType = context.getAdapter().getExtendedTypes().getRegisteredType(typeName);
    bindings[0].include(1, true, extendedType);
    return sql;
}
Also used : DeleteBatchQuery(org.apache.cayenne.query.DeleteBatchQuery) DbAttribute(org.apache.cayenne.map.DbAttribute) UpdateBuilder(org.apache.cayenne.access.sqlbuilder.UpdateBuilder)

Example 2 with UpdateBuilder

use of org.apache.cayenne.access.sqlbuilder.UpdateBuilder in project cayenne by apache.

the class UpdateBatchTranslator method getSql.

@Override
public String getSql() {
    UpdateBatchQuery query = context.getQuery();
    UpdateBuilder updateBuilder = SQLBuilder.update(context.getRootDbEntity());
    for (DbAttribute attr : query.getUpdatedAttributes()) {
        updateBuilder.set(SQLBuilder.column(attr.getName()).attribute(attr).eq(SQLBuilder.value(1).attribute(attr)));
    }
    updateBuilder.where(buildQualifier(query.getQualifierAttributes()));
    return doTranslate(updateBuilder);
}
Also used : UpdateBatchQuery(org.apache.cayenne.query.UpdateBatchQuery) DbAttribute(org.apache.cayenne.map.DbAttribute) UpdateBuilder(org.apache.cayenne.access.sqlbuilder.UpdateBuilder)

Aggregations

UpdateBuilder (org.apache.cayenne.access.sqlbuilder.UpdateBuilder)2 DbAttribute (org.apache.cayenne.map.DbAttribute)2 DeleteBatchQuery (org.apache.cayenne.query.DeleteBatchQuery)1 UpdateBatchQuery (org.apache.cayenne.query.UpdateBatchQuery)1