1 package org.hibernate.cache.entry; 3 4 import java.io.Serializable ; 5 import java.util.HashMap ; 6 import java.util.Map ; 7 8 import org.hibernate.engine.SessionFactoryImplementor; 9 import org.hibernate.persister.entity.EntityPersister; 10 11 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 destructure(Object item, SessionFactoryImplementor factory) { 23 Map map = (Map ) item; 24 boolean lazyPropertiesUnfetched = ( (Boolean ) map.get("_lazyPropertiesUnfetched") ).booleanValue(); 25 String subclass = (String ) map.get("_subclass"); 26 EntityPersister subclassPersister = factory.getEntityPersister(subclass); 27 String [] names = subclassPersister.getPropertyNames(); 28 Serializable [] state = new Serializable [names.length]; 29 for ( int i=0; i<names.length; i++ ) { 30 state[i] = (Serializable ) map.get( names[i] ); 31 } 32 return new CacheEntry(state, subclass, lazyPropertiesUnfetched); 33 } 34 35 public Object structure(Object item) { 36 CacheEntry entry = (CacheEntry) item; 37 String [] names = persister.getPropertyNames(); 38 Map map = new HashMap (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 |