当前位置: 首页>>代码示例>>Java>>正文


Java RowSelection.setMaxRows方法代码示例

本文整理汇总了Java中org.hibernate.engine.spi.RowSelection.setMaxRows方法的典型用法代码示例。如果您正苦于以下问题:Java RowSelection.setMaxRows方法的具体用法?Java RowSelection.setMaxRows怎么用?Java RowSelection.setMaxRows使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.hibernate.engine.spi.RowSelection的用法示例。


在下文中一共展示了RowSelection.setMaxRows方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: 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

示例2: 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

示例3: 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

示例4: 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

示例5: 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

示例6: 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

示例7: 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.setMaxRows方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。