本文整理汇总了Java中org.hibernate.engine.spi.RowSelection类的典型用法代码示例。如果您正苦于以下问题:Java RowSelection类的具体用法?Java RowSelection怎么用?Java RowSelection使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
RowSelection类属于org.hibernate.engine.spi包,在下文中一共展示了RowSelection类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。
示例1: getLimitHandler
import org.hibernate.engine.spi.RowSelection; //导入依赖的package包/类
@Override
public LimitHandler getLimitHandler() {
return new AbstractLimitHandler() {
@Override
public boolean supportsLimit() {
return true;
}
@Override
public String processSql(String sql, RowSelection selection) {
if (LimitHelper.useLimit(this, selection)) {
final boolean hasMaxRows = LimitHelper.hasMaxRows(selection);
final boolean hasOffset = LimitHelper.hasFirstRow(selection);
return sql + (hasMaxRows ? " limit ?" : "")
+ (hasOffset ? " offset ?" : "");
}
return sql;
}
};
}
开发者ID:jruesga,项目名称:phoenix-hibernate-dialect,代码行数:21,代码来源:PhoenixDialect.java
示例2: doTheLoad
import org.hibernate.engine.spi.RowSelection; //导入依赖的package包/类
private List doTheLoad(String sql, QueryParameters queryParameters, SessionImplementor session) throws SQLException {
final RowSelection selection = queryParameters.getRowSelection();
final int maxRows = LimitHelper.hasMaxRows( selection ) ?
selection.getMaxRows() :
Integer.MAX_VALUE;
final List<AfterLoadAction> afterLoadActions = new ArrayList<AfterLoadAction>();
final SqlStatementWrapper wrapper = executeQueryStatement( sql, queryParameters, false, afterLoadActions, session );
final ResultSet rs = wrapper.getResultSet();
final Statement st = wrapper.getStatement();
try {
return processResultSet( rs, queryParameters, session, false, null, maxRows, afterLoadActions );
}
finally {
session.getTransactionCoordinator().getJdbcCoordinator().release( st );
}
}
开发者ID:lamsfoundation,项目名称:lams,代码行数:18,代码来源:DynamicBatchingEntityLoaderBuilder.java
示例3: advance
import org.hibernate.engine.spi.RowSelection; //导入依赖的package包/类
/**
* Advance the cursor to the first required row of the <tt>ResultSet</tt>
*/
private void advance(final ResultSet rs, final RowSelection selection)
throws SQLException {
final int firstRow = LimitHelper.getFirstRow( selection );
if ( firstRow != 0 ) {
if ( getFactory().getSettings().isScrollableResultSetsEnabled() ) {
// we can go straight to the first required row
rs.absolute( firstRow );
}
else {
// we need to step through the rows one row at a time (slow)
for ( int m = 0; m < firstRow; m++ ) rs.next();
}
}
}
开发者ID:lamsfoundation,项目名称:lams,代码行数:19,代码来源:Loader.java
示例4: getResultSet
import org.hibernate.engine.spi.RowSelection; //导入依赖的package包/类
/**
* Execute given <tt>PreparedStatement</tt>, advance to the first result and return SQL <tt>ResultSet</tt>.
*/
protected final ResultSet getResultSet(
final PreparedStatement st,
final RowSelection selection,
final LimitHandler limitHandler,
final boolean autodiscovertypes,
final SessionImplementor session)
throws SQLException, HibernateException {
try {
ResultSet rs = session.getTransactionCoordinator().getJdbcCoordinator().getResultSetReturn().extract( st );
rs = wrapResultSetIfEnabled( rs , session );
if ( !limitHandler.supportsLimitOffset() || !LimitHelper.useLimit( limitHandler, selection ) ) {
advance( rs, selection );
}
if ( autodiscovertypes ) {
autoDiscoverTypes( rs );
}
return rs;
}
catch ( SQLException sqle ) {
session.getTransactionCoordinator().getJdbcCoordinator().release( st );
throw sqle;
}
}
开发者ID:lamsfoundation,项目名称:lams,代码行数:30,代码来源:Loader.java
示例5: doTheLoad
import org.hibernate.engine.spi.RowSelection; //导入依赖的package包/类
private void doTheLoad(String sql, QueryParameters queryParameters, SessionImplementor session) throws SQLException {
final RowSelection selection = queryParameters.getRowSelection();
final int maxRows = LimitHelper.hasMaxRows( selection ) ?
selection.getMaxRows() :
Integer.MAX_VALUE;
final List<AfterLoadAction> afterLoadActions = Collections.emptyList();
final SqlStatementWrapper wrapper = executeQueryStatement( sql, queryParameters, false, afterLoadActions, session );
final ResultSet rs = wrapper.getResultSet();
final Statement st = wrapper.getStatement();
try {
processResultSet( rs, queryParameters, session, true, null, maxRows, afterLoadActions );
}
finally {
session.getTransactionCoordinator().getJdbcCoordinator().release( st );
}
}
开发者ID:lamsfoundation,项目名称:lams,代码行数:18,代码来源:DynamicBatchingCollectionInitializerBuilder.java
示例6: getResultSet
import org.hibernate.engine.spi.RowSelection; //导入依赖的package包/类
/**
* Execute given <tt>PreparedStatement</tt>, advance to the first result and return SQL <tt>ResultSet</tt>.
*/
protected final ResultSet getResultSet(
final PreparedStatement st,
final RowSelection selection,
final LimitHandler limitHandler,
final boolean autodiscovertypes,
final SessionImplementor session)
throws SQLException, HibernateException {
try {
ResultSet rs = session.getTransactionCoordinator().getJdbcCoordinator().getResultSetReturn().extract( st );
rs = wrapResultSetIfEnabled( rs , session );
if ( !limitHandler.supportsLimitOffset() || !LimitHelper.useLimit( limitHandler, selection ) ) {
advance( rs, selection );
}
if ( autodiscovertypes ) {
autoDiscoverTypes( rs );
}
return rs;
}
catch ( SQLException sqle ) {
session.getTransactionCoordinator().getJdbcCoordinator().release( st );
throw sqle;
}
}
开发者ID:lamsfoundation,项目名称:lams,代码行数:30,代码来源:AbstractLoadPlanBasedLoader.java
示例7: advance
import org.hibernate.engine.spi.RowSelection; //导入依赖的package包/类
/**
* Advance the cursor to the first required row of the <tt>ResultSet</tt>
*/
protected void advance(final ResultSet rs, final RowSelection selection) throws SQLException {
final int firstRow = LimitHelper.getFirstRow( selection );
if ( firstRow != 0 ) {
if ( getFactory().getSettings().isScrollableResultSetsEnabled() ) {
// we can go straight to the first required row
rs.absolute( firstRow );
}
else {
// we need to step through the rows one row at a time (slow)
for ( int m = 0; m < firstRow; m++ ) {
rs.next();
}
}
}
}
开发者ID:lamsfoundation,项目名称:lams,代码行数:19,代码来源:AbstractLoadPlanBasedLoader.java
示例8: selectRecordsByMaxAge
import org.hibernate.engine.spi.RowSelection; //导入依赖的package包/类
private int selectRecordsByMaxAge(Session session, String tempTable, Date minValue, Dialect dialect) {
// fill temporary table, we don't need to join task on object on
// container, oid and id is already in task table
StringBuilder selectSB = new StringBuilder();
selectSB.append("select a.id as id from ").append(RAuditEventRecord.TABLE_NAME).append(" a");
selectSB.append(" where a.").append(RAuditEventRecord.COLUMN_TIMESTAMP).append(" < ###TIME###");
String selectString = selectSB.toString();
// batch size
RowSelection rowSelection = new RowSelection();
rowSelection.setMaxRows(CLEANUP_AUDIT_BATCH_SIZE);
LimitHandler limitHandler = dialect.buildLimitHandler(selectString, rowSelection);
selectString = limitHandler.getProcessedSql();
// replace ? -> batch size, $ -> ?
// Sorry for that .... I just don't know how to write this query in HQL,
// nor I'm not sure if limiting max size in
// compound insert into ... select ... query via query.setMaxSize()
// would work - TODO write more nicely if anybody knows how)
selectString = selectString.replace("?", String.valueOf(CLEANUP_AUDIT_BATCH_SIZE));
selectString = selectString.replace("###TIME###", "?");
String queryString = "insert into " + tempTable + " " + selectString;
LOGGER.trace("Query string = {}", queryString);
SQLQuery query = session.createSQLQuery(queryString);
query.setParameter(0, new Timestamp(minValue.getTime()));
return query.executeUpdate();
}
开发者ID:Pardus-Engerek,项目名称:engerek,代码行数:31,代码来源:SqlAuditServiceImpl.java
示例9: testLimit
import org.hibernate.engine.spi.RowSelection; //导入依赖的package包/类
@Test
public void testLimit() {
RowSelection rowSelection = new RowSelection();
rowSelection.setMaxRows(getMaxRows());
long startNanos = System.nanoTime();
doInJDBC(connection -> {
try (PreparedStatement statement = connection.prepareStatement(SELECT_POST)
) {
statement.setMaxRows(getMaxRows());
assertEquals(getMaxRows(), processResultSet(statement));
} catch (SQLException e) {
fail(e.getMessage());
}
});
LOGGER.info("{} Result Set with limit took {} millis",
dataSourceProvider().database(),
TimeUnit.NANOSECONDS.toMillis(System.nanoTime() - startNanos));
}
开发者ID:vladmihalcea,项目名称:high-performance-java-persistence,代码行数:20,代码来源:OracleResultSetLimitTest.java
示例10: testLimit
import org.hibernate.engine.spi.RowSelection; //导入依赖的package包/类
@Test
public void testLimit() {
RowSelection rowSelection = new RowSelection();
rowSelection.setMaxRows(getMaxRows());
long startNanos = System.nanoTime();
doInJDBC(connection -> {
try (PreparedStatement statement1 = connection.prepareStatement(SELECT_POST_COMMENT_1);
PreparedStatement statement11 = connection.prepareStatement(SELECT_POST_COMMENT_1);
PreparedStatement statement2 = connection.prepareStatement(SELECT_POST_COMMENT_2);
) {
statement1.setMaxRows(getMaxRows());
assertEquals(getMaxRows(), processResultSet(statement1));
assertEquals(getPostCommentCount() * getPostCount(), processResultSet(statement11));
assertEquals(getPostCommentCount() * getPostCount(), processResultSet(statement2));
} catch (SQLException e) {
fail(e.getMessage());
}
});
LOGGER.info("{} Result Set with limit took {} millis",
dataSourceProvider().database(),
TimeUnit.NANOSECONDS.toMillis(System.nanoTime() - startNanos));
}
开发者ID:vladmihalcea,项目名称:high-performance-java-persistence,代码行数:24,代码来源:SQLServerResultSetLimitTest.java
示例11: processSql
import org.hibernate.engine.spi.RowSelection; //导入依赖的package包/类
@Override
public String processSql(String sql, RowSelection selection) {
if (LimitHelper.hasFirstRow(selection)) {
return sql + " limit ? offset ?";
} else {
return sql + " limit ?";
}
}
开发者ID:ZsoltFabok,项目名称:sqlite-dialect,代码行数:9,代码来源:SQLiteLimitHandler.java
示例12: setup
import org.hibernate.engine.spi.RowSelection; //导入依赖的package包/类
@Before
public void setup() {
limitHandler = new SQLiteLimitHandler();
rowSelection = new RowSelection();
PowerMockito.mockStatic(LimitHelper.class);
}
开发者ID:ZsoltFabok,项目名称:sqlite-dialect,代码行数:8,代码来源:SQLiteLimitHandlerTest.java
示例13: doQuery
import org.hibernate.engine.spi.RowSelection; //导入依赖的package包/类
private List doQuery(
final SessionImplementor session,
final QueryParameters queryParameters,
final boolean returnProxies,
final ResultTransformer forcedResultTransformer) throws SQLException, HibernateException {
final RowSelection selection = queryParameters.getRowSelection();
final int maxRows = LimitHelper.hasMaxRows( selection ) ?
selection.getMaxRows() :
Integer.MAX_VALUE;
final List<AfterLoadAction> afterLoadActions = new ArrayList<AfterLoadAction>();
final SqlStatementWrapper wrapper = executeQueryStatement( queryParameters, false, afterLoadActions, session );
final ResultSet rs = wrapper.getResultSet();
final Statement st = wrapper.getStatement();
// would be great to move all this below here into another method that could also be used
// from the new scrolling stuff.
//
// Would need to change the way the max-row stuff is handled (i.e. behind an interface) so
// that I could do the control breaking at the means to know when to stop
try {
return processResultSet( rs, queryParameters, session, returnProxies, forcedResultTransformer, maxRows, afterLoadActions );
}
finally {
session.getTransactionCoordinator().getJdbcCoordinator().release( st );
}
}
开发者ID:lamsfoundation,项目名称:lams,代码行数:32,代码来源:Loader.java
示例14: guessResultSize
import org.hibernate.engine.spi.RowSelection; //导入依赖的package包/类
/**
* If we're able to guess a likely size of the results we can optimize allocation
* of our datastructures.
* Essentially if we detect the user is not using pagination, we attempt to use the FetchSize
* as a reasonable hint. If fetch size is not being set either, it is reasonable to expect
* that we're going to have a single hit. In such a case it would be tempting to return a constant
* of value one, but that's dangerous as it doesn't scale up appropriately for example
* with an ArrayList if the guess is wrong.
*
* @param rowSelection
* @return a reasonable size to use for allocation
*/
private final int guessResultSize(RowSelection rowSelection) {
if ( rowSelection != null ) {
final int maxReasonableAllocation = rowSelection.getFetchSize() != null ? rowSelection.getFetchSize().intValue() : 100;
if ( rowSelection.getMaxRows() != null && rowSelection.getMaxRows().intValue() > 0 ) {
return Math.min( maxReasonableAllocation, rowSelection.getMaxRows().intValue() );
}
else if ( rowSelection.getFetchSize() != null && rowSelection.getFetchSize().intValue() > 0 ) {
return rowSelection.getFetchSize().intValue();
}
}
return 7;//magic number guessed as a reasonable default.
}
开发者ID:lamsfoundation,项目名称:lams,代码行数:25,代码来源:HQLQueryPlan.java
示例15: AbstractQueryImpl
import org.hibernate.engine.spi.RowSelection; //导入依赖的package包/类
public AbstractQueryImpl(
String queryString,
FlushMode flushMode,
SessionImplementor session,
ParameterMetadata parameterMetadata) {
this.session = session;
this.queryString = queryString;
this.selection = new RowSelection();
this.flushMode = flushMode;
this.cacheMode = null;
this.parameterMetadata = parameterMetadata;
}
开发者ID:lamsfoundation,项目名称:lams,代码行数:13,代码来源:AbstractQueryImpl.java
示例16: doExecute
import org.hibernate.engine.spi.RowSelection; //导入依赖的package包/类
protected int doExecute(QueryParameters parameters, SessionImplementor 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.getTransactionCoordinator().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.getTransactionCoordinator().getJdbcCoordinator().getResultSetReturn().executeUpdate( st );
}
finally {
if ( st != null ) {
session.getTransactionCoordinator().getJdbcCoordinator().release( st );
}
}
}
catch( SQLException sqle ) {
throw factory.getSQLExceptionHelper().convert( sqle, "could not execute update query", sql );
}
}
开发者ID:lamsfoundation,项目名称:lams,代码行数:41,代码来源:BasicExecutor.java
示例17: selectRecordsByNumberToKeep
import org.hibernate.engine.spi.RowSelection; //导入依赖的package包/类
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();
}
开发者ID:Pardus-Engerek,项目名称:engerek,代码行数:34,代码来源:SqlAuditServiceImpl.java
示例18: testLimit
import org.hibernate.engine.spi.RowSelection; //导入依赖的package包/类
@Test
public void testLimit() {
final RowSelection rowSelection = new RowSelection();
rowSelection.setMaxRows(getMaxRows());
LimitHandler limitHandler = ((SessionFactoryImpl) sessionFactory()).getDialect().getLimitHandler();
String limitStatement = limitHandler.processSql(SELECT_POST_COMMENT, rowSelection);
long startNanos = System.nanoTime();
doInJDBC(connection -> {
try (PreparedStatement statement = connection.prepareStatement(limitStatement)) {
limitHandler.bindLimitParametersAtEndOfQuery(rowSelection, statement, 1);
statement.setInt(1, getMaxRows());
statement.execute();
int count = 0;
ResultSet resultSet = statement.getResultSet();
while (resultSet.next()) {
resultSet.getLong(1);
count++;
}
assertEquals(getMaxRows(), count);
} catch (SQLException e) {
fail(e.getMessage());
}
});
LOGGER.info("{} Result Set with limit took {} millis",
dataSourceProvider().database(),
TimeUnit.NANOSECONDS.toMillis(System.nanoTime() - startNanos));
}
开发者ID:vladmihalcea,项目名称:high-performance-java-persistence,代码行数:29,代码来源:ResultSetLimitTest.java
示例19: selectRecordsByMaxAge
import org.hibernate.engine.spi.RowSelection; //导入依赖的package包/类
private int selectRecordsByMaxAge(Session session, String tempTable, Date minValue, Dialect dialect) {
// fill temporary table, we don't need to join task on object on
// container, oid and id is already in task table
StringBuilder selectSB = new StringBuilder();
selectSB.append("select a.id as id from ").append(RAuditEventRecord.TABLE_NAME).append(" a");
selectSB.append(" where a.").append(RAuditEventRecord.COLUMN_TIMESTAMP).append(" < ###TIME###");
String selectString = selectSB.toString();
// batch size
RowSelection rowSelection = new RowSelection();
rowSelection.setMaxRows(CLEANUP_AUDIT_BATCH_SIZE);
LimitHandler limitHandler = dialect.getLimitHandler();
selectString = limitHandler.processSql(selectString, rowSelection);
// replace ? -> batch size, $ -> ?
// Sorry for that .... I just don't know how to write this query in HQL,
// nor I'm not sure if limiting max size in
// compound insert into ... select ... query via query.setMaxSize()
// would work - TODO write more nicely if anybody knows how)
selectString = selectString.replace("?", String.valueOf(CLEANUP_AUDIT_BATCH_SIZE));
selectString = selectString.replace("###TIME###", "?");
String queryString = "insert into " + tempTable + " " + selectString;
LOGGER.trace("Query string = {}", queryString);
NativeQuery query = session.createNativeQuery(queryString);
query.setParameter(1, new Timestamp(minValue.getTime()));
return query.executeUpdate();
}
开发者ID:Evolveum,项目名称:midpoint,代码行数:31,代码来源:SqlAuditServiceImpl.java
示例20: selectRecordsByNumberToKeep
import org.hibernate.engine.spi.RowSelection; //导入依赖的package包/类
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.getLimitHandler();
selectString = limitHandler.processSql(selectString, rowSelection);
selectString = selectString.replace("?", String.valueOf(recordsToDelete));
String queryString = "insert into " + tempTable + " " + selectString;
LOGGER.trace("Query string = {}", queryString);
NativeQuery query = session.createNativeQuery(queryString);
return query.executeUpdate();
}
开发者ID:Evolveum,项目名称:midpoint,代码行数:34,代码来源:SqlAuditServiceImpl.java
注:本文中的org.hibernate.engine.spi.RowSelection类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论