KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > hibernate > cache > entry > StructuredCacheEntry


1 //$Id: StructuredCacheEntry.java,v 1.1 2005/02/13 12:46:58 oneovthafew Exp $
2
package org.hibernate.cache.entry;
3
4 import java.io.Serializable JavaDoc;
5 import java.util.HashMap JavaDoc;
6 import java.util.Map JavaDoc;
7
8 import org.hibernate.engine.SessionFactoryImplementor;
9 import org.hibernate.persister.entity.EntityPersister;
10
11 /**
12  * @author Gavin King
13  */

14 public class StructuredCacheEntry implements CacheEntryStructure {
15
16     private EntityPersister persister;
17
18     public StructuredCacheEntry(EntityPersister persister) {
19         this.persister = persister;
20     }
21     
22     public Object JavaDoc destructure(Object JavaDoc item, SessionFactoryImplementor factory) {
23         Map JavaDoc map = (Map JavaDoc) item;
24         boolean lazyPropertiesUnfetched = ( (Boolean JavaDoc) map.get("_lazyPropertiesUnfetched") ).booleanValue();
25         String JavaDoc subclass = (String JavaDoc) map.get("_subclass");
26         EntityPersister subclassPersister = factory.getEntityPersister(subclass);
27         String JavaDoc[] names = subclassPersister.getPropertyNames();
28         Serializable JavaDoc[] state = new Serializable JavaDoc[names.length];
29         for ( int i=0; i<names.length; i++ ) {
30             state[i] = (Serializable JavaDoc) map.get( names[i] );
31         }
32         return new CacheEntry(state, subclass, lazyPropertiesUnfetched);
33     }
34
35     public Object JavaDoc structure(Object JavaDoc item) {
36         CacheEntry entry = (CacheEntry) item;
37         String JavaDoc[] names = persister.getPropertyNames();
38         Map JavaDoc map = new HashMap JavaDoc(names.length+2);
39         map.put( "_subclass", entry.getSubclass() );
40         map.put( "_lazyPropertiesUnfetched", entry.areLazyPropertiesUnfetched() ? Boolean.TRUE : Boolean.FALSE );
41         for ( int i=0; i<names.length; i++ ) {
42             map.put( names[i], entry.getDisassembledState()[i] );
43         }
44         return map;
45     }
46 }
47
Popular Tags