List of usage examples for org.hibernate Hibernate isPropertyInitialized
public static boolean isPropertyInitialized(Object proxy, String propertyName)
From source file:es.caib.seycon.ng.servei.DispatcherServiceImpl.java
@Override protected ObjectMapping handleCreate(ObjectMapping om) throws Exception { ObjectMappingEntity ome = getObjectMappingEntityDao().objectMappingToEntity(om); getObjectMappingEntityDao().create(ome); ome.getDispatcher().setTimeStamp(new Date()); if (Hibernate.isPropertyInitialized(ome.getDispatcher(), "objectMappings")) //$NON-NLS-1$ {/*from w ww.j a v a 2 s . co m*/ ome.getDispatcher().getObjectMappings().add(ome); } getDispatcherEntityDao().update(ome.getDispatcher()); updateServers(); return getObjectMappingEntityDao().toObjectMapping(ome); }
From source file:es.caib.seycon.ng.servei.DispatcherServiceImpl.java
@Override protected ObjectMapping handleUpdate(ObjectMapping om) throws Exception { ObjectMappingEntity ome = getObjectMappingEntityDao().objectMappingToEntity(om); getObjectMappingEntityDao().update(ome); ome.getDispatcher().setTimeStamp(new Date()); if (Hibernate.isPropertyInitialized(ome.getDispatcher(), "objectMappings")) //$NON-NLS-1$ {/*from www .ja v a 2s . co m*/ ome.getDispatcher().getObjectMappings().add(ome); } getDispatcherEntityDao().update(ome.getDispatcher()); updateServers(); return getObjectMappingEntityDao().toObjectMapping(ome); }
From source file:es.caib.seycon.ng.servei.DispatcherServiceImpl.java
@Override protected void handleDelete(ObjectMapping om) throws Exception { ObjectMappingEntity ome = getObjectMappingEntityDao().objectMappingToEntity(om); for (ObjectMappingPropertyEntity ompe : ome.getProperties()) { getObjectMappingPropertyEntityDao().remove(ompe); }/*from ww w.ja v a 2s .co m*/ for (AttributeMappingEntity ame : ome.getAttributeMappings()) { getAttributeMappingEntityDao().remove(ame); } DispatcherEntity de = ome.getDispatcher(); getObjectMappingEntityDao().remove(ome); de.setTimeStamp(new Date()); if (Hibernate.isPropertyInitialized(ome.getDispatcher(), "objectMappings")) //$NON-NLS-1$ { de.getObjectMappings().remove(ome); } getDispatcherEntityDao().update(de); updateServers(); }
From source file:es.caib.seycon.ng.servei.DispatcherServiceImpl.java
@Override protected ObjectMappingProperty handleCreate(ObjectMappingProperty omp) throws Exception { ObjectMappingPropertyEntity ome = getObjectMappingPropertyEntityDao().objectMappingPropertyToEntity(omp); getObjectMappingPropertyEntityDao().create(ome); ome.getObject().getDispatcher().setTimeStamp(new Date()); if (Hibernate.isPropertyInitialized(ome.getObject(), "properties")) //$NON-NLS-1$ {/*from ww w.j ava 2 s. c o m*/ ome.getObject().getProperties().add(ome); } getDispatcherEntityDao().update(ome.getObject().getDispatcher()); updateServers(); return getObjectMappingPropertyEntityDao().toObjectMappingProperty(ome); }
From source file:es.caib.seycon.ng.servei.DispatcherServiceImpl.java
@Override protected ObjectMappingProperty handleUpdate(ObjectMappingProperty omp) throws Exception { ObjectMappingPropertyEntity ome = getObjectMappingPropertyEntityDao().objectMappingPropertyToEntity(omp); getObjectMappingPropertyEntityDao().update(ome); ome.getObject().getDispatcher().setTimeStamp(new Date()); if (Hibernate.isPropertyInitialized(ome.getObject(), "properties")) //$NON-NLS-1$ {//from www.j a v a 2 s .com ome.getObject().getProperties().add(ome); } getDispatcherEntityDao().update(ome.getObject().getDispatcher()); updateServers(); return getObjectMappingPropertyEntityDao().toObjectMappingProperty(ome); }
From source file:es.caib.seycon.ng.servei.DispatcherServiceImpl.java
@Override protected void handleDelete(ObjectMappingProperty omp) throws Exception { ObjectMappingPropertyEntity ome = getObjectMappingPropertyEntityDao().objectMappingPropertyToEntity(omp); ome.getObject().getDispatcher().setTimeStamp(new Date()); getDispatcherEntityDao().update(ome.getObject().getDispatcher()); if (Hibernate.isPropertyInitialized(ome.getObject(), "properties")) //$NON-NLS-1$ {/* w w w . j ava 2 s. com*/ ome.getObject().getProperties().remove(ome); } getObjectMappingPropertyEntityDao().remove(ome); updateServers(); }
From source file:org.directwebremoting.hibernate.H3BeanConverter.java
License:Apache License
@Override public Map<String, Property> getPropertyMapFromObject(Object example, boolean readRequired, boolean writeRequired) throws ConversionException { Class<?> clazz = getClass(example); try {/*w ww. j a v a 2 s. c o m*/ BeanInfo info = Introspector.getBeanInfo(clazz); PropertyDescriptor[] descriptors = info.getPropertyDescriptors(); Map<String, Property> properties = new HashMap<String, Property>(); for (PropertyDescriptor descriptor : descriptors) { String name = descriptor.getName(); // We don't marshall getClass() if ("class".equals(name)) { continue; } // And this is something added by hibernate if ("hibernateLazyInitializer".equals(name)) { continue; } // Access rules mean we might not want to do this one if (!isAllowedByIncludeExcludeRules(name)) { continue; } if (readRequired && descriptor.getReadMethod() == null) { continue; } if (writeRequired && descriptor.getWriteMethod() == null) { continue; } if (!assumeSession) { // We don't marshall un-initialized properties for // Hibernate3 Method method = findGetter(example, name); if (method == null) { log.warn("Failed to find property: " + name); properties.put(name, new PlainProperty(name, null)); continue; } if (!Hibernate.isPropertyInitialized(example, name)) { properties.put(name, new PlainProperty(name, null)); continue; } // This might be a lazy-collection so we need to double check Object retval = method.invoke(example); if (!Hibernate.isInitialized(retval)) { properties.put(name, new PlainProperty(name, null)); continue; } } properties.put(name, new H3PropertyDescriptorProperty(descriptor)); } return properties; } catch (Exception ex) { throw new ConversionException(clazz, ex); } }
From source file:org.directwebremoting.hibernate.H3PropertyDescriptorProperty.java
License:Apache License
@Override public Object getValue(Object bean) throws ConversionException { if (!(bean instanceof HibernateProxy)) { // This is not a hibernate dynamic proxy, just use it return super.getValue(bean); } else {/*w w w.j a va2 s . co m*/ // If the property is already initialized, use it boolean initialized = Hibernate.isPropertyInitialized(bean, descriptor.getName()); if (initialized) { // This might be a lazy-collection so we need to double check Object reply = super.getValue(bean); initialized = Hibernate.isInitialized(reply); } if (initialized) { return super.getValue(bean); } else { // If the session bound to the property is live, use it HibernateProxy proxy = (HibernateProxy) bean; LazyInitializer initializer = proxy.getHibernateLazyInitializer(); SessionImplementor implementor = initializer.getSession(); if (implementor.isOpen()) { return super.getValue(bean); } // So the property needs database access, and the session is closed // We'll need to try get another session ServletContext context = WebContextFactory.get().getServletContext(); Session session = H3SessionAjaxFilter.getCurrentSession(context); if (session != null) { session.update(bean); return super.getValue(bean); } return null; } } }
From source file:org.directwebremoting.hibernate.H4BeanConverter.java
License:Apache License
@Override public Map<String, Property> getPropertyMapFromObject(Object example, boolean readRequired, boolean writeRequired) throws ConversionException { Class<?> clazz = getClass(example); try {/*from w w w . ja v a 2 s . c om*/ BeanInfo info = Introspector.getBeanInfo(clazz); PropertyDescriptor[] descriptors = info.getPropertyDescriptors(); Map<String, Property> properties = new HashMap<String, Property>(); for (PropertyDescriptor descriptor : descriptors) { String name = descriptor.getName(); // We don't marshall getClass() if ("class".equals(name)) { continue; } // And this is something added by hibernate if ("hibernateLazyInitializer".equals(name)) { continue; } // Access rules mean we might not want to do this one if (!isAllowedByIncludeExcludeRules(name)) { continue; } if (readRequired && descriptor.getReadMethod() == null) { continue; } if (writeRequired && descriptor.getWriteMethod() == null) { continue; } if (!assumeSession) { // We don't marshall un-initialized properties for // Hibernate3 Method method = findGetter(example, name); if (method == null) { log.warn("Failed to find property: " + name); properties.put(name, new PlainProperty(name, null)); continue; } if (!Hibernate.isPropertyInitialized(example, name)) { properties.put(name, new PlainProperty(name, null)); continue; } // This might be a lazy-collection so we need to double check Object retval = method.invoke(example); if (!Hibernate.isInitialized(retval)) { properties.put(name, new PlainProperty(name, null)); continue; } } properties.put(name, new H4PropertyDescriptorProperty(descriptor)); } return properties; } catch (Exception ex) { throw new ConversionException(clazz, ex); } }
From source file:org.directwebremoting.hibernate.H4PropertyDescriptorProperty.java
License:Apache License
@Override public Object getValue(Object bean) throws ConversionException { if (!(bean instanceof HibernateProxy)) { // This is not a hibernate dynamic proxy, just use it return super.getValue(bean); } else {/*ww w.j a va 2 s .c o m*/ // If the property is already initialized, use it boolean initialized = Hibernate.isPropertyInitialized(bean, descriptor.getName()); if (initialized) { // This might be a lazy-collection so we need to double check Object reply = super.getValue(bean); initialized = Hibernate.isInitialized(reply); } if (initialized) { return super.getValue(bean); } else { // If the session bound to the property is live, use it HibernateProxy proxy = (HibernateProxy) bean; LazyInitializer initializer = proxy.getHibernateLazyInitializer(); SessionImplementor implementor = initializer.getSession(); if (implementor.isOpen()) { return super.getValue(bean); } // So the property needs database access, and the session is closed // We'll need to try get another session ServletContext context = WebContextFactory.get().getServletContext(); Session session = H4SessionAjaxFilter.getCurrentSession(context); if (session != null) { session.update(bean); return super.getValue(bean); } return null; } } }