KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > hibernate > action > EntityAction


1 //$Id: EntityAction.java,v 1.11 2005/05/27 03:53:58 oneovthafew Exp $
2
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 JavaDoc;
11 import java.io.ObjectInputStream JavaDoc;
12 import java.io.Serializable JavaDoc;
13
14 /**
15  * Any action relating to insert/update/delete of an entity instance
16  * @author Gavin King
17  */

18 public abstract class EntityAction implements Executable, Serializable JavaDoc, Comparable JavaDoc {
19
20     private final SessionImplementor session;
21     private final Serializable JavaDoc id;
22     private final Object JavaDoc instance;
23     private final String JavaDoc entityName;
24
25     private transient EntityPersister persister;
26
27     protected EntityAction(SessionImplementor session, Serializable JavaDoc id, Object JavaDoc 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 JavaDoc ois) throws IOException JavaDoc, ClassNotFoundException JavaDoc {
36         ois.defaultReadObject();
37         persister = session.getFactory()
38                 .getEntityPersister( entityName );
39     }
40
41     public final Serializable JavaDoc[] getPropertySpaces() {
42         return persister.getPropertySpaces();
43     }
44
45     protected final SessionImplementor getSession() {
46         return session;
47     }
48
49     protected final Serializable JavaDoc getId() {
50         return id;
51     }
52
53     protected final EntityPersister getPersister() {
54         return persister;
55     }
56
57     protected final Object JavaDoc 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 JavaDoc toString() {
70         return StringHelper.unqualify( getClass().getName() ) + MessageHelper.infoString( entityName, id );
71     }
72
73     public int compareTo(Object JavaDoc other) {
74         EntityAction action = ( EntityAction ) other;
75         //sort first by entity name
76
int roleComparison = entityName.compareTo( action.entityName );
77         if ( roleComparison != 0 ) {
78             return roleComparison;
79         }
80         else {
81             //then by id
82
return persister.getIdentifierType()
83                 .compare( id, action.id, session.getEntityMode() );
84         }
85     }
86 }
87
88
89
90
91
92
93
Popular Tags