EntityIdentityInsertActionpublic final class EntityIdentityInsertAction extends EntityAction
Fields Summary |
---|
private final Object[] | state | private final boolean | isDelayed | private final org.hibernate.engine.EntityKey | delayedEntityKey | private Serializable | generatedId |
Methods Summary |
---|
public void | afterTransactionCompletion(boolean success)
//TODO: reenable if we also fix the above todo
/*EntityPersister persister = getEntityPersister();
if ( success && persister.hasCache() && !persister.isCacheInvalidationRequired() ) {
persister.getCache().afterInsert( getGeneratedId(), cacheEntry );
}*/
postCommitInsert();
| public void | execute()
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() );
}
| private synchronized org.hibernate.engine.EntityKey | generateDelayedEntityKey()
if ( !isDelayed ) {
throw new AssertionFailure( "cannot request delayed entity-key for non-delayed post-insert-id generation" );
}
return new EntityKey( new DelayedPostInsertIdentifier(), getPersister(), getSession().getEntityMode() );
| public org.hibernate.engine.EntityKey | getDelayedEntityKey()
return delayedEntityKey;
| public final java.io.Serializable | getGeneratedId()
return generatedId;
| public boolean | hasAfterTransactionCompletion()
//TODO: simply remove this override
// if we fix the above todos
return hasPostCommitEventListeners();
| protected boolean | hasPostCommitEventListeners()
return getSession().getListeners().getPostCommitInsertEventListeners().length>0;
| private void | postCommitInsert()
PostInsertEventListener[] postListeners = getSession().getListeners()
.getPostCommitInsertEventListeners();
if (postListeners.length>0) {
PostInsertEvent postEvent = new PostInsertEvent(
getInstance(),
generatedId,
state,
getPersister(),
(EventSource) getSession()
);
for ( int i = 0; i < postListeners.length; i++ ) {
postListeners[i].onPostInsert(postEvent);
}
}
| private void | postInsert()
if ( isDelayed ) {
getSession().getPersistenceContext().replaceDelayedEntityIdentityInsertKeys( delayedEntityKey, generatedId );
}
PostInsertEventListener[] postListeners = getSession().getListeners()
.getPostInsertEventListeners();
if (postListeners.length>0) {
PostInsertEvent postEvent = new PostInsertEvent(
getInstance(),
generatedId,
state,
getPersister(),
(EventSource) getSession()
);
for ( int i = 0; i < postListeners.length; i++ ) {
postListeners[i].onPostInsert(postEvent);
}
}
| private boolean | preInsert()
PreInsertEventListener[] preListeners = getSession().getListeners()
.getPreInsertEventListeners();
boolean veto = false;
if (preListeners.length>0) {
PreInsertEvent preEvent = new PreInsertEvent( getInstance(), null, state, getPersister(), getSession() );
for ( int i = 0; i < preListeners.length; i++ ) {
veto = preListeners[i].onPreInsert(preEvent) || veto;
}
}
return veto;
|
|