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;
}
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;
}
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;
}
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);
}
}
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();
}
Aggregations