Search in sources :

Example 1 with ExtendedType

use of org.apache.cayenne.access.types.ExtendedType in project cayenne by apache.

the class SQLTemplateAction method bindExtendedTypes.

private void bindExtendedTypes(ParameterBinding[] bindings) {
    int i = 1;
    for (ParameterBinding binding : bindings) {
        Object value = binding.getValue();
        ExtendedType extendedType = value != null ? getAdapter().getExtendedTypes().getRegisteredType(value.getClass()) : getAdapter().getExtendedTypes().getDefaultType();
        binding.setExtendedType(extendedType);
        binding.setStatementPosition(i++);
    }
}
Also used : ExtendedType(org.apache.cayenne.access.types.ExtendedType) ParameterBinding(org.apache.cayenne.access.translator.ParameterBinding)

Example 2 with ExtendedType

use of org.apache.cayenne.access.types.ExtendedType in project cayenne by apache.

the class DeleteBatchTranslator method doUpdateBindings.

@Override
protected DbAttributeBinding[] doUpdateBindings(BatchQueryRow row) {
    int len = bindings.length;
    DeleteBatchQuery deleteBatch = (DeleteBatchQuery) query;
    for (int i = 0, j = 1; i < len; i++) {
        DbAttributeBinding b = bindings[i];
        // skip null attributes... they are translated as "IS NULL"
        if (deleteBatch.isNull(b.getAttribute())) {
            b.exclude();
        } else {
            Object value = row.getValue(i);
            ExtendedType extendedType = value != null ? adapter.getExtendedTypes().getRegisteredType(value.getClass()) : adapter.getExtendedTypes().getDefaultType();
            b.include(j++, value, extendedType);
        }
    }
    return bindings;
}
Also used : DeleteBatchQuery(org.apache.cayenne.query.DeleteBatchQuery) DbAttributeBinding(org.apache.cayenne.access.translator.DbAttributeBinding) ExtendedType(org.apache.cayenne.access.types.ExtendedType)

Example 3 with ExtendedType

use of org.apache.cayenne.access.types.ExtendedType in project cayenne by apache.

the class InsertBatchTranslator method doUpdateBindings.

@Override
protected DbAttributeBinding[] doUpdateBindings(BatchQueryRow row) {
    int len = bindings.length;
    for (int i = 0, j = 1; i < len; i++) {
        DbAttributeBinding b = bindings[i];
        // exclusions are permanent
        if (!b.isExcluded()) {
            Object value = row.getValue(i);
            ExtendedType extendedType = value != null ? adapter.getExtendedTypes().getRegisteredType(value.getClass()) : adapter.getExtendedTypes().getDefaultType();
            b.include(j++, value, extendedType);
        }
    }
    return bindings;
}
Also used : DbAttributeBinding(org.apache.cayenne.access.translator.DbAttributeBinding) ExtendedType(org.apache.cayenne.access.types.ExtendedType)

Example 4 with ExtendedType

use of org.apache.cayenne.access.types.ExtendedType in project cayenne by apache.

the class SoftDeleteBatchTranslator method doUpdateBindings.

@Override
protected DbAttributeBinding[] doUpdateBindings(BatchQueryRow row) {
    int len = bindings.length;
    DeleteBatchQuery deleteBatch = (DeleteBatchQuery) query;
    // skip position 0... Otherwise follow super algorithm
    for (int i = 1, j = 2; i < len; i++) {
        DbAttributeBinding b = bindings[i];
        // skip null attributes... they are translated as "IS NULL"
        if (deleteBatch.isNull(b.getAttribute())) {
            b.exclude();
        } else {
            Object value = row.getValue(i - 1);
            ExtendedType extendedType = value != null ? adapter.getExtendedTypes().getRegisteredType(value.getClass()) : adapter.getExtendedTypes().getDefaultType();
            b.include(j++, value, extendedType);
        }
    }
    return bindings;
}
Also used : DeleteBatchQuery(org.apache.cayenne.query.DeleteBatchQuery) DbAttributeBinding(org.apache.cayenne.access.translator.DbAttributeBinding) ExtendedType(org.apache.cayenne.access.types.ExtendedType)

Example 5 with ExtendedType

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