Search in sources :

Example 1 with BulkOperationCleanupAction

use of org.hibernate.action.internal.BulkOperationCleanupAction in project hibernate-orm by hibernate.

the class BasicExecutor method doExecute.

protected int doExecute(QueryParameters parameters, SharedSessionContractImplementor session, String sql, List parameterSpecifications) throws HibernateException {
    BulkOperationCleanupAction action = new BulkOperationCleanupAction(session, persister);
    if (session.isEventSource()) {
        ((EventSource) session).getActionQueue().addAction(action);
    } else {
        action.getAfterTransactionCompletionProcess().doAfterTransactionCompletion(true, session);
    }
    PreparedStatement st = null;
    RowSelection selection = parameters.getRowSelection();
    try {
        try {
            st = session.getJdbcCoordinator().getStatementPreparer().prepareStatement(sql, false);
            Iterator paramSpecItr = parameterSpecifications.iterator();
            int pos = 1;
            while (paramSpecItr.hasNext()) {
                final ParameterSpecification paramSpec = (ParameterSpecification) paramSpecItr.next();
                pos += paramSpec.bind(st, parameters, session, pos);
            }
            if (selection != null) {
                if (selection.getTimeout() != null) {
                    st.setQueryTimeout(selection.getTimeout());
                }
            }
            return session.getJdbcCoordinator().getResultSetReturn().executeUpdate(st);
        } finally {
            if (st != null) {
                session.getJdbcCoordinator().getLogicalConnection().getResourceRegistry().release(st);
                session.getJdbcCoordinator().afterStatementExecution();
            }
        }
    } catch (SQLException sqle) {
        throw session.getJdbcServices().getSqlExceptionHelper().convert(sqle, "could not execute update query", sql);
    }
}
Also used : BulkOperationCleanupAction(org.hibernate.action.internal.BulkOperationCleanupAction) ParameterSpecification(org.hibernate.param.ParameterSpecification) SQLException(java.sql.SQLException) Iterator(java.util.Iterator) PreparedStatement(java.sql.PreparedStatement) RowSelection(org.hibernate.engine.spi.RowSelection)

Aggregations

PreparedStatement (java.sql.PreparedStatement)1 SQLException (java.sql.SQLException)1 Iterator (java.util.Iterator)1 BulkOperationCleanupAction (org.hibernate.action.internal.BulkOperationCleanupAction)1 RowSelection (org.hibernate.engine.spi.RowSelection)1 ParameterSpecification (org.hibernate.param.ParameterSpecification)1