use of org.apache.cayenne.access.translator.DbAttributeBinding 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.access.translator.DbAttributeBinding 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;
}
use of org.apache.cayenne.access.translator.DbAttributeBinding in project cayenne by apache.
the class CryptoBatchTranslatorFactoryDecorator method translator.
@Override
public BatchTranslator translator(BatchQuery query, final DbAdapter adapter, String trimFunction) {
final BatchTranslator delegateTranslator = delegate.translator(query, adapter, trimFunction);
return new BatchTranslator() {
private boolean encryptorCompiled;
private BindingsTransformer encryptor;
private void ensureEncryptorCompiled() {
if (!encryptorCompiled) {
encryptor = cryptoFactory.encryptor(getBindings(), adapter.getExtendedTypes());
encryptorCompiled = true;
}
}
@Override
public String getSql() {
return delegateTranslator.getSql();
}
@Override
public DbAttributeBinding[] getBindings() {
return delegateTranslator.getBindings();
}
@Override
public DbAttributeBinding[] updateBindings(BatchQueryRow row) {
ensureEncryptorCompiled();
DbAttributeBinding[] bindings = delegateTranslator.updateBindings(row);
if (encryptor != null) {
encryptor.transform(bindings);
}
return bindings;
}
};
}
use of org.apache.cayenne.access.translator.DbAttributeBinding in project cayenne by apache.
the class DefaultBindingsTransformer method transform.
@Override
public void transform(DbAttributeBinding[] bindings) {
int len = positions.length;
for (int i = 0; i < len; i++) {
DbAttributeBinding b = bindings[positions[i]];
Object transformed = transformers[i].encrypt(encryptor, b.getValue());
b.setValue(transformed);
ExtendedType extendedType = transformed != null ? extendedTypeMap.getRegisteredType(transformed.getClass()) : extendedTypeMap.getDefaultType();
b.setExtendedType(extendedType);
}
}
use of org.apache.cayenne.access.translator.DbAttributeBinding in project cayenne by apache.
the class DefaultBatchTranslatorIT method testAppendDbAttribute1.
@Test
public void testAppendDbAttribute1() throws Exception {
DbAdapter adapter = objectFactory.newInstance(DbAdapter.class, JdbcAdapter.class.getName());
String trimFunction = "testTrim";
DefaultBatchTranslator builder = new DefaultBatchTranslator(mock(BatchQuery.class), adapter, trimFunction) {
@Override
protected String createSql() {
return null;
}
@Override
protected DbAttributeBinding[] createBindings() {
return new DbAttributeBinding[0];
}
@Override
protected DbAttributeBinding[] doUpdateBindings(BatchQueryRow row) {
return new DbAttributeBinding[0];
}
};
StringBuilder buf = new StringBuilder();
DbEntity entity = new DbEntity("Test");
DbAttribute attr = new DbAttribute("testAttr", Types.CHAR, null);
attr.setEntity(entity);
builder.appendDbAttribute(buf, attr);
assertEquals("testTrim(testAttr)", buf.toString());
buf = new StringBuilder();
attr = new DbAttribute("testAttr", Types.VARCHAR, null);
attr.setEntity(entity);
builder.appendDbAttribute(buf, attr);
assertEquals("testAttr", buf.toString());
}
Aggregations