KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > hibernate > tuple > EntityTuplizer


1 //$Id: EntityTuplizer.java,v 1.8 2005/07/16 22:20:48 oneovthafew Exp $
2
package org.hibernate.tuple;
3
4 import java.io.Serializable JavaDoc;
5 import java.util.Map JavaDoc;
6
7 import org.hibernate.HibernateException;
8 import org.hibernate.engine.SessionImplementor;
9
10 /**
11  * Defines further responsibilities reagarding tuplization based on
12  * a mapped entity.
13  * <p/>
14  * EntityTuplizer implementations should have the following constructor signature:
15  * (org.hibernate.tuple.EntityMetamodel, org.hibernate.mapping.PersistentClass)
16  *
17  * @author Gavin King
18  */

19 public interface EntityTuplizer extends Tuplizer {
20
21     /**
22      * Create an entity instance initialized with the given identifier.
23      *
24      * @param id The identifier value for the entity to be instantiated.
25      * @return The instantiated entity.
26      * @throws HibernateException
27      */

28     public Object JavaDoc instantiate(Serializable JavaDoc id) throws HibernateException;
29
30     /**
31      * Extract the identifier value from the given entity.
32      *
33      * @param entity The entity from which to extract the identifier value.
34      * @return The identifier value.
35      * @throws HibernateException If the entity does not define an identifier property, or an
36      * error occurrs accessing its value.
37      */

38     public Serializable JavaDoc getIdentifier(Object JavaDoc entity) throws HibernateException;
39
40     /**
41      * Inject the identifier value into the given entity.
42      * </p>
43      * Has no effect if the entity does not define an identifier property
44      *
45      * @param entity The entity to inject with the identifier value.
46      * @param id The value to be injected as the identifier.
47      * @throws HibernateException
48      */

49     public void setIdentifier(Object JavaDoc entity, Serializable JavaDoc id) throws HibernateException;
50
51     /**
52      * Inject the given identifier and version into the entity, in order to
53      * "roll back" to their original values.
54      *
55      * @param currentId The identifier value to inject into the entity.
56      * @param currentVersion The version value to inject into the entity.
57      */

58     public void resetIdentifier(Object JavaDoc entity, Serializable JavaDoc currentId, Object JavaDoc currentVersion);
59
60     /**
61      * Extract the value of the version property from the given entity.
62      *
63      * @param entity The entity from which to extract the version value.
64      * @return The value of the version property, or null if not versioned.
65      * @throws HibernateException
66      */

67     public Object JavaDoc getVersion(Object JavaDoc entity) throws HibernateException;
68
69     /**
70      * Inject the value of a particular property.
71      *
72      * @param entity The entity into which to inject the value.
73      * @param i The property's index.
74      * @param value The property value to inject.
75      * @throws HibernateException
76      */

77     public void setPropertyValue(Object JavaDoc entity, int i, Object JavaDoc value) throws HibernateException;
78
79     /**
80      * Inject the value of a particular property.
81      *
82      * @param entity The entity into which to inject the value.
83      * @param propertyName The name of the property.
84      * @param value The property value to inject.
85      * @throws HibernateException
86      */

87     public void setPropertyValue(Object JavaDoc entity, String JavaDoc propertyName, Object JavaDoc value) throws HibernateException;
88
89     /**
90      * Extract the values of the insertable properties of the entity (including backrefs)
91      *
92      * @param entity The entity from which to extract.
93      * @param mergeMap a map of instances being merged to merged instances
94      * @param session The session in which the resuest is being made.
95      * @return The insertable property values.
96      * @throws HibernateException
97      */

98     public Object JavaDoc[] getPropertyValuesToInsert(Object JavaDoc entity, Map JavaDoc mergeMap, SessionImplementor session)
99     throws HibernateException;
100
101     /**
102      * Extract the value of a particular property from the given entity.
103      *
104      * @param entity The entity from which to extract the property value.
105      * @param propertyName The name of the property for which to extract the value.
106      * @return The current value of the given property on the given entity.
107      * @throws HibernateException
108      */

109     public Object JavaDoc getPropertyValue(Object JavaDoc entity, String JavaDoc propertyName) throws HibernateException;
110
111     /**
112      * Called just after the entities properties have been initialized.
113      *
114      * @param entity The entity being initialized.
115      * @param lazyPropertiesAreUnfetched Are defined lazy properties currently unfecthed
116      * @param session The session initializing this entity.
117      */

118     public void afterInitialize(Object JavaDoc entity, boolean lazyPropertiesAreUnfetched, SessionImplementor session);
119
120     /**
121      * Does this entity, for this mode, present a possibility for proxying?
122      *
123      * @return True if this tuplizer can generate proxies for this entity.
124      */

125     public boolean hasProxy();
126
127     /**
128      * Generates an appropriate proxy representation of this entity for this
129      * entity-mode.
130      *
131      * @param id The id of the instance for which to generate a proxy.
132      * @param session The session to which the proxy should be bound.
133      * @return The generate proxies.
134      * @throws HibernateException Indicates an error generating the proxy.
135      */

136     public Object JavaDoc createProxy(Serializable JavaDoc id, SessionImplementor session) throws HibernateException;
137
138     /**
139      * Does the {@link #getMappedClass() class} managed by this tuplizer implement
140      * the {@link org.hibernate.classic.Lifecycle} interface.
141      *
142      * @return True if the Lifecycle interface is implemented; false otherwise.
143      */

144     public boolean isLifecycleImplementor();
145
146     /**
147      * Does the {@link #getMappedClass() class} managed by this tuplizer implement
148      * the {@link org.hibernate.classic.Validatable} interface.
149      *
150      * @return True if the Validatable interface is implemented; false otherwise.
151      */

152     public boolean isValidatableImplementor();
153
154     // TODO: getConcreteProxyClass() is solely used (externally) to perform narrowProxy()
155
// would be great to fully encapsulate that narrowProxy() functionality within the
156
// Tuplizer, itself, with a Tuplizer.narrowProxy(..., PersistentContext) method
157
/**
158      * Returns the java class to which generated proxies will be typed.
159      *
160      * @return The java class to which generated proxies will be typed
161      */

162     public Class JavaDoc getConcreteProxyClass();
163     
164     /**
165      * Does the given entity instance have any currently uninitialized lazy properties?
166      *
167      * @param entity The entity to be check for uninitialized lazy properties.
168      * @return True if uninitialized lazy properties were found; false otherwise.
169      */

170     public boolean hasUninitializedLazyProperties(Object JavaDoc entity);
171     
172     /**
173      * Is it an instrumented POJO?
174      */

175     public boolean isInstrumented();
176 }
177
Popular Tags