/** * Force initialization of a proxy or persistent collection. * <p/> * Note: This only ensures intialization of a proxy object or collection; * it is not guaranteed that the elements INSIDE the collection will be initialized/materialized. * * @param proxy a persistable object, proxy, persistent collection or <tt>null</tt> * @throws HibernateException if we can't initialize the proxy at this time, eg. the <tt>Session</tt> was closed */ public static void initialize(Object proxy) throws HibernateException { if ( proxy == null ) { return; } if ( proxy instanceof HibernateProxy ) { ( (HibernateProxy) proxy ).getHibernateLazyInitializer().initialize(); } else if ( proxy instanceof PersistentCollection ) { ( (PersistentCollection) proxy ).forceInitialization(); } }
@Override public void load() { if (this.value instanceof HibernateProxy) { ((HibernateProxy)this.value).getHibernateLazyInitializer().initialize(); } }
@Override public void load() { if (this.value instanceof HibernateProxy) { ((HibernateProxy)this.value).getHibernateLazyInitializer().initialize(); } }
@Override public void load() { if (this.value instanceof HibernateProxy) { ((HibernateProxy)this.value).getHibernateLazyInitializer().initialize(); } }
public void initialize(Object obj) { if (obj != null && isProxy(obj.getClass())) { getInitializer(obj).initialize(); } }
/** * Force initialization of a proxy or persistent collection. * <p/> * Note: This only ensures intialization of a proxy object or collection; * it is not guaranteed that the elements INSIDE the collection will be initialized/materialized. * * @param proxy a persistable object, proxy, persistent collection or <tt>null</tt> * @throws HibernateException if we can't initialize the proxy at this time, eg. the <tt>Session</tt> was closed */ public static void initialize(Object proxy) throws HibernateException { if ( proxy == null ) { return; } if ( proxy instanceof HibernateProxy ) { ( (HibernateProxy) proxy ).getHibernateLazyInitializer().initialize(); } else if ( proxy instanceof PersistentCollection ) { ( (PersistentCollection) proxy ).forceInitialization(); } }
/** * Force initialization of a proxy or persistent collection. * <p/> * Note: This only ensures intialization of a proxy object or collection; * it is not guaranteed that the elements INSIDE the collection will be initialized/materialized. * * @param proxy a persistable object, proxy, persistent collection or <tt>null</tt> * @throws HibernateException if we can't initialize the proxy at this time, eg. the <tt>Session</tt> was closed */ public static void initialize(Object proxy) throws HibernateException { if ( proxy == null ) { return; } else if ( proxy instanceof HibernateProxy ) { ( ( HibernateProxy ) proxy ).getHibernateLazyInitializer().initialize(); } else if ( proxy instanceof PersistentCollection ) { ( (PersistentCollection) proxy ).forceInitialization(); } }
/** * Force initialization of a proxy or persistent collection. * <p/> * Note: This only ensures intialization of a proxy object or collection; * it is not guaranteed that the elements INSIDE the collection will be initialized/materialized. * * @param proxy a persistable object, proxy, persistent collection or <tt>null</tt> * @throws HibernateException if we can't initialize the proxy at this time, eg. the <tt>Session</tt> was closed */ public static void initialize(Object proxy) throws HibernateException { if ( proxy == null ) { return; } else if ( proxy instanceof HibernateProxy ) { ( ( HibernateProxy ) proxy ).getHibernateLazyInitializer().initialize(); } else if ( proxy instanceof PersistentCollection ) { ( (PersistentCollection) proxy ).forceInitialization(); } }
/** * Force initialization of a proxy or persistent collection. * <p/> * Note: This only ensures intialization of a proxy object or collection; * it is not guaranteed that the elements INSIDE the collection will be initialized/materialized. * * @param proxy a persistable object, proxy, persistent collection or <tt>null</tt> * @throws HibernateException if we can't initialize the proxy at this time, eg. the <tt>Session</tt> was closed */ public static void initialize(Object proxy) throws HibernateException { if ( proxy == null ) { return; } else if ( proxy instanceof HibernateProxy ) { ( ( HibernateProxy ) proxy ).getHibernateLazyInitializer().initialize(); } else if ( proxy instanceof PersistentCollection ) { ( ( PersistentCollection ) proxy ).forceInitialization(); } }
/** * Force initialization of a proxy or persistent collection. * <p/> * Note: This only ensures intialization of a proxy object or collection; * it is not guaranteed that the elements INSIDE the collection will be initialized/materialized. * * @param proxy a persistable object, proxy, persistent collection or <tt>null</tt> * @throws HibernateException if we can't initialize the proxy at this time, eg. the <tt>Session</tt> was closed */ public static void initialize(Object proxy) throws HibernateException { if ( proxy == null ) { return; } else if ( proxy instanceof HibernateProxy ) { ( ( HibernateProxy ) proxy ).getHibernateLazyInitializer().initialize(); } else if ( proxy instanceof PersistentCollection ) { ( ( PersistentCollection ) proxy ).forceInitialization(); } }
public Object unwrapProxy(final HibernateProxy proxy) { final LazyInitializer lazyInitializer = proxy.getHibernateLazyInitializer(); if (lazyInitializer.isUninitialized()) { lazyInitializer.initialize(); } final Object obj = lazyInitializer.getImplementation(); if (obj != null) { ensureCorrectGroovyMetaClass(obj, obj.getClass()); } return obj; }
public void initialize(Object o) { if (o instanceof HibernateProxy) { final LazyInitializer hibernateLazyInitializer = ((HibernateProxy)o).getHibernateLazyInitializer(); if (hibernateLazyInitializer.isUninitialized()) { hibernateLazyInitializer.initialize(); } } else { super.initialize(o); } }
public Object unwrapProxy(final HibernateProxy proxy) { final LazyInitializer lazyInitializer = proxy.getHibernateLazyInitializer(); if (lazyInitializer.isUninitialized()) { lazyInitializer.initialize(); } final Object obj = lazyInitializer.getImplementation(); if (obj != null) { GrailsHibernateUtil.ensureCorrectGroovyMetaClass(obj,obj.getClass()); } return obj; }
public void initialize(Object o) { if (o instanceof HibernateProxy) { final LazyInitializer hibernateLazyInitializer = ((HibernateProxy)o).getHibernateLazyInitializer(); if (hibernateLazyInitializer.isUninitialized()) { hibernateLazyInitializer.initialize(); } } else if (o instanceof AbstractPersistentCollection) { final AbstractPersistentCollection col = (AbstractPersistentCollection)o; if (!col.wasInitialized()) { col.forceInitialization(); } } }
@Test public void shouldRunHibernateLazyInitialization() throws Exception { LazyInitializer initializer = mock(LazyInitializer.class); SomeProxy proxy = new SomeProxy(initializer); proxy.name = "my name"; proxy.aField = "abc"; when(initializer.getPersistentClass()).thenReturn(Client.class); serialization.from(proxy).serialize(); assertThat(result(), is("{\"client\": {\"name\": \"my name\",\"aField\": \"abc\"}}")); verify(initializer).initialize(); }
public void initializeField(final Object parent, final Object field) { if (!Hibernate.isInitialized(field)) { // TODO push this functionality up into // OneTo(One|Many)Transaction.get...() which should // wrap a transaction around all method calls which could hit the // db. // This method may not be running within the scope of a transaction, // so // make sure one is active try { boolean started = startHibernateTransaction(); if (field instanceof PersistentCollection) { HibernateUtil.getCurrentSession().lock(parent, org.hibernate.LockMode.NONE); Hibernate.initialize(field); } else { final LazyInitializer lazy = ((HibernateProxy) field).getHibernateLazyInitializer(); lazy.setSession((SessionImplementor) HibernateUtil.getCurrentSession()); lazy.initialize(); } commitHibernateTransaction(started); LOG.debug("initializeField of type " + field.getClass() + " for parent " + parent); } catch (final RuntimeException e) { HibernateUtil.rollbackTransaction(); throw e; } } }
LazyInitializer initializer = ((HibernateProxy) value).getHibernateLazyInitializer(); if (initializer.isUninitialized()) { initializer.initialize(); return true;
@Override public void initialize() throws HibernateException { LazyInitializer rawLazyInitializer = this.lazyInitializer; Object oldTarget = rawLazyInitializer.isUninitialized() ? null : rawLazyInitializer.getImplementation(); rawLazyInitializer.initialize(); Object target = rawLazyInitializer.getImplementation(); if (oldTarget != target) { ScalarListener listener = this.new TargetScalarListener(); if (oldTarget != null) { ((ObjectModelProvider)oldTarget).objectModel().removeScalarListener(listener); } this.oldTarget = target; if (target != null) { ObjectModel targetOM = ((ObjectModelProvider)target).objectModel(); targetOM.removeScalarListener(listener); //remove the duplicated listener. targetOM.addScalarListener(listener); } } }
LazyInitializer lazy = ((HibernateProxy) field).getHibernateLazyInitializer(); lazy.setSession((SessionImplementor) session); lazy.initialize();