1 package org.hibernate.tuple; 3 4 import java.util.Map ; 5 6 import org.hibernate.EntityMode; 7 import org.hibernate.HibernateException; 8 import org.hibernate.mapping.PersistentClass; 9 import org.hibernate.mapping.Property; 10 import org.hibernate.property.Getter; 11 import org.hibernate.property.PropertyAccessor; 12 import org.hibernate.property.PropertyAccessorFactory; 13 import org.hibernate.property.Setter; 14 import org.hibernate.proxy.MapProxyFactory; 15 import org.hibernate.proxy.ProxyFactory; 16 import org.apache.commons.logging.Log; 17 import org.apache.commons.logging.LogFactory; 18 19 24 public class DynamicMapEntityTuplizer extends AbstractEntityTuplizer { 25 26 static final Log log = LogFactory.getLog( DynamicMapEntityTuplizer.class ); 27 28 DynamicMapEntityTuplizer(EntityMetamodel entityMetamodel, PersistentClass mappedEntity) { 29 super(entityMetamodel, mappedEntity); 30 } 31 32 public EntityMode getEntityMode() { 33 return EntityMode.MAP; 34 } 35 36 private PropertyAccessor buildPropertyAccessor(Property mappedProperty) { 37 if ( mappedProperty.isBackRef() ) { 38 return mappedProperty.getPropertyAccessor(null); 39 } 40 else { 41 return PropertyAccessorFactory.getDynamicMapPropertyAccessor(); 42 } 43 } 44 45 protected Getter buildPropertyGetter(Property mappedProperty, PersistentClass mappedEntity) { 46 return buildPropertyAccessor(mappedProperty).getGetter( null, mappedProperty.getName() ); 47 } 48 49 protected Setter buildPropertySetter(Property mappedProperty, PersistentClass mappedEntity) { 50 return buildPropertyAccessor(mappedProperty).getSetter( null, mappedProperty.getName() ); 51 } 52 53 protected Instantiator buildInstantiator(PersistentClass mappingInfo) { 54 return new DynamicMapInstantiator( mappingInfo ); 55 } 56 57 protected ProxyFactory buildProxyFactory(PersistentClass mappingInfo, Getter idGetter, Setter idSetter) { 58 59 ProxyFactory pf = new MapProxyFactory(); 60 try { 61 pf.postInstantiate( 63 getEntityName(), 64 null, 65 null, 66 null, 67 null, 68 null 69 ); 70 } 71 catch ( HibernateException he ) { 72 log.warn( "could not create proxy factory for:" + getEntityName(), he ); 73 pf = null; 74 } 75 return pf; 76 } 77 78 public Class getMappedClass() { 79 return Map .class; 80 } 81 82 public Class getConcreteProxyClass() { 83 return Map .class; 84 } 85 86 public boolean isInstrumented() { 87 return false; 88 } 89 } 90 | Popular Tags |