• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Java LimitHelper类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Java中org.hibernate.dialect.pagination.LimitHelper的典型用法代码示例。如果您正苦于以下问题:Java LimitHelper类的具体用法?Java LimitHelper怎么用?Java LimitHelper使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



LimitHelper类属于org.hibernate.dialect.pagination包,在下文中一共展示了LimitHelper类的19个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。

示例1: getLimitHandler

import org.hibernate.dialect.pagination.LimitHelper; //导入依赖的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.dialect.pagination.LimitHelper; //导入依赖的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.dialect.pagination.LimitHelper; //导入依赖的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.dialect.pagination.LimitHelper; //导入依赖的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.dialect.pagination.LimitHelper; //导入依赖的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.dialect.pagination.LimitHelper; //导入依赖的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.dialect.pagination.LimitHelper; //导入依赖的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: processSql

import org.hibernate.dialect.pagination.LimitHelper; //导入依赖的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


示例9: setup

import org.hibernate.dialect.pagination.LimitHelper; //导入依赖的package包/类
@Before
public void setup() {
    limitHandler = new SQLiteLimitHandler();
    rowSelection = new RowSelection();

    PowerMockito.mockStatic(LimitHelper.class);
}
 
开发者ID:ZsoltFabok,项目名称:sqlite-dialect,代码行数:8,代码来源:SQLiteLimitHandlerTest.java


示例10: doQuery

import org.hibernate.dialect.pagination.LimitHelper; //导入依赖的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


示例11: getProcessedSql

import org.hibernate.dialect.pagination.LimitHelper; //导入依赖的package包/类
@Override
public String getProcessedSql() {
    if ( LimitHelper.useLimit( this, selection ) ) {
        // useLimitOffset: whether "offset" is set or not;
        // if set, use "LIMIT offset, row_count" syntax;
        // if not, use "LIMIT row_count"
        final boolean useLimitOffset = LimitHelper.hasFirstRow( selection );
        return sql + (useLimitOffset ? " limit ? offset ?" : " limit ?");
    }
    else {
        // or return unaltered SQL
        return sql;
    }
}
 
开发者ID:EnigmaBridge,项目名称:hibernate4-sqlite-dialect,代码行数:15,代码来源:SQLiteDialect.java


示例12: processSqlHasOffset

import org.hibernate.dialect.pagination.LimitHelper; //导入依赖的package包/类
@Test
public void processSqlHasOffset() {
    when(LimitHelper.hasFirstRow(rowSelection)).thenReturn(true);

    assertEquals("sql limit ? offset ?", limitHandler.processSql("sql", rowSelection));
}
 
开发者ID:ZsoltFabok,项目名称:sqlite-dialect,代码行数:7,代码来源:SQLiteLimitHandlerTest.java


示例13: processSqlDoesNotHaveOffset

import org.hibernate.dialect.pagination.LimitHelper; //导入依赖的package包/类
@Test
public void processSqlDoesNotHaveOffset() {
    when(LimitHelper.hasFirstRow(rowSelection)).thenReturn(false);

    assertEquals("sql limit ?", limitHandler.processSql("sql", rowSelection));
}
 
开发者ID:ZsoltFabok,项目名称:sqlite-dialect,代码行数:7,代码来源:SQLiteLimitHandlerTest.java


示例14: processSql

import org.hibernate.dialect.pagination.LimitHelper; //导入依赖的package包/类
@Override
public String processSql(String sql, RowSelection selection)
{
	final boolean hasOffset = LimitHelper.hasFirstRow(selection);
	return sql + (hasOffset ? " limit ? offset ?" : " limit ?");
}
 
开发者ID:olavloite,项目名称:spanner-hibernate,代码行数:7,代码来源:CloudSpannerDialect.java


示例15: extractResults

import org.hibernate.dialect.pagination.LimitHelper; //导入依赖的package包/类
@Override
public List extractResults(
		ResultSet resultSet,
		final SessionImplementor session,
		QueryParameters queryParameters,
		NamedParameterContext namedParameterContext,
		boolean returnProxies,
		boolean readOnly,
		ResultTransformer forcedResultTransformer,
		List<AfterLoadAction> afterLoadActionList) throws SQLException {

	handlePotentiallyEmptyCollectionRootReturns( loadPlan, queryParameters.getCollectionKeys(), resultSet, session );

	final int maxRows;
	final RowSelection selection = queryParameters.getRowSelection();
	if ( LimitHelper.hasMaxRows( selection ) ) {
		maxRows = selection.getMaxRows();
		LOG.tracef( "Limiting ResultSet processing to just %s rows", maxRows );
	}
	else {
		maxRows = Integer.MAX_VALUE;
	}

	// There are times when the "optional entity information" on QueryParameters should be used and
	// times when they should be ignored.  Loader uses its isSingleRowLoader method to allow
	// subclasses to override that.  Collection initializers, batch loaders, e.g. override that
	// it to be false.  The 'shouldUseOptionalEntityInstance' setting is meant to fill that same role.
	final boolean shouldUseOptionalEntityInstance = true;

	// Handles the "FETCH ALL PROPERTIES" directive in HQL
	final boolean forceFetchLazyAttributes = false;

	final ResultSetProcessingContextImpl context = new ResultSetProcessingContextImpl(
			resultSet,
			session,
			loadPlan,
			readOnly,
			shouldUseOptionalEntityInstance,
			forceFetchLazyAttributes,
			returnProxies,
			queryParameters,
			namedParameterContext,
			hadSubselectFetches
	);

	final List loadResults = new ArrayList();

	LOG.trace( "Processing result set" );
	int count;
	for ( count = 0; count < maxRows && resultSet.next(); count++ ) {
		LOG.debugf( "Starting ResultSet row #%s", count );

		Object logicalRow = rowReader.readRow( resultSet, context );

		// todo : apply transformers here?

		loadResults.add( logicalRow );

		context.finishUpRow();
	}

	LOG.tracev( "Done processing result set ({0} rows)", count );

	rowReader.finishUp( context, afterLoadActionList );
	context.wrapUp();

	session.getPersistenceContext().initializeNonLazyCollections();

	return loadResults;
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:71,代码来源:ResultSetProcessorImpl.java


示例16: prepareQueryStatement

import org.hibernate.dialect.pagination.LimitHelper; //导入依赖的package包/类
/**
 * Obtain a <tt>PreparedStatement</tt> with all parameters pre-bound.
 * Bind JDBC-style <tt>?</tt> parameters, named parameters, and
 * limit parameters.
 */
protected final PreparedStatement prepareQueryStatement(
		final String sql,
		final QueryParameters queryParameters,
		final LimitHandler limitHandler,
		final boolean scroll,
		final SessionImplementor session) throws SQLException, HibernateException {
	final Dialect dialect = getFactory().getDialect();
	final RowSelection selection = queryParameters.getRowSelection();
	final boolean useLimit = LimitHelper.useLimit( limitHandler, selection );
	final boolean hasFirstRow = LimitHelper.hasFirstRow( selection );
	final boolean useLimitOffset = hasFirstRow && useLimit && limitHandler.supportsLimitOffset();
	final boolean callable = queryParameters.isCallable();
	final ScrollMode scrollMode = getScrollMode( scroll, hasFirstRow, useLimitOffset, queryParameters );

	final PreparedStatement st = session.getTransactionCoordinator().getJdbcCoordinator()
			.getStatementPreparer().prepareQueryStatement( sql, callable, scrollMode );

	try {

		int col = 1;
		//TODO: can we limit stored procedures ?!
		col += limitHandler.bindLimitParametersAtStartOfQuery( st, col );

		if (callable) {
			col = dialect.registerResultSetOutParameter( (CallableStatement)st, col );
		}

		col += bindParameterValues( st, queryParameters, col, session );

		col += limitHandler.bindLimitParametersAtEndOfQuery( st, col );

		limitHandler.setMaxRows( st );

		if ( selection != null ) {
			if ( selection.getTimeout() != null ) {
				st.setQueryTimeout( selection.getTimeout() );
			}
			if ( selection.getFetchSize() != null ) {
				st.setFetchSize( selection.getFetchSize() );
			}
		}

		// handle lock timeout...
		final LockOptions lockOptions = queryParameters.getLockOptions();
		if ( lockOptions != null ) {
			if ( lockOptions.getTimeOut() != LockOptions.WAIT_FOREVER ) {
				if ( !dialect.supportsLockTimeouts() ) {
					if ( log.isDebugEnabled() ) {
						log.debugf(
								"Lock timeout [%s] requested but dialect reported to not support lock timeouts",
								lockOptions.getTimeOut()
						);
					}
				}
				else if ( dialect.isLockTimeoutParameterized() ) {
					st.setInt( col++, lockOptions.getTimeOut() );
				}
			}
		}

		if ( log.isTraceEnabled() ) {
			log.tracev( "Bound [{0}] parameters total", col );
		}
	}
	catch ( SQLException sqle ) {
		session.getTransactionCoordinator().getJdbcCoordinator().release( st );
		throw sqle;
	}
	catch ( HibernateException he ) {
		session.getTransactionCoordinator().getJdbcCoordinator().release( st );
		throw he;
	}

	return st;
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:81,代码来源:AbstractLoadPlanBasedLoader.java


示例17: processSql

import org.hibernate.dialect.pagination.LimitHelper; //导入依赖的package包/类
@Override
public String processSql(String sql, RowSelection selection) {
	final boolean hasOffset = LimitHelper.hasFirstRow(selection);
	return sql + (hasOffset ? " limit ? offset ?" : " limit ?");
}
 
开发者ID:shilongdai,项目名称:vsDiaryWriter,代码行数:6,代码来源:SQLiteDialect.java


示例18: getLimitHandler

import org.hibernate.dialect.pagination.LimitHelper; //导入依赖的package包/类
/**
 * Build LIMIT clause handler applicable for given selection criteria. Returns {@link NoopLimitHandler} delegate
 * if dialect does not support LIMIT expression or processed query does not use pagination.
 *
 * @param sql Query string.
 * @param selection Selection criteria.
 * @return LIMIT clause delegate.
 */
protected LimitHandler getLimitHandler(String sql, RowSelection selection) {
	final LimitHandler limitHandler = getFactory().getDialect().buildLimitHandler( sql, selection );
	return LimitHelper.useLimit( limitHandler, selection ) ? limitHandler : new NoopLimitHandler( sql, selection );
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:13,代码来源:Loader.java


示例19: getLimitHandler

import org.hibernate.dialect.pagination.LimitHelper; //导入依赖的package包/类
/**
 * Build LIMIT clause handler applicable for given selection criteria. Returns {@link org.hibernate.dialect.pagination.NoopLimitHandler} delegate
 * if dialect does not support LIMIT expression or processed query does not use pagination.
 *
 * @param sql Query string.
 * @param selection Selection criteria.
 * @return LIMIT clause delegate.
 */
protected LimitHandler getLimitHandler(String sql, RowSelection selection) {
	final LimitHandler limitHandler = getFactory().getDialect().buildLimitHandler( sql, selection );
	return LimitHelper.useLimit( limitHandler, selection ) ? limitHandler : new NoopLimitHandler( sql, selection );
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:13,代码来源:AbstractLoadPlanBasedLoader.java



注:本文中的org.hibernate.dialect.pagination.LimitHelper类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java EntityFallingBlock类代码示例发布时间:2022-05-23
下一篇:
Java XmiReader类代码示例发布时间:2022-05-23
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap