1 package org.hibernate.cache.entry; 3 4 import java.io.Serializable ; 5 import java.util.HashMap ; 6 import java.util.Iterator ; 7 import java.util.Map ; 8 9 import org.hibernate.engine.SessionFactoryImplementor; 10 11 14 public class StructuredMapCacheEntry implements CacheEntryStructure { 15 16 public Object structure(Object item) { 17 CollectionCacheEntry entry = (CollectionCacheEntry) item; 18 Serializable [] state = entry.getState(); 19 Map map = new HashMap (state.length); 20 for ( int i=0; i<state.length; ) { 21 map.put( state[i++], state[i++] ); 22 } 23 return map; 24 } 25 26 public Object destructure(Object item, SessionFactoryImplementor factory) { 27 Map map = (Map ) item; 28 Serializable [] state = new Serializable [ map.size()*2 ]; 29 int i=0; 30 Iterator iter = map.entrySet().iterator(); 31 while ( iter.hasNext() ) { 32 Map.Entry me = (Map.Entry ) iter.next(); 33 state[i++] = (Serializable ) me.getKey(); 34 state[i++] = (Serializable ) me.getValue(); 35 } 36 return new CollectionCacheEntry(state); 37 } 38 39 } 40 | Popular Tags |