Java Code Examples for org.hibernate.LockOptions#WAIT_FOREVER
The following examples show how to use
org.hibernate.LockOptions#WAIT_FOREVER .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: AbstractEntityPersister.java From lams with GNU General Public License v2.0 | 5 votes |
protected UniqueEntityLoader getAppropriateLoader(LockOptions lockOptions, SharedSessionContractImplementor session) { if ( queryLoader != null ) { // if the user specified a custom query loader we need to that // regardless of any other consideration return queryLoader; } else if ( isAffectedByEnabledFilters( session ) ) { // because filters affect the rows returned (because they add // restrictions) these need to be next in precedence return createEntityLoader( lockOptions, session.getLoadQueryInfluencers() ); } else if ( session.getLoadQueryInfluencers().getInternalFetchProfile() != null && LockMode.UPGRADE.greaterThan( lockOptions.getLockMode() ) ) { // Next, we consider whether an 'internal' fetch profile has been set. // This indicates a special fetch profile Hibernate needs applied // (for its merge loading process e.g.). return loaders.get( session.getLoadQueryInfluencers().getInternalFetchProfile() ); } else if ( isAffectedByEnabledFetchProfiles( session ) ) { // If the session has associated influencers we need to adjust the // SQL query used for loading based on those influencers return createEntityLoader( lockOptions, session.getLoadQueryInfluencers() ); } else if ( isAffectedByEntityGraph( session ) ) { return createEntityLoader( lockOptions, session.getLoadQueryInfluencers() ); } else if ( lockOptions.getTimeOut() != LockOptions.WAIT_FOREVER ) { return createEntityLoader( lockOptions, session.getLoadQueryInfluencers() ); } else { return getLoaderByLockMode( lockOptions.getLockMode() ); } }
Example 2
Source File: NamedQueryDefinition.java From lams with GNU General Public License v2.0 | 5 votes |
/** * This form is used to bind named queries from Hibernate metadata, both {@code hbm.xml} files and * {@link org.hibernate.annotations.NamedQuery} annotation. * * @param name The name under which to key/register the query * @param query The query string. * @param cacheable Is the query cacheable? * @param cacheRegion If cacheable, was there a specific region named? * @param timeout Query timeout, {@code null} indicates no timeout * @param fetchSize Fetch size associated with the query, {@code null} indicates no limit * @param flushMode Flush mode associated with query * @param cacheMode Cache mode associated with query * @param readOnly Should entities returned from this query (those not already associated with the Session anyway) * be loaded as read-only? * @param comment SQL comment to be used in the generated SQL, {@code null} indicates none * @param parameterTypes (no idea, afaict this is always passed as null) * * @deprecated Use {@link NamedQueryDefinitionBuilder} instead. */ @Deprecated public NamedQueryDefinition( String name, String query, boolean cacheable, String cacheRegion, Integer timeout, Integer fetchSize, FlushMode flushMode, CacheMode cacheMode, boolean readOnly, String comment, Map parameterTypes) { this( name, query, cacheable, cacheRegion, timeout, LockOptions.WAIT_FOREVER, fetchSize, flushMode, cacheMode, readOnly, comment, parameterTypes ); }
Example 3
Source File: AbstractSelectLockingStrategy.java From lams with GNU General Public License v2.0 | 5 votes |
protected String determineSql(int timeout) { if ( timeout == LockOptions.WAIT_FOREVER) { return waitForeverSql; } else if ( timeout == LockOptions.NO_WAIT) { return getNoWaitSql(); } else if ( timeout == LockOptions.SKIP_LOCKED) { return getSkipLockedSql(); } else { return generateLockString( timeout ); } }
Example 4
Source File: Loader.java From lams with GNU General Public License v2.0 | 4 votes |
/** * 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( String sql, final QueryParameters queryParameters, final LimitHandler limitHandler, final boolean scroll, final SharedSessionContractImplementor 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 ); PreparedStatement st = session.getJdbcCoordinator().getStatementPreparer().prepareQueryStatement( sql, callable, scrollMode ); try { int col = 1; //TODO: can we limit stored procedures ?! col += limitHandler.bindLimitParametersAtStartOfQuery( selection, st, col ); if ( callable ) { col = dialect.registerResultSetOutParameter( (CallableStatement) st, col ); } col += bindParameterValues( st, queryParameters, col, session ); col += limitHandler.bindLimitParametersAtEndOfQuery( selection, st, col ); limitHandler.setMaxRows( selection, st ); if ( selection != null ) { if ( selection.getTimeout() != null ) { st.setQueryTimeout( selection.getTimeout() ); } if ( selection.getFetchSize() != null ) { st.setFetchSize( selection.getFetchSize() ); } } // handle lock timeout... 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 | HibernateException e) { session.getJdbcCoordinator().getLogicalConnection().getResourceRegistry().release( st ); session.getJdbcCoordinator().afterStatementExecution(); throw e; } return st; }
Example 5
Source File: AbstractLoadPlanBasedLoader.java From lams with GNU General Public License v2.0 | 4 votes |
/** * 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 SharedSessionContractImplementor session) throws SQLException, HibernateException { final Dialect dialect = session.getJdbcServices().getJdbcEnvironment().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.getJdbcCoordinator() .getStatementPreparer().prepareQueryStatement( sql, callable, scrollMode ); try { int col = 1; //TODO: can we limit stored procedures ?! col += limitHandler.bindLimitParametersAtStartOfQuery( selection, st, col ); if (callable) { col = dialect.registerResultSetOutParameter( (CallableStatement)st, col ); } col += bindParameterValues( st, queryParameters, col, session ); col += limitHandler.bindLimitParametersAtEndOfQuery( selection, st, col ); limitHandler.setMaxRows( selection, 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.getJdbcCoordinator().getResourceRegistry().release( st ); session.getJdbcCoordinator().afterStatementExecution(); throw sqle; } catch ( HibernateException he ) { session.getJdbcCoordinator().getResourceRegistry().release( st ); session.getJdbcCoordinator().afterStatementExecution(); throw he; } return st; }