1 package org.hibernate.action; 3 4 import org.hibernate.AssertionFailure; 5 import org.hibernate.engine.SessionImplementor; 6 import org.hibernate.persister.entity.EntityPersister; 7 import org.hibernate.pretty.MessageHelper; 8 import org.hibernate.util.StringHelper; 9 10 import java.io.IOException ; 11 import java.io.ObjectInputStream ; 12 import java.io.Serializable ; 13 14 18 public abstract class EntityAction implements Executable, Serializable , Comparable { 19 20 private final SessionImplementor session; 21 private final Serializable id; 22 private final Object instance; 23 private final String entityName; 24 25 private transient EntityPersister persister; 26 27 protected EntityAction(SessionImplementor session, Serializable id, Object instance, EntityPersister persister) { 28 this.session = session; 29 this.id = id; 30 this.persister = persister; 31 this.instance = instance; 32 this.entityName = persister.getEntityName(); 33 } 34 35 private void readObject(ObjectInputStream ois) throws IOException , ClassNotFoundException { 36 ois.defaultReadObject(); 37 persister = session.getFactory() 38 .getEntityPersister( entityName ); 39 } 40 41 public final Serializable [] getPropertySpaces() { 42 return persister.getPropertySpaces(); 43 } 44 45 protected final SessionImplementor getSession() { 46 return session; 47 } 48 49 protected final Serializable getId() { 50 return id; 51 } 52 53 protected final EntityPersister getPersister() { 54 return persister; 55 } 56 57 protected final Object getInstance() { 58 return instance; 59 } 60 61 public void beforeExecutions() { 62 throw new AssertionFailure( "beforeExecutions() called for non-collection action" ); 63 } 64 65 public boolean hasAfterTransactionCompletion() { 66 return persister.hasCache(); 67 } 68 69 public String toString() { 70 return StringHelper.unqualify( getClass().getName() ) + MessageHelper.infoString( entityName, id ); 71 } 72 73 public int compareTo(Object other) { 74 EntityAction action = ( EntityAction ) other; 75 int roleComparison = entityName.compareTo( action.entityName ); 77 if ( roleComparison != 0 ) { 78 return roleComparison; 79 } 80 else { 81 return persister.getIdentifierType() 83 .compare( id, action.id, session.getEntityMode() ); 84 } 85 } 86 } 87 88 89 90 91 92 93 | Popular Tags |