1 package org.hibernate.cache.entry; 3 4 import java.io.Serializable ; 5 6 import org.hibernate.AssertionFailure; 7 import org.hibernate.HibernateException; 8 import org.hibernate.Interceptor; 9 import org.hibernate.engine.SessionImplementor; 10 import org.hibernate.event.EventSource; 11 import org.hibernate.event.PreLoadEvent; 12 import org.hibernate.persister.entity.EntityPersister; 13 import org.hibernate.type.TypeFactory; 14 import org.hibernate.util.ArrayHelper; 15 16 21 public final class CacheEntry implements Serializable { 22 23 private final Serializable [] disassembledState; 24 private final String subclass; 25 private final boolean lazyPropertiesAreUnfetched; 26 27 public String getSubclass() { 28 return subclass; 29 } 30 31 public boolean areLazyPropertiesUnfetched() { 32 return lazyPropertiesAreUnfetched; 33 } 34 35 public CacheEntry( 36 final Object [] state, 37 final EntityPersister persister, 38 final boolean unfetched, 39 final SessionImplementor session, 40 final Object owner) 41 throws HibernateException { 42 this.disassembledState = TypeFactory.disassemble( 44 state, 45 persister.getPropertyTypes(), 46 session, 47 owner 48 ); 49 subclass = persister.getEntityName(); 50 lazyPropertiesAreUnfetched = unfetched; 51 } 52 53 CacheEntry(Serializable [] state, String subclass, boolean unfetched) { 54 this.disassembledState = state; 55 this.subclass = subclass; 56 this.lazyPropertiesAreUnfetched = unfetched; 57 } 58 59 public Object [] assemble( 60 final Object instance, 61 final Serializable id, 62 final EntityPersister persister, 63 final Interceptor interceptor, 64 final EventSource session) 65 throws HibernateException { 66 67 if ( !persister.getEntityName().equals(subclass) ) { 68 throw new AssertionFailure("Tried to assemble a different subclass instance"); 69 } 70 71 return assemble(disassembledState, instance, id, persister, interceptor, session); 72 73 } 74 75 private static Object [] assemble( 76 final Serializable [] values, 77 final Object result, 78 final Serializable id, 79 final EntityPersister persister, 80 final Interceptor interceptor, 81 final EventSource session) 82 throws HibernateException { 83 84 Object [] assembledProps = TypeFactory.assemble( 86 values, 87 persister.getPropertyTypes(), 88 session, result 89 ); 90 91 93 PreLoadEvent preLoadEvent = new PreLoadEvent( session ) 95 .setEntity(result) 96 .setState(assembledProps) 97 .setId(id) 98 .setPersister(persister); 99 100 session.getListeners() 101 .getPreLoadEventListener() 102 .onPreLoad(preLoadEvent); 103 104 persister.setPropertyValues( 105 result, 106 assembledProps, 107 session.getEntityMode() 108 ); 109 110 return assembledProps; 111 } 112 113 public Serializable [] getDisassembledState() { 114 return disassembledState; 118 } 119 120 public String toString() { 121 return "CacheEntry(" + subclass + ')' + 122 ArrayHelper.toString(disassembledState); 123 } 124 125 } 126 127 128 129 130 131 132 | Popular Tags |