KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > hibernate > id > Assigned


1 //$Id: Assigned.java,v 1.6 2005/05/26 03:58:23 oneovthafew Exp $
2
package org.hibernate.id;
3
4 import java.io.Serializable JavaDoc;
5 import java.util.Properties JavaDoc;
6
7 import org.hibernate.HibernateException;
8 import org.hibernate.MappingException;
9 import org.hibernate.dialect.Dialect;
10 import org.hibernate.engine.SessionImplementor;
11 import org.hibernate.type.Type;
12
13 /**
14  * <b>assigned</b><br>
15  * <br>
16  * An <tt>IdentifierGenerator</tt> that returns the current identifier assigned
17  * to an instance.
18  *
19  * @author Gavin King
20  */

21
22 public class Assigned implements IdentifierGenerator, Configurable {
23     
24     private String JavaDoc entityName;
25
26     public Serializable JavaDoc generate(SessionImplementor session, Object JavaDoc obj) throws HibernateException {
27         
28         final Serializable JavaDoc id = session.getEntityPersister( entityName, obj )
29                 //TODO: cache the persister, this shows up in yourkit
30
.getIdentifier( obj, session.getEntityMode() );
31         
32         if (id==null) {
33             throw new IdentifierGenerationException(
34                 "ids for this class must be manually assigned before calling save(): " +
35                 entityName
36             );
37         }
38         
39         return id;
40     }
41
42     public void configure(Type type, Properties JavaDoc params, Dialect d)
43     throws MappingException {
44         entityName = params.getProperty(ENTITY_NAME);
45         if (entityName==null) {
46             throw new MappingException("no entity name");
47         }
48     }
49 }
50
51
52
53
54
55
56
Popular Tags