use of org.apache.cayenne.access.types.ExtendedType in project cayenne by apache.
the class OracleAdapter method bindParameter.
@Override
public void bindParameter(PreparedStatement statement, ParameterBinding binding) throws SQLException, Exception {
// NULL Boolean here, as super doesn't pass it through ExtendedType...
if (binding.getValue() == null && binding.getJdbcType() == Types.BOOLEAN) {
ExtendedType typeProcessor = getExtendedTypes().getRegisteredType(Boolean.class);
typeProcessor.setJdbcObject(statement, binding.getValue(), binding.getStatementPosition(), binding.getJdbcType(), binding.getScale());
} else {
super.bindParameter(statement, binding);
}
}
use of org.apache.cayenne.access.types.ExtendedType in project cayenne by apache.
the class Oracle8LOBBatchAction method processLOBRow.
void processLOBRow(Connection con, Oracle8LOBBatchTranslator queryBuilder, Oracle8LOBBatchQueryWrapper selectQuery, List<DbAttribute> qualifierAttributes, BatchQueryRow row) throws SQLException, Exception {
List<DbAttribute> lobAttributes = selectQuery.getDbAttributesForUpdatedLOBColumns();
if (lobAttributes.size() == 0) {
return;
}
final boolean isLoggable = logger.isLoggable();
List<Object> qualifierValues = selectQuery.getValuesForLOBSelectQualifier(row);
List<Object> lobValues = selectQuery.getValuesForUpdatedLOBColumns();
int parametersSize = qualifierValues.size();
int lobSize = lobAttributes.size();
String selectStr = queryBuilder.createLOBSelectString(lobAttributes, qualifierAttributes);
try (PreparedStatement selectStatement = con.prepareStatement(selectStr)) {
DbAttributeBinding[] attributeBindings = null;
if (isLoggable) {
attributeBindings = new DbAttributeBinding[parametersSize];
}
for (int i = 0; i < parametersSize; i++) {
DbAttribute attribute = qualifierAttributes.get(i);
Object value = qualifierValues.get(i);
ExtendedType extendedType = value != null ? adapter.getExtendedTypes().getRegisteredType(value.getClass()) : adapter.getExtendedTypes().getDefaultType();
DbAttributeBinding binding = new DbAttributeBinding(attribute);
binding.setStatementPosition(i + 1);
binding.setValue(value);
binding.setExtendedType(extendedType);
adapter.bindParameter(selectStatement, binding);
if (isLoggable) {
attributeBindings[i] = binding;
}
}
if (isLoggable) {
logger.logQuery(selectStr, attributeBindings);
}
try (ResultSet result = selectStatement.executeQuery()) {
if (!result.next()) {
throw new CayenneRuntimeException("Missing LOB row.");
}
// read the only expected row
for (int i = 0; i < lobSize; i++) {
DbAttribute attribute = lobAttributes.get(i);
int type = attribute.getType();
if (type == Types.CLOB) {
Clob clob = result.getClob(i + 1);
Object clobVal = lobValues.get(i);
if (clobVal instanceof char[]) {
writeClob(clob, (char[]) clobVal);
} else {
writeClob(clob, clobVal.toString());
}
} else if (type == Types.BLOB) {
Blob blob = result.getBlob(i + 1);
Object blobVal = lobValues.get(i);
if (blobVal instanceof byte[]) {
writeBlob(blob, (byte[]) blobVal);
} else {
String className = (blobVal != null) ? blobVal.getClass().getName() : null;
throw new CayenneRuntimeException("Unsupported class of BLOB value: %s", className);
}
} else {
throw new CayenneRuntimeException("Only BLOB or CLOB is expected here, got: %s", type);
}
}
if (result.next()) {
throw new CayenneRuntimeException("More than one LOB row found.");
}
}
}
}
use of org.apache.cayenne.access.types.ExtendedType in project cayenne by apache.
the class Oracle8LOBBatchTranslator 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];
Object value = row.getValue(i);
DbAttribute attribute = b.getAttribute();
int type = attribute.getType();
// qualifier
if (isUpdateableColumn(value, type)) {
ExtendedType extendedType = value != null ? adapter.getExtendedTypes().getRegisteredType(value.getClass()) : adapter.getExtendedTypes().getDefaultType();
b.include(j++, value, extendedType);
} else {
b.exclude();
}
}
return bindings;
}
use of org.apache.cayenne.access.types.ExtendedType in project cayenne by apache.
the class OracleProcedureAction method readProcedureOutParameters.
/**
* Helper method that reads OUT parameters of a CallableStatement.
*/
@Override
protected void readProcedureOutParameters(CallableStatement statement, OperationObserver delegate) throws SQLException, Exception {
long t1 = System.currentTimeMillis();
// build result row...
DataRow result = null;
List<ProcedureParameter> parameters = getProcedure().getCallParameters();
for (int i = 0; i < parameters.size(); i++) {
ProcedureParameter parameter = parameters.get(i);
if (!parameter.isOutParam()) {
continue;
}
// ==== start Oracle-specific part
if (parameter.getType() == OracleAdapter.getOracleCursorType()) {
try (ResultSet rs = (ResultSet) statement.getObject(i + 1)) {
RowDescriptor rsDescriptor = describeResultSet(rs, processedResultSets++);
readResultSet(rs, rsDescriptor, query, delegate);
}
} else // ==== end Oracle-specific part
{
if (result == null) {
result = new DataRow(2);
}
ColumnDescriptor descriptor = new ColumnDescriptor(parameter);
ExtendedType type = dataNode.getAdapter().getExtendedTypes().getRegisteredType(descriptor.getJavaClass());
Object val = type.materializeObject(statement, i + 1, descriptor.getJdbcType());
result.put(descriptor.getDataRowKey(), val);
}
}
if (result != null && !result.isEmpty()) {
// treat out parameters as a separate data row set
dataNode.getJdbcEventLogger().logSelectCount(1, System.currentTimeMillis() - t1);
delegate.nextRows(query, Collections.singletonList(result));
}
}
use of org.apache.cayenne.access.types.ExtendedType in project cayenne by apache.
the class PerAdapterProviderTest method before.
@Before
public void before() {
ResourceLocator locator = new ClassLoaderResourceLocator(new DefaultClassLoaderManager());
RuntimeProperties runtimeProperties = mock(RuntimeProperties.class);
ValueObjectTypeRegistry valueObjectTypeRegistry = mock(ValueObjectTypeRegistry.class);
this.oracleAdapter = new OracleAdapter(runtimeProperties, Collections.<ExtendedType>emptyList(), Collections.<ExtendedType>emptyList(), Collections.<ExtendedTypeFactory>emptyList(), locator, valueObjectTypeRegistry);
this.derbyAdapter = new DerbyAdapter(runtimeProperties, Collections.<ExtendedType>emptyList(), Collections.<ExtendedType>emptyList(), Collections.<ExtendedTypeFactory>emptyList(), locator, valueObjectTypeRegistry);
this.autoDerbyAdapter = new AutoAdapter(new Provider<DbAdapter>() {
@Override
public DbAdapter get() throws DIRuntimeException {
return derbyAdapter;
}
}, new Slf4jJdbcEventLogger(runtimeProperties));
}
Aggregations