public void processFilters(String sql, SharedSessionContractImplementor session) { processFilters( sql, session.getLoadQueryInfluencers().getEnabledFilters(), session.getFactory() ); }
protected ExceptionConverter getExceptionConverter(){ return producer.getExceptionConverter(); }
/** * Reconnect to session after deserialization... * * @param session The session being deserialized */ @Override public void afterDeserialize(SharedSessionContractImplementor session) { if ( this.session != null || this.persister != null ) { throw new IllegalStateException( "already attached to a session." ); } // IMPL NOTE: non-flushed changes code calls this method with session == null... // guard against NullPointerException if ( session != null ) { this.session = session; this.persister = session.getFactory().getMetamodel().entityPersister( entityName ); this.instance = session.getPersistenceContext().getEntity( session.generateEntityKey( id, persister ) ); } }
private static EntityKey generateEntityKeyOrNull(Serializable id, SharedSessionContractImplementor s, String entityName) { if ( id == null || s == null || entityName == null ) { return null; } return s.generateEntityKey( id, s.getFactory().getEntityPersister( entityName ) ); }
protected boolean isConnectedToSession() { return session != null && session.isOpen() && session.getPersistenceContext().containsCollection( this ); }
@Override public boolean isNull(Object owner, SharedSessionContractImplementor session) { if ( propertyName != null ) { final EntityPersister ownerPersister = session.getFactory().getMetamodel().entityPersister( entityName ); final Serializable id = session.getContextEntityIdentifier( owner ); final EntityKey entityKey = session.generateEntityKey( id, ownerPersister ); return session.getPersistenceContext().isPropertyNull( entityKey, getPropertyName() ); } else { return false; } }
@Override public Object assemble(Serializable cached, SharedSessionContractImplementor session, Object owner) throws HibernateException { if ( cached==null ) { return null; } else { return deepCopy( cached, session.getFactory() ); } }
private boolean isAffectedByEnabledFetchProfiles(SharedSessionContractImplementor session) { for ( String s : session.getLoadQueryInfluencers().getEnabledFetchProfileNames() ) { if ( affectingFetchProfileNames.contains( s ) ) { return true; } } return false; }
/** * Attempt to initialize the proxy without loading anything from the database. * * This will only have any effect if the proxy is still attached to a session, * and the entity being proxied has been loaded and added to the persistence context * of that session since the proxy was created. */ public final void initializeWithoutLoadIfPossible() { if ( !initialized && session != null && session.isOpenOrWaitingForAutoClose() ) { final EntityKey key = session.generateEntityKey( getIdentifier(), session.getFactory().getMetamodel().entityPersister( getEntityName() ) ); final Object entity = session.getPersistenceContext().getEntity( key ); if ( entity != null ) { setImplementation( entity ); } } }
public void createTempTable( IdTableInfoImpl idTableInfo, TempTableDdlTransactionHandling ddlTransactionHandling, SharedSessionContractImplementor session) { // Don't really know all the codes required to adequately decipher returned jdbc exceptions here. // simply allow the failure to be eaten and the subsequent insert-selects/deletes should fail TemporaryTableCreationWork work = new TemporaryTableCreationWork( idTableInfo, session.getFactory() ); if ( ddlTransactionHandling == TempTableDdlTransactionHandling.NONE ) { final Connection connection = session.getJdbcCoordinator() .getLogicalConnection() .getPhysicalConnection(); work.execute( connection ); session.getJdbcCoordinator().afterStatementExecution(); } else { session.getTransactionCoordinator() .createIsolationDelegate() .delegateWork( work, ddlTransactionHandling == TempTableDdlTransactionHandling.ISOLATE_AND_TRANSACT ); } }
@Override public int executeUpdate() throws HibernateException { if ( ! getProducer().isTransactionInProgress() ) { throw getProducer().getExceptionConverter().convert( new TransactionRequiredException( "Executing an update/delete query" if ( getProducer().getFactory().getSessionFactoryOptions().isJpaBootstrap() ) { throw getExceptionConverter().convert( e );
protected Object getObjectFromList(List results, Serializable id, SharedSessionContractImplementor session) { for ( Object obj : results ) { final boolean equal = persister.getIdentifierType().isEqual( id, session.getContextEntityIdentifier( obj ), session.getFactory() ); if ( equal ) { return obj; } } return null; }
@Override public Object getForInsert(Object owner, Map mergeMap, SharedSessionContractImplementor session) { if ( session == null ) { return PropertyAccessStrategyBackRefImpl.UNKNOWN; } else { return session.getPersistenceContext().getIndexInOwner( entityName, propertyName, owner, mergeMap ); } }
final EntityPersister entityPersister; if ( optionalObject != null ) { entityPersister = session.getEntityPersister( optionalEntityName, optionalObject ); entityPersister = session.getFactory().getMetamodel().entityPersister( optionalEntityName ); session ); return session.generateEntityKey( identifierState, entityPersister ); return session.generateEntityKey( optionalId, entityPersister );
private static boolean useMinimalPuts(SharedSessionContractImplementor session, EntityEntry entityEntry) { if ( session.getFactory().getSessionFactoryOptions().isMinimalPutsEnabled() ) { return session.getCacheMode() != CacheMode.REFRESH; } else { return entityEntry.getPersister().hasLazyProperties() && entityEntry.getPersister().isLazyPropertiesCacheable(); } }
@Override public void jdbcReleaseRegistryResourcesStart() { session.getJdbcCoordinator().abortBatch(); }
public void cleanUpRows(String tableName, SharedSessionContractImplementor session) { final String sql = "delete from " + tableName + " where " + SESSION_ID_COLUMN_NAME + "=?"; try { PreparedStatement ps = null; try { ps = session.getJdbcCoordinator().getStatementPreparer().prepareStatement( sql, false ); bindSessionIdentifier( ps, session, 1 ); session.getJdbcCoordinator().getResultSetReturn().executeUpdate( ps ); } finally { if ( ps != null ) { try { session.getJdbcCoordinator().getLogicalConnection().getResourceRegistry().release( ps ); } catch( Throwable ignore ) { // ignore } } } } catch (SQLException e) { throw session.getJdbcServices().getSqlExceptionHelper().convert( e, "Unable to clean up id table [" + tableName + "]", sql ); } } }
/** * Remove the entity key with the specified {@code id} and {@code persister} from * the batch loadable entities {@link BatchFetchQueue}. * * @param id - the ID for the entity to be removed * @param persister - the entity persister * @param session - the session */ public static void removeBatchLoadableEntityKey( Serializable id, EntityPersister persister, SharedSessionContractImplementor session) { final EntityKey entityKey = session.generateEntityKey( id, persister ); final BatchFetchQueue batchFetchQueue = session.getPersistenceContext().getBatchFetchQueue(); batchFetchQueue.removeBatchLoadableEntityKey( entityKey ); } }
@Override public Object load(Serializable id, Object optionalObject, SharedSessionContractImplementor session) { LOG.debugf( "Loading entity: %s using named query: %s", persister.getEntityName(), queryName ); // IMPL NOTE: essentially we perform the named query (which loads the entity into the PC), and then // do an internal lookup of the entity from the PC. final AbstractProducedQuery query = (AbstractProducedQuery) session.getNamedQuery( queryName ); if ( query.getParameterMetadata().hasNamedParameters() ) { query.setParameter( query.getNamedParameters()[0], id, persister.getIdentifierType() ); } else { query.setParameter( position, id, persister.getIdentifierType() ); } query.setOptionalId( id ); query.setOptionalEntityName( persister.getEntityName() ); query.setOptionalObject( optionalObject ); query.setFlushMode( FlushMode.MANUAL ); query.list(); // now look up the object we are really interested in! // (this lets us correctly handle proxies and multi-row or multi-column queries) return session.getPersistenceContext().getEntity( session.generateEntityKey( id, persister ) ); } }
/** * Get the current state of the entity as known to the underlying * database, or null if there is no corresponding row * <p/> * {@inheritDoc} */ @Override public Object[] getDatabaseSnapshot(Serializable id, EntityPersister persister) throws HibernateException { final EntityKey key = session.generateEntityKey( id, persister ); final Object cached = entitySnapshotsByKey.get( key ); if ( cached != null ) { return cached == NO_ROW ? null : (Object[]) cached; } else { final Object[] snapshot = persister.getDatabaseSnapshot( id, session ); entitySnapshotsByKey.put( key, snapshot == null ? NO_ROW : snapshot ); return snapshot; } }