Java Code Examples for org.hibernate.persister.entity.EntityPersister#hasInsertGeneratedProperties()

The following examples show how to use org.hibernate.persister.entity.EntityPersister#hasInsertGeneratedProperties() . 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: EntityIdentityInsertAction.java    From cacheonix-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
public void execute() throws HibernateException {
	
	final EntityPersister persister = getPersister();
	final SessionImplementor session = getSession();
	final Object instance = getInstance();
	
	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 ) {
		generatedId = persister.insert( state, instance, session );
		if ( persister.hasInsertGeneratedProperties() ) {
			persister.processInsertGeneratedProperties( generatedId, instance, state, session );
		}
		//need to do that here rather than in the save event listener to let
		//the post insert events to have a id-filled entity when IDENTITY is used (EJB3)
		persister.setIdentifier( instance, generatedId, session.getEntityMode() );
	}


	//TODO: this bit actually has to be called after all cascades!
	//      but since identity insert is called *synchronously*,
	//      instead of asynchronously as other actions, it isn't
	/*if ( persister.hasCache() && !persister.isCacheInvalidationRequired() ) {
		cacheEntry = new CacheEntry(object, persister, session);
		persister.getCache().insert(generatedId, cacheEntry);
	}*/
	
	postInsert();

	if ( session.getFactory().getStatistics().isStatisticsEnabled() && !veto ) {
		session.getFactory().getStatisticsImplementor()
				.insertEntity( getPersister().getEntityName() );
	}

}
 
Example 2
Source File: EntityInsertAction.java    From lams with GNU General Public License v2.0 4 votes vote down vote up
@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 3
Source File: EntityIdentityInsertAction.java    From lams with GNU General Public License v2.0 4 votes vote down vote up
@Override
public void execute() throws HibernateException {
	nullifyTransientReferencesIfNotAlready();

	final EntityPersister persister = getPersister();
	final SharedSessionContractImplementor session = getSession();
	final Object instance = getInstance();

	setVeto( preInsert() );

	// Don't need to lock the cache here, since if someone
	// else inserted the same pk first, the insert would fail

	if ( !isVeto() ) {
		generatedId = persister.insert( getState(), instance, session );
		if ( persister.hasInsertGeneratedProperties() ) {
			persister.processInsertGeneratedProperties( generatedId, instance, getState(), session );
		}
		//need to do that here rather than in the save event listener to let
		//the post insert events to have a id-filled entity when IDENTITY is used (EJB3)
		persister.setIdentifier( instance, generatedId, session );
		session.getPersistenceContext().registerInsertedKey( getPersister(), generatedId );
		entityKey = session.generateEntityKey( generatedId, persister );
		session.getPersistenceContext().checkUniqueness( entityKey, getInstance() );
	}


	//TODO: this bit actually has to be called after all cascades!
	//      but since identity insert is called *synchronously*,
	//      instead of asynchronously as other actions, it isn't
	/*if ( persister.hasCache() && !persister.isCacheInvalidationRequired() ) {
		cacheEntry = new CacheEntry(object, persister, session);
		persister.getCache().insert(generatedId, cacheEntry);
	}*/

	postInsert();

	if ( session.getFactory().getStatistics().isStatisticsEnabled() && !isVeto() ) {
		session.getFactory().getStatistics().insertEntity( getPersister().getEntityName() );
	}

	markExecuted();
}
 
Example 4
Source File: EntityInsertAction.java    From cacheonix-core with GNU Lesser General Public License v2.1 4 votes vote down vote up
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() );
		}

	}