Search in sources :

Example 1 with RowSelection

use of org.hibernate.engine.spi.RowSelection in project hibernate-orm by hibernate.

the class SQLServer2005DialectTestCase method toRowSelection.

private RowSelection toRowSelection(int firstRow, int maxRows) {
    RowSelection selection = new RowSelection();
    selection.setFirstRow(firstRow);
    selection.setMaxRows(maxRows);
    return selection;
}
Also used : RowSelection(org.hibernate.engine.spi.RowSelection)

Example 2 with RowSelection

use of org.hibernate.engine.spi.RowSelection in project hibernate-orm by hibernate.

the class SQLServer2012DialectTestCase method toRowSelection.

private RowSelection toRowSelection(int firstRow, int maxRows) {
    final RowSelection selection = new RowSelection();
    selection.setFirstRow(firstRow);
    selection.setMaxRows(maxRows);
    return selection;
}
Also used : RowSelection(org.hibernate.engine.spi.RowSelection)

Example 3 with RowSelection

use of org.hibernate.engine.spi.RowSelection in project hibernate-orm by hibernate.

the class LegacyLimitHandlerTestCase method toRowSelection.

private RowSelection toRowSelection(int firstRow, int maxRows) {
    RowSelection selection = new RowSelection();
    selection.setFirstRow(firstRow);
    selection.setMaxRows(maxRows);
    return selection;
}
Also used : RowSelection(org.hibernate.engine.spi.RowSelection)

Example 4 with RowSelection

use of org.hibernate.engine.spi.RowSelection 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)

Example 5 with RowSelection

use of org.hibernate.engine.spi.RowSelection in project midpoint by Evolveum.

the class SqlAuditServiceImpl method selectRecordsByNumberToKeep.

private int selectRecordsByNumberToKeep(Session session, String tempTable, Integer recordsToKeep, Dialect dialect) {
    Number totalAuditRecords = (Number) session.createCriteria(RAuditEventRecord.class).setProjection(Projections.rowCount()).uniqueResult();
    int recordsToDelete = totalAuditRecords.intValue() - recordsToKeep;
    if (recordsToDelete <= 0) {
        recordsToDelete = 0;
    } else if (recordsToDelete > CLEANUP_AUDIT_BATCH_SIZE) {
        recordsToDelete = CLEANUP_AUDIT_BATCH_SIZE;
    }
    LOGGER.debug("Total audit records: {}, records to keep: {} => records to delete in this batch: {}", totalAuditRecords, recordsToKeep, recordsToDelete);
    if (recordsToDelete == 0) {
        return 0;
    }
    StringBuilder selectSB = new StringBuilder();
    selectSB.append("select a.id as id from ").append(RAuditEventRecord.TABLE_NAME).append(" a");
    selectSB.append(" order by a.").append(RAuditEventRecord.COLUMN_TIMESTAMP).append(" asc");
    String selectString = selectSB.toString();
    // batch size
    RowSelection rowSelection = new RowSelection();
    rowSelection.setMaxRows(recordsToDelete);
    LimitHandler limitHandler = dialect.buildLimitHandler(selectString, rowSelection);
    selectString = limitHandler.getProcessedSql();
    selectString = selectString.replace("?", String.valueOf(recordsToDelete));
    String queryString = "insert into " + tempTable + " " + selectString;
    LOGGER.trace("Query string = {}", queryString);
    SQLQuery query = session.createSQLQuery(queryString);
    return query.executeUpdate();
}
Also used : LimitHandler(org.hibernate.dialect.pagination.LimitHandler) RowSelection(org.hibernate.engine.spi.RowSelection) SQLQuery(org.hibernate.SQLQuery)

Aggregations

RowSelection (org.hibernate.engine.spi.RowSelection)19 PreparedStatement (java.sql.PreparedStatement)5 ArrayList (java.util.ArrayList)5 SQLException (java.sql.SQLException)4 CallableStatement (java.sql.CallableStatement)3 List (java.util.List)3 HibernateException (org.hibernate.HibernateException)3 LockOptions (org.hibernate.LockOptions)3 QueryParameters (org.hibernate.engine.spi.QueryParameters)3 TestForIssue (org.hibernate.testing.TestForIssue)3 Test (org.junit.Test)3 SQLQuery (org.hibernate.SQLQuery)2 ScrollMode (org.hibernate.ScrollMode)2 Dialect (org.hibernate.dialect.Dialect)2 LimitHandler (org.hibernate.dialect.pagination.LimitHandler)2 TypedValue (org.hibernate.engine.spi.TypedValue)2 IdentitySet (org.hibernate.internal.util.collections.IdentitySet)2 Type (org.hibernate.type.Type)2 ResultSet (java.sql.ResultSet)1 Statement (java.sql.Statement)1