Search in sources :

Example 1 with ProcedureTranslator

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;
        }
    };
}
Also used : ProcedureAction(org.apache.cayenne.access.jdbc.ProcedureAction) Connection(java.sql.Connection) ProcedureTranslator(org.apache.cayenne.access.translator.procedure.ProcedureTranslator)

Example 2 with ProcedureTranslator

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;
}
Also used : ProcedureTranslator(org.apache.cayenne.access.translator.procedure.ProcedureTranslator)

Example 3 with ProcedureTranslator

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;
}
Also used : ProcedureTranslator(org.apache.cayenne.access.translator.procedure.ProcedureTranslator)

Example 4 with ProcedureTranslator

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);
    }
}
Also used : CallableStatement(java.sql.CallableStatement) OperationObserver(org.apache.cayenne.access.OperationObserver) ResultSet(java.sql.ResultSet) ProcedureTranslator(org.apache.cayenne.access.translator.procedure.ProcedureTranslator) RowDescriptor(org.apache.cayenne.access.jdbc.RowDescriptor)

Example 5 with ProcedureTranslator

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();
        }
    }
}
Also used : CallableStatement(java.sql.CallableStatement) ResultSet(java.sql.ResultSet) ProcedureTranslator(org.apache.cayenne.access.translator.procedure.ProcedureTranslator) RowDescriptor(org.apache.cayenne.access.jdbc.RowDescriptor)

Aggregations

ProcedureTranslator (org.apache.cayenne.access.translator.procedure.ProcedureTranslator)8 CallableStatement (java.sql.CallableStatement)4 ResultSet (java.sql.ResultSet)3 RowDescriptor (org.apache.cayenne.access.jdbc.RowDescriptor)2 Connection (java.sql.Connection)1 OperationObserver (org.apache.cayenne.access.OperationObserver)1 ProcedureAction (org.apache.cayenne.access.jdbc.ProcedureAction)1