use of org.apache.cayenne.access.types.ExtendedType 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.access.types.ExtendedType in project cayenne by apache.
the class CryptoRowReaderFactoryDecorator method encryptedRowDescriptor.
protected RowDescriptor encryptedRowDescriptor(RowDescriptor descriptor, ExtendedTypeMap typeMap) {
// need to tweak the original descriptor to ensure binary columns are read as binary, eben if the plain Java
// type is not a byte[]
ColumnDescriptor[] originalColumns = descriptor.getColumns();
int len = originalColumns.length;
ExtendedType[] originalConverters = descriptor.getConverters();
ExtendedType[] encryptedConverters = new ExtendedType[len];
for (int i = 0; i < len; i++) {
DbAttribute attribute = originalColumns[i].getAttribute();
ExtendedType t = originalConverters[i];
if (attribute != null && columnMapper.isEncrypted(attribute)) {
// only char or binary columns can store encrypted data
if (TypesMapping.isBinary(attribute.getType())) {
t = typeMap.getRegisteredType(byte[].class);
} else if (TypesMapping.isCharacter(attribute.getType())) {
t = typeMap.getRegisteredType(String.class);
}
// else - warning?
}
encryptedConverters[i] = t;
}
return new RowDescriptor(originalColumns, encryptedConverters);
}
use of org.apache.cayenne.access.types.ExtendedType 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.types.ExtendedType in project cayenne by apache.
the class ProcedureTranslator method setInParam.
/**
* Sets a single IN parameter of the CallableStatement.
*/
protected void setInParam(CallableStatement stmt, ProcedureParameter param, Object val, int pos) throws Exception {
ExtendedType extendedType = val != null ? adapter.getExtendedTypes().getRegisteredType(val.getClass()) : adapter.getExtendedTypes().getDefaultType();
ProcedureParameterBinding binding = new ProcedureParameterBinding(param);
binding.setStatementPosition(pos);
binding.setValue(val);
binding.setExtendedType(extendedType);
adapter.bindParameter(stmt, binding);
}
use of org.apache.cayenne.access.types.ExtendedType in project cayenne by apache.
the class QueryAssembler method addToParamList.
/**
* Registers <code>anObject</code> as a PreparedStatement parameter.
*
* @param anObject
* object that represents a value of DbAttribute
* @param dbAttr
* DbAttribute being processed.
*/
public void addToParamList(DbAttribute dbAttr, Object anObject) {
ExtendedType extendedType = anObject != null ? adapter.getExtendedTypes().getRegisteredType(anObject.getClass()) : adapter.getExtendedTypes().getDefaultType();
DbAttributeBinding binding = new DbAttributeBinding(dbAttr);
binding.setStatementPosition(bindings.size() + 1);
binding.setValue(anObject);
binding.setExtendedType(extendedType);
bindings.add(binding);
if (addBindingListener != null) {
addBindingListener.onAdd(binding);
}
}
Aggregations