1 package org.hibernate.action; 3 4 import java.io.Serializable ; 5 6 import org.hibernate.HibernateException; 7 import org.hibernate.engine.SessionImplementor; 8 import org.hibernate.event.PostInsertEvent; 9 import org.hibernate.event.PreInsertEvent; 10 import org.hibernate.persister.entity.EntityPersister; 11 12 public final class EntityIdentityInsertAction extends EntityAction { 13 private final Object [] state; 14 private Serializable generatedId; 16 17 public EntityIdentityInsertAction(Object [] state, Object instance, EntityPersister persister, SessionImplementor session) 18 throws HibernateException { 19 super( session, null, instance, persister ); 20 this.state = state; 21 } 22 23 public void execute() throws HibernateException { 24 EntityPersister persister = getPersister(); 25 SessionImplementor session = getSession(); 26 Object instance = getInstance(); 27 28 PreInsertEvent preEvent = new PreInsertEvent( instance, null, state, persister ); 29 final boolean veto = session.getListeners().getPreInsertEventListener().onPreInsert( preEvent ); 30 31 34 if ( !veto ) generatedId = persister.insert( state, instance, session ); 35 36 43 44 PostInsertEvent postEvent = new PostInsertEvent( instance, generatedId, state, getPersister() ); 45 session.getListeners().getPostInsertEventListener().onPostInsert( postEvent ); 46 47 if ( getSession().getFactory().getStatistics().isStatisticsEnabled() && !veto ) { 48 getSession().getFactory().getStatisticsImplementor() 49 .insertEntity( getPersister().getEntityName() ); 50 } 51 52 } 53 54 public void afterTransactionCompletion(boolean success) throws HibernateException { 56 61 } 62 63 public boolean hasAfterTransactionCompletion() { 64 return false; 67 } 68 69 public final Serializable getGeneratedId() { 70 return generatedId; 71 } 72 73 } 74 75 76 77 78 79 80 81 | Popular Tags |