use of org.apache.cayenne.access.jdbc.RowDescriptor 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.jdbc.RowDescriptor in project cayenne by apache.
the class MySQLProcedureAction method processResultSet.
private void processResultSet(CallableStatement statement, OperationObserver observer) throws Exception {
ResultSet rs = Objects.requireNonNull(statement.getResultSet());
try {
RowDescriptor descriptor = describeResultSet(rs, processedResultSets++);
readResultSet(rs, descriptor, query, observer);
} finally {
try {
rs.close();
} catch (SQLException ex) {
}
}
}
use of org.apache.cayenne.access.jdbc.RowDescriptor in project cayenne by apache.
the class SQLServerProcedureAction method performAction.
@Override
public void performAction(Connection connection, OperationObserver observer) throws SQLException, Exception {
ProcedureTranslator transl = createTranslator(connection);
try (CallableStatement statement = (CallableStatement) transl.createStatement()) {
// stored procedure may contain a mixture of update counts and
// result sets,
// and out parameters. Read out parameters first, then
// iterate until we exhaust all results
boolean hasResultSet = statement.execute();
// local observer to cache results and provide them to the external
// observer
// in the order consistent with other adapters.
Observer localObserver = new Observer(observer);
while (true) {
if (hasResultSet) {
try (ResultSet rs = statement.getResultSet()) {
RowDescriptor descriptor = describeResultSet(rs, processedResultSets++);
readResultSet(rs, descriptor, query, localObserver);
}
} else {
int updateCount = statement.getUpdateCount();
if (updateCount == -1) {
break;
}
dataNode.getJdbcEventLogger().logUpdateCount(updateCount);
localObserver.nextCount(query, updateCount);
}
hasResultSet = statement.getMoreResults();
}
// read out parameters to the main observer ... AFTER the main
// result set
// TODO: I hope SQLServer does not support ResultSets as OUT
// parameters,
// otherwise
// the order of custom result descriptors will be messed up
readProcedureOutParameters(statement, observer);
// add results back to main observer
localObserver.flushResults(query);
}
}
use of org.apache.cayenne.access.jdbc.RowDescriptor in project cayenne by apache.
the class DB2ProcedureAction method performAction.
@Override
public void performAction(Connection connection, OperationObserver observer) throws SQLException, Exception {
// cloned from super except for result processing consistent with
// CAY-1874
processedResultSets = 0;
ProcedureTranslator transl = createTranslator(connection);
try (CallableStatement statement = (CallableStatement) transl.createStatement()) {
initStatement(statement);
boolean hasResultSet = statement.execute();
// read out parameters
readProcedureOutParameters(statement, observer);
// read the rest of the query
while (true) {
if (hasResultSet) {
try (ResultSet rs = statement.getResultSet()) {
RowDescriptor descriptor = describeResultSet(rs, processedResultSets++);
readResultSet(rs, descriptor, query, observer);
}
} else {
int updateCount = statement.getUpdateCount();
if (updateCount == -1) {
break;
}
dataNode.getJdbcEventLogger().logUpdateCount(updateCount);
observer.nextCount(query, updateCount);
}
hasResultSet = statement.getMoreResults();
}
}
}
use of org.apache.cayenne.access.jdbc.RowDescriptor 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));
}
}
Aggregations