use of org.apache.cayenne.access.translator.procedure.ProcedureTranslator in project cayenne by apache.
the class MySQLProcedureAction method performAction.
@Override
public void performAction(Connection connection, OperationObserver observer) throws SQLException, Exception {
processedResultSets = 0;
ProcedureTranslator transl = createTranslator(connection);
try (CallableStatement statement = (CallableStatement) transl.createStatement()) {
// this is one difference with super - we need to read the first
// result set
// without calling 'getMoreResults' - which may actually be a good
// default
// strategy?
boolean firstResult = statement.execute();
// read out parameters
readProcedureOutParameters(statement, observer);
// read first result
if (firstResult) {
processResultSet(statement, observer);
} else if (!processUpdate(statement, observer)) {
return;
}
// read the rest of the query
while (true) {
if (statement.getMoreResults()) {
processResultSet(statement, observer);
} else if (!processUpdate(statement, observer)) {
break;
}
}
}
}
use of org.apache.cayenne.access.translator.procedure.ProcedureTranslator in project cayenne by apache.
the class ProcedureAction method performAction.
@Override
public void performAction(Connection connection, OperationObserver observer) throws SQLException, Exception {
processedResultSets = 0;
ProcedureTranslator transl = createTranslator(connection);
try (CallableStatement statement = (CallableStatement) transl.createStatement()) {
initStatement(statement);
// 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
// TODO: andrus, 4/2/2007 - according to the docs we should store
// the boolean
// return value of this method and avoid calling 'getMoreResults' if
// it is
// true.
// some db's handle this well, some don't (MySQL).
// 09/23/2013: almost all adapters except Oracle (and maybe a few
// more?) are actually using the correct strategy, so making it a
// default in the superclass, and isolating hack to subclasses is
// probably a good idea
statement.execute();
// read out parameters
readProcedureOutParameters(statement, observer);
// read the rest of the query
while (true) {
if (statement.getMoreResults()) {
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);
}
}
}
}
use of org.apache.cayenne.access.translator.procedure.ProcedureTranslator in project cayenne by apache.
the class ProcedureAction method createTranslator.
/**
* Returns the ProcedureTranslator to use for this ProcedureAction.
*
* @param connection
* JDBC connection
*/
protected ProcedureTranslator createTranslator(Connection connection) {
ProcedureTranslator translator = new ProcedureTranslator();
translator.setAdapter(dataNode.getAdapter());
translator.setQuery(query);
translator.setEntityResolver(dataNode.getEntityResolver());
translator.setConnection(connection);
translator.setJdbcEventLogger(dataNode.getJdbcEventLogger());
return translator;
}
Aggregations