Search in sources :

Example 6 with ExtendedType

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;
}
Also used : UpdateBatchQuery(org.apache.cayenne.query.UpdateBatchQuery) DbAttribute(org.apache.cayenne.map.DbAttribute) ExtendedType(org.apache.cayenne.access.types.ExtendedType)

Example 7 with ExtendedType

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);
}
Also used : ColumnDescriptor(org.apache.cayenne.access.jdbc.ColumnDescriptor) DbAttribute(org.apache.cayenne.map.DbAttribute) ExtendedType(org.apache.cayenne.access.types.ExtendedType) RowDescriptor(org.apache.cayenne.access.jdbc.RowDescriptor)

Example 8 with ExtendedType

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);
    }
}
Also used : DbAttributeBinding(org.apache.cayenne.access.translator.DbAttributeBinding) ExtendedType(org.apache.cayenne.access.types.ExtendedType)

Example 9 with 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);
}
Also used : ProcedureParameterBinding(org.apache.cayenne.access.translator.ProcedureParameterBinding) ExtendedType(org.apache.cayenne.access.types.ExtendedType)

Example 10 with ExtendedType

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);
    }
}
Also used : DbAttributeBinding(org.apache.cayenne.access.translator.DbAttributeBinding) ExtendedType(org.apache.cayenne.access.types.ExtendedType)

Aggregations

ExtendedType (org.apache.cayenne.access.types.ExtendedType)17 DbAttributeBinding (org.apache.cayenne.access.translator.DbAttributeBinding)8 DbAttribute (org.apache.cayenne.map.DbAttribute)5 ResultSet (java.sql.ResultSet)2 DataRow (org.apache.cayenne.DataRow)2 ColumnDescriptor (org.apache.cayenne.access.jdbc.ColumnDescriptor)2 RowDescriptor (org.apache.cayenne.access.jdbc.RowDescriptor)2 ExtendedTypeFactory (org.apache.cayenne.access.types.ExtendedTypeFactory)2 ProcedureParameter (org.apache.cayenne.map.ProcedureParameter)2 DeleteBatchQuery (org.apache.cayenne.query.DeleteBatchQuery)2 Blob (java.sql.Blob)1 Clob (java.sql.Clob)1 PreparedStatement (java.sql.PreparedStatement)1 CayenneRuntimeException (org.apache.cayenne.CayenneRuntimeException)1 ParameterBinding (org.apache.cayenne.access.translator.ParameterBinding)1 ProcedureParameterBinding (org.apache.cayenne.access.translator.ProcedureParameterBinding)1 ValueObjectTypeFactory (org.apache.cayenne.access.types.ValueObjectTypeFactory)1 ValueObjectTypeRegistry (org.apache.cayenne.access.types.ValueObjectTypeRegistry)1 RuntimeProperties (org.apache.cayenne.configuration.RuntimeProperties)1 DerbyAdapter (org.apache.cayenne.dba.derby.DerbyAdapter)1