Java Code Examples for org.hibernate.engine.spi.PersistenceContext#setDefaultReadOnly()
The following examples show how to use
org.hibernate.engine.spi.PersistenceContext#setDefaultReadOnly() .
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: Loader.java From lams with GNU General Public License v2.0 | 5 votes |
public List doQueryAndInitializeNonLazyCollections( final SharedSessionContractImplementor session, final QueryParameters queryParameters, final boolean returnProxies, final ResultTransformer forcedResultTransformer) throws HibernateException, SQLException { final PersistenceContext persistenceContext = session.getPersistenceContext(); boolean defaultReadOnlyOrig = persistenceContext.isDefaultReadOnly(); if ( queryParameters.isReadOnlyInitialized() ) { // The read-only/modifiable mode for the query was explicitly set. // Temporarily set the default read-only/modifiable setting to the query's setting. persistenceContext.setDefaultReadOnly( queryParameters.isReadOnly() ); } else { // The read-only/modifiable setting for the query was not initialized. // Use the default read-only/modifiable from the persistence context instead. queryParameters.setReadOnly( persistenceContext.isDefaultReadOnly() ); } persistenceContext.beforeLoad(); List result; try { try { result = doQuery( session, queryParameters, returnProxies, forcedResultTransformer ); } finally { persistenceContext.afterLoad(); } persistenceContext.initializeNonLazyCollections(); } finally { // Restore the original default persistenceContext.setDefaultReadOnly( defaultReadOnlyOrig ); } return result; }
Example 2
Source File: DynamicBatchingEntityLoaderBuilder.java From lams with GNU General Public License v2.0 | 4 votes |
public List doEntityBatchFetch( SharedSessionContractImplementor session, QueryParameters queryParameters, Serializable[] ids) { final String sql = StringHelper.expandBatchIdPlaceholder( sqlTemplate, ids, alias, persister.getKeyColumnNames(), session.getJdbcServices().getJdbcEnvironment().getDialect() ); try { final PersistenceContext persistenceContext = session.getPersistenceContext(); boolean defaultReadOnlyOrig = persistenceContext.isDefaultReadOnly(); if ( queryParameters.isReadOnlyInitialized() ) { // The read-only/modifiable mode for the query was explicitly set. // Temporarily set the default read-only/modifiable setting to the query's setting. persistenceContext.setDefaultReadOnly( queryParameters.isReadOnly() ); } else { // The read-only/modifiable setting for the query was not initialized. // Use the default read-only/modifiable from the persistence context instead. queryParameters.setReadOnly( persistenceContext.isDefaultReadOnly() ); } persistenceContext.beforeLoad(); List results; try { try { results = doTheLoad( sql, queryParameters, session ); } finally { persistenceContext.afterLoad(); } persistenceContext.initializeNonLazyCollections(); log.debug( "Done batch load" ); return results; } finally { // Restore the original default persistenceContext.setDefaultReadOnly( defaultReadOnlyOrig ); } } catch ( SQLException sqle ) { throw session.getJdbcServices().getSqlExceptionHelper().convert( sqle, "could not load an entity batch: " + MessageHelper.infoString( getEntityPersisters()[0], ids, session.getFactory() ), sql ); } }
Example 3
Source File: Loader.java From lams with GNU General Public License v2.0 | 4 votes |
private List getResultFromQueryCache( final SharedSessionContractImplementor session, final QueryParameters queryParameters, final Set<Serializable> querySpaces, final Type[] resultTypes, final QueryResultsCache queryCache, final QueryKey key) { List result = null; if ( session.getCacheMode().isGetEnabled() ) { boolean isImmutableNaturalKeyLookup = queryParameters.isNaturalKeyLookup() && resultTypes.length == 1 && resultTypes[0].isEntityType() && getEntityPersister( EntityType.class.cast( resultTypes[0] ) ) .getEntityMetamodel() .hasImmutableNaturalId(); final PersistenceContext persistenceContext = session.getPersistenceContext(); boolean defaultReadOnlyOrig = persistenceContext.isDefaultReadOnly(); if ( queryParameters.isReadOnlyInitialized() ) { // The read-only/modifiable mode for the query was explicitly set. // Temporarily set the default read-only/modifiable setting to the query's setting. persistenceContext.setDefaultReadOnly( queryParameters.isReadOnly() ); } else { // The read-only/modifiable setting for the query was not initialized. // Use the default read-only/modifiable from the persistence context instead. queryParameters.setReadOnly( persistenceContext.isDefaultReadOnly() ); } try { result = queryCache.get( key, querySpaces, key.getResultTransformer().getCachedResultTypes( resultTypes ), session ); } finally { persistenceContext.setDefaultReadOnly( defaultReadOnlyOrig ); } if ( factory.getStatistics().isStatisticsEnabled() ) { if ( result == null ) { factory.getStatistics().queryCacheMiss( getQueryIdentifier(), queryCache.getRegion().getName() ); } else { factory.getStatistics().queryCacheHit( getQueryIdentifier(), queryCache.getRegion().getName() ); } } } return result; }
Example 4
Source File: DynamicBatchingCollectionInitializerBuilder.java From lams with GNU General Public License v2.0 | 4 votes |
public final void doBatchedCollectionLoad( final SharedSessionContractImplementor session, final Serializable[] ids, final Type type) throws HibernateException { if ( LOG.isDebugEnabled() ) { LOG.debugf( "Batch loading collection: %s", MessageHelper.collectionInfoString( getCollectionPersisters()[0], ids, getFactory() ) ); } final Type[] idTypes = new Type[ids.length]; Arrays.fill( idTypes, type ); final QueryParameters queryParameters = new QueryParameters( idTypes, ids, ids ); final String sql = StringHelper.expandBatchIdPlaceholder( sqlTemplate, ids, alias, collectionPersister().getKeyColumnNames(), session.getJdbcServices().getJdbcEnvironment().getDialect() ); try { final PersistenceContext persistenceContext = session.getPersistenceContext(); boolean defaultReadOnlyOrig = persistenceContext.isDefaultReadOnly(); if ( queryParameters.isReadOnlyInitialized() ) { // The read-only/modifiable mode for the query was explicitly set. // Temporarily set the default read-only/modifiable setting to the query's setting. persistenceContext.setDefaultReadOnly( queryParameters.isReadOnly() ); } else { // The read-only/modifiable setting for the query was not initialized. // Use the default read-only/modifiable from the persistence context instead. queryParameters.setReadOnly( persistenceContext.isDefaultReadOnly() ); } persistenceContext.beforeLoad(); try { try { doTheLoad( sql, queryParameters, session ); } finally { persistenceContext.afterLoad(); } persistenceContext.initializeNonLazyCollections(); } finally { // Restore the original default persistenceContext.setDefaultReadOnly( defaultReadOnlyOrig ); } } catch ( SQLException e ) { throw session.getJdbcServices().getSqlExceptionHelper().convert( e, "could not initialize a collection batch: " + MessageHelper.collectionInfoString( collectionPersister(), ids, getFactory() ), sql ); } LOG.debug( "Done batch load" ); }
Example 5
Source File: AbstractLoadPlanBasedLoader.java From lams with GNU General Public License v2.0 | 4 votes |
protected List executeLoad( SharedSessionContractImplementor session, QueryParameters queryParameters, LoadQueryDetails loadQueryDetails, boolean returnProxies, ResultTransformer forcedResultTransformer, List<AfterLoadAction> afterLoadActions) throws SQLException { final PersistenceContext persistenceContext = session.getPersistenceContext(); final boolean defaultReadOnlyOrig = persistenceContext.isDefaultReadOnly(); if ( queryParameters.isReadOnlyInitialized() ) { // The read-only/modifiable mode for the query was explicitly set. // Temporarily set the default read-only/modifiable setting to the query's setting. persistenceContext.setDefaultReadOnly( queryParameters.isReadOnly() ); } else { // The read-only/modifiable setting for the query was not initialized. // Use the default read-only/modifiable from the persistence context instead. queryParameters.setReadOnly( persistenceContext.isDefaultReadOnly() ); } persistenceContext.beforeLoad(); try { List results = null; final String sql = loadQueryDetails.getSqlStatement(); SqlStatementWrapper wrapper = null; try { wrapper = executeQueryStatement( sql, queryParameters, false, afterLoadActions, session ); results = loadQueryDetails.getResultSetProcessor().extractResults( wrapper.getResultSet(), session, queryParameters, new NamedParameterContext() { @Override public int[] getNamedParameterLocations(String name) { return AbstractLoadPlanBasedLoader.this.getNamedParameterLocs( name ); } }, returnProxies, queryParameters.isReadOnly(), forcedResultTransformer, afterLoadActions ); } finally { if ( wrapper != null ) { session.getJdbcCoordinator().getResourceRegistry().release( wrapper.getResultSet(), wrapper.getStatement() ); session.getJdbcCoordinator().getResourceRegistry().release( wrapper.getStatement() ); session.getJdbcCoordinator().afterStatementExecution(); } persistenceContext.afterLoad(); } persistenceContext.initializeNonLazyCollections(); return results; } finally { // Restore the original default persistenceContext.setDefaultReadOnly( defaultReadOnlyOrig ); } }