use of org.apache.cayenne.access.translator.procedure.ProcedureTranslator in project cayenne by apache.
the class HSQLActionBuilder method procedureAction.
@Override
public SQLAction procedureAction(ProcedureQuery query) {
return new ProcedureAction(query, dataNode) {
@Override
protected ProcedureTranslator createTranslator(Connection connection) {
ProcedureTranslator transl = new HSQLDBProcedureTranslator();
transl.setAdapter(dataNode.getAdapter());
transl.setQuery(query);
transl.setEntityResolver(dataNode.getEntityResolver());
transl.setConnection(connection);
transl.setJdbcEventLogger(dataNode.getJdbcEventLogger());
return transl;
}
};
}
use of org.apache.cayenne.access.translator.procedure.ProcedureTranslator in project cayenne by apache.
the class MySQLProcedureAction method createTranslator.
/**
* Creates a translator that adds parenthesis to no-param queries.
*/
// see CAY-750 for the problem description
@Override
protected ProcedureTranslator createTranslator(Connection connection) {
ProcedureTranslator translator = new MySQLProcedureTranslator();
translator.setAdapter(dataNode.getAdapter());
translator.setQuery(query);
translator.setEntityResolver(dataNode.getEntityResolver());
translator.setConnection(connection);
translator.setJdbcEventLogger(dataNode.getJdbcEventLogger());
return translator;
}
use of org.apache.cayenne.access.translator.procedure.ProcedureTranslator in project cayenne by apache.
the class PostgresProcedureAction method createTranslator.
/**
* Creates a translator that adds parenthesis to no-param queries.
*/
// see CAY-750 for the problem description
@Override
protected ProcedureTranslator createTranslator(Connection connection) {
ProcedureTranslator translator = new PostgresProcedureTranslator();
translator.setAdapter(dataNode.getAdapter());
translator.setQuery(query);
translator.setEntityResolver(dataNode.getEntityResolver());
translator.setConnection(connection);
translator.setJdbcEventLogger(dataNode.getJdbcEventLogger());
return translator;
}
use of org.apache.cayenne.access.translator.procedure.ProcedureTranslator 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.translator.procedure.ProcedureTranslator 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();
}
}
}
Aggregations