1 16 package org.directwebremoting.hibernate; 17 18 import java.beans.PropertyDescriptor ; 19 20 import javax.servlet.ServletContext ; 21 22 import org.directwebremoting.WebContextFactory; 23 import org.directwebremoting.extend.MarshallException; 24 import org.directwebremoting.extend.Property; 25 import org.directwebremoting.impl.PropertyDescriptorProperty; 26 import org.hibernate.Hibernate; 27 import org.hibernate.Session; 28 import org.hibernate.engine.SessionImplementor; 29 import org.hibernate.proxy.HibernateProxy; 30 import org.hibernate.proxy.LazyInitializer; 31 32 38 public class H3PropertyDescriptorProperty extends PropertyDescriptorProperty 39 { 40 44 public H3PropertyDescriptorProperty(PropertyDescriptor descriptor) 45 { 46 super(descriptor); 47 } 48 49 52 public Object getValue(Object bean) throws MarshallException 53 { 54 if (!(bean instanceof HibernateProxy)) 55 { 56 return super.getValue(bean); 58 } 59 else 60 { 61 boolean initialized = Hibernate.isPropertyInitialized(bean, descriptor.getName()); 63 if (initialized) 64 { 65 Object reply = super.getValue(bean); 67 initialized = Hibernate.isInitialized(reply); 68 } 69 70 if (initialized) 71 { 72 return super.getValue(bean); 73 } 74 else 75 { 76 HibernateProxy proxy = (HibernateProxy) bean; 78 LazyInitializer initializer = proxy.getHibernateLazyInitializer(); 79 SessionImplementor implementor = initializer.getSession(); 80 if (implementor.isOpen()) 81 { 82 return super.getValue(bean); 83 } 84 85 ServletContext context = WebContextFactory.get().getServletContext(); 88 Session session = H3SessionAjaxFilter.getCurrentSession(context); 89 90 if (session != null) 91 { 92 session.update(bean); 93 return super.getValue(bean); 94 } 95 96 return null; 97 } 98 } 99 } 100 } 101 | Popular Tags |