Java Code Examples for org.hibernate.persister.entity.EntityPersister#isVersionPropertyGenerated()
The following examples show how to use
org.hibernate.persister.entity.EntityPersister#isVersionPropertyGenerated() .
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: ReactiveEntityDeleteAction.java From hibernate-reactive with GNU Lesser General Public License v2.1 | 4 votes |
@Override public CompletionStage<Void> reactiveExecute() throws HibernateException { final Serializable id = getId(); final EntityPersister persister = getPersister(); final SharedSessionContractImplementor session = getSession(); final Object instance = getInstance(); final boolean veto = preDelete(); Object version = getVersion(); if ( persister.isVersionPropertyGenerated() ) { // we need to grab the version value from the entity, otherwise // we have issues with generated-version entities that may have // multiple actions queued during the same flush version = persister.getVersion( instance ); } final Object ck; if ( persister.canWriteToCache() ) { final EntityDataAccess cache = persister.getCacheAccessStrategy(); ck = cache.generateCacheKey( id, persister, session.getFactory(), session.getTenantIdentifier() ); setLock( cache.lockItem( session, ck, version ) ); } else { ck = null; } CompletionStage<?> deleteStep = CompletionStages.nullFuture(); if ( !isCascadeDeleteEnabled() && !veto ) { deleteStep = ((ReactiveEntityPersister) persister).deleteReactive( id, version, instance, session ); } return deleteStep.thenAccept( deleteAR -> { //postDelete: // After actually deleting a row, record the fact that the instance no longer // exists on the database (needed for identity-column key generation), and // remove it from the session cache final PersistenceContext persistenceContext = session.getPersistenceContextInternal(); final EntityEntry entry = persistenceContext.removeEntry( instance ); if ( entry == null ) { throw new AssertionFailure( "possible non-threadsafe access to session" ); } entry.postDelete(); persistenceContext.removeEntity( entry.getEntityKey() ); persistenceContext.removeProxy( entry.getEntityKey() ); if ( persister.canWriteToCache() ) { persister.getCacheAccessStrategy().remove( session, ck ); } persistenceContext.getNaturalIdHelper().removeSharedNaturalIdCrossReference( persister, id, getNaturalIdValues() ); postDelete(); final StatisticsImplementor statistics = getSession().getFactory().getStatistics(); if ( statistics.isStatisticsEnabled() && !veto ) { statistics.deleteEntity( getPersister().getEntityName() ); } } ); }
Example 2
Source File: EntityDeleteAction.java From lams with GNU General Public License v2.0 | 4 votes |
@Override public void execute() throws HibernateException { final Serializable id = getId(); final EntityPersister persister = getPersister(); final SharedSessionContractImplementor session = getSession(); final Object instance = getInstance(); final boolean veto = preDelete(); Object version = this.version; if ( persister.isVersionPropertyGenerated() ) { // we need to grab the version value from the entity, otherwise // we have issues with generated-version entities that may have // multiple actions queued during the same flush version = persister.getVersion( instance ); } final Object ck; if ( persister.canWriteToCache() ) { final EntityDataAccess cache = persister.getCacheAccessStrategy(); ck = cache.generateCacheKey( id, persister, session.getFactory(), session.getTenantIdentifier() ); lock = cache.lockItem( session, ck, version ); } else { ck = null; } if ( !isCascadeDeleteEnabled && !veto ) { persister.delete( id, version, instance, session ); } //postDelete: // After actually deleting a row, record the fact that the instance no longer // exists on the database (needed for identity-column key generation), and // remove it from the session cache final PersistenceContext persistenceContext = session.getPersistenceContext(); final EntityEntry entry = persistenceContext.removeEntry( instance ); if ( entry == null ) { throw new AssertionFailure( "possible nonthreadsafe access to session" ); } entry.postDelete(); persistenceContext.removeEntity( entry.getEntityKey() ); persistenceContext.removeProxy( entry.getEntityKey() ); if ( persister.canWriteToCache() ) { persister.getCacheAccessStrategy().remove( session, ck); } persistenceContext.getNaturalIdHelper().removeSharedNaturalIdCrossReference( persister, id, naturalIdValues ); postDelete(); if ( getSession().getFactory().getStatistics().isStatisticsEnabled() && !veto ) { getSession().getFactory().getStatistics().deleteEntity( getPersister().getEntityName() ); } }
Example 3
Source File: EntityInsertAction.java From lams with GNU General Public License v2.0 | 4 votes |
@Override public void execute() throws HibernateException { nullifyTransientReferencesIfNotAlready(); final EntityPersister persister = getPersister(); final SharedSessionContractImplementor session = getSession(); final Object instance = getInstance(); final Serializable id = getId(); final boolean veto = preInsert(); // Don't need to lock the cache here, since if someone // else inserted the same pk first, the insert would fail if ( !veto ) { persister.insert( id, getState(), instance, session ); PersistenceContext persistenceContext = session.getPersistenceContext(); final EntityEntry entry = persistenceContext.getEntry( instance ); if ( entry == null ) { throw new AssertionFailure( "possible non-threadsafe access to session" ); } entry.postInsert( getState() ); if ( persister.hasInsertGeneratedProperties() ) { persister.processInsertGeneratedProperties( id, instance, getState(), session ); if ( persister.isVersionPropertyGenerated() ) { version = Versioning.getVersion( getState(), persister ); } entry.postUpdate( instance, getState(), version ); } persistenceContext.registerInsertedKey( persister, getId() ); } final SessionFactoryImplementor factory = session.getFactory(); if ( isCachePutEnabled( persister, session ) ) { final CacheEntry ce = persister.buildCacheEntry( instance, getState(), version, session ); cacheEntry = persister.getCacheEntryStructure().structure( ce ); final EntityDataAccess cache = persister.getCacheAccessStrategy(); final Object ck = cache.generateCacheKey( id, persister, factory, session.getTenantIdentifier() ); final boolean put = cacheInsert( persister, ck ); if ( put && factory.getStatistics().isStatisticsEnabled() ) { factory.getStatistics().entityCachePut( StatsHelper.INSTANCE.getRootEntityRole( persister ), cache.getRegion().getName() ); } } handleNaturalIdPostSaveNotifications( id ); postInsert(); if ( factory.getStatistics().isStatisticsEnabled() && !veto ) { factory.getStatistics().insertEntity( getPersister().getEntityName() ); } markExecuted(); }
Example 4
Source File: EntityDeleteAction.java From cacheonix-core with GNU Lesser General Public License v2.1 | 4 votes |
public void execute() throws HibernateException { Serializable id = getId(); EntityPersister persister = getPersister(); SessionImplementor session = getSession(); Object instance = getInstance(); boolean veto = preDelete(); Object version = this.version; if ( persister.isVersionPropertyGenerated() ) { // we need to grab the version value from the entity, otherwise // we have issues with generated-version entities that may have // multiple actions queued during the same flush version = persister.getVersion( instance, session.getEntityMode() ); } final CacheKey ck; if ( persister.hasCache() ) { ck = new CacheKey( id, persister.getIdentifierType(), persister.getRootEntityName(), session.getEntityMode(), session.getFactory() ); lock = persister.getCache().lock(ck, version); } else { ck = null; } if ( !isCascadeDeleteEnabled && !veto ) { persister.delete( id, version, instance, session ); } //postDelete: // After actually deleting a row, record the fact that the instance no longer // exists on the database (needed for identity-column key generation), and // remove it from the session cache final PersistenceContext persistenceContext = session.getPersistenceContext(); EntityEntry entry = persistenceContext.removeEntry( instance ); if ( entry == null ) { throw new AssertionFailure( "possible nonthreadsafe access to session" ); } entry.postDelete(); EntityKey key = new EntityKey( entry.getId(), entry.getPersister(), session.getEntityMode() ); persistenceContext.removeEntity(key); persistenceContext.removeProxy(key); if ( persister.hasCache() ) persister.getCache().evict(ck); postDelete(); if ( getSession().getFactory().getStatistics().isStatisticsEnabled() && !veto ) { getSession().getFactory().getStatisticsImplementor() .deleteEntity( getPersister().getEntityName() ); } }
Example 5
Source File: EntityInsertAction.java From cacheonix-core with GNU Lesser General Public License v2.1 | 4 votes |
public void execute() throws HibernateException { EntityPersister persister = getPersister(); SessionImplementor session = getSession(); Object instance = getInstance(); Serializable id = getId(); boolean veto = preInsert(); // Don't need to lock the cache here, since if someone // else inserted the same pk first, the insert would fail if ( !veto ) { persister.insert( id, state, instance, session ); EntityEntry entry = session.getPersistenceContext().getEntry( instance ); if ( entry == null ) { throw new AssertionFailure( "possible nonthreadsafe access to session" ); } entry.postInsert(); if ( persister.hasInsertGeneratedProperties() ) { persister.processInsertGeneratedProperties( id, instance, state, session ); if ( persister.isVersionPropertyGenerated() ) { version = Versioning.getVersion(state, persister); } entry.postUpdate(instance, state, version); } } final SessionFactoryImplementor factory = getSession().getFactory(); if ( isCachePutEnabled( persister, session ) ) { CacheEntry ce = new CacheEntry( state, persister, persister.hasUninitializedLazyProperties( instance, session.getEntityMode() ), version, session, instance ); cacheEntry = persister.getCacheEntryStructure().structure(ce); final CacheKey ck = new CacheKey( id, persister.getIdentifierType(), persister.getRootEntityName(), session.getEntityMode(), session.getFactory() ); // boolean put = persister.getCache().insert(ck, cacheEntry); boolean put = persister.getCache().insert( ck, cacheEntry, version ); if ( put && factory.getStatistics().isStatisticsEnabled() ) { factory.getStatisticsImplementor() .secondLevelCachePut( getPersister().getCache().getRegionName() ); } } postInsert(); if ( factory.getStatistics().isStatisticsEnabled() && !veto ) { factory.getStatisticsImplementor() .insertEntity( getPersister().getEntityName() ); } }