本文整理汇总了Java中org.hibernate.engine.spi.RowSelection类的典型用法代码示例。如果您正苦于以下问题:Java RowSelection类的具体用法?Java RowSelection怎么用?Java RowSelection使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
RowSelection类属于org.hibernate.engine.spi包,在下文中一共展示了RowSelection类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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;
}
};
}
示例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 );
}
}
示例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();
}
}
}
示例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;
}
}
示例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 );
}
}
示例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;
}
}
示例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();
}
}
}
}
示例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();
}
示例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 ?";
}
}
示例12: setup
import org.hibernate.engine.spi.RowSelection; //导入依赖的package包/类
@Before
public void setup() {
limitHandler = new SQLiteLimitHandler();
rowSelection = new RowSelection();
PowerMockito.mockStatic(LimitHelper.class);
}
示例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 );
}
}
示例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.
}
示例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;
}