Java Code Examples for org.hibernate.proxy.LazyInitializer#isUnwrap()

The following examples show how to use org.hibernate.proxy.LazyInitializer#isUnwrap() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: DefaultLoadEventListener.java    From cacheonix-core with GNU Lesser General Public License v2.1 6 votes vote down vote up
/**
 * Given that there is a pre-existing proxy.
 * Initialize it if necessary; narrow if necessary.
 */
private Object returnNarrowedProxy(
		final LoadEvent event, 
		final EntityPersister persister, 
		final EntityKey keyToLoad, 
		final LoadEventListener.LoadType options, 
		final PersistenceContext persistenceContext, 
		final Object proxy
) {
	log.trace("entity proxy found in session cache");
	LazyInitializer li = ( (HibernateProxy) proxy ).getHibernateLazyInitializer();
	if ( li.isUnwrap() ) {
		return li.getImplementation();
	}
	Object impl = null;
	if ( !options.isAllowProxyCreation() ) {
		impl = load( event, persister, keyToLoad, options );
		if ( impl == null ) {
			event.getSession().getFactory().getEntityNotFoundDelegate().handleEntityNotFound( persister.getEntityName(), keyToLoad.getIdentifier());
		}
	}
	return persistenceContext.narrowProxy( proxy, persister, keyToLoad, impl );
}
 
Example 2
Source File: DefaultReactiveLoadEventListener.java    From hibernate-reactive with GNU Lesser General Public License v2.1 5 votes vote down vote up
/**
 * Given a proxy, initialize it and/or narrow it provided either
 * is necessary.
 *
 * @param event The initiating load request event
 * @param persister The persister corresponding to the entity to be loaded
 * @param keyToLoad The key of the entity to be loaded
 * @param options The defined load options
 * @param persistenceContext The originating session
 * @param proxy The proxy to narrow
 *
 * @return The created/existing proxy
 */
private CompletionStage<Object> returnNarrowedProxy(
		final LoadEvent event,
		final EntityPersister persister,
		final EntityKey keyToLoad,
		final LoadEventListener.LoadType options,
		final PersistenceContext persistenceContext,
		final Object proxy) {
	if ( LOG.isTraceEnabled() ) {
		LOG.trace( "Entity proxy found in session cache" );
	}

	LazyInitializer li = ( (HibernateProxy) proxy ).getHibernateLazyInitializer();

	if ( li.isUnwrap() ) {
		return CompletionStages.completedFuture( li.getImplementation() );
	}

	CompletionStage<Object> implStage;
	if ( !options.isAllowProxyCreation() ) {
		implStage = load( event, persister, keyToLoad, options )
				.thenApply( optional -> {
					if ( optional == null ) {
						event.getSession()
								.getFactory()
								.getEntityNotFoundDelegate()
								.handleEntityNotFound( persister.getEntityName(), keyToLoad.getIdentifier() );
					}
					return optional;
				} );
	}
	else {
		implStage = CompletionStages.nullFuture();
	}

	return implStage.thenApply( impl -> persistenceContext.narrowProxy( proxy, persister, keyToLoad, impl ) );
}
 
Example 3
Source File: DefaultLoadEventListener.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Given a proxy, initialize it and/or narrow it provided either
 * is necessary.
 *
 * @param event The initiating load request event
 * @param persister The persister corresponding to the entity to be loaded
 * @param keyToLoad The key of the entity to be loaded
 * @param options The defined load options
 * @param persistenceContext The originating session
 * @param proxy The proxy to narrow
 *
 * @return The created/existing proxy
 */
private Object returnNarrowedProxy(
		final LoadEvent event,
		final EntityPersister persister,
		final EntityKey keyToLoad,
		final LoadEventListener.LoadType options,
		final PersistenceContext persistenceContext,
		final Object proxy) {
	if ( traceEnabled ) {
		LOG.trace( "Entity proxy found in session cache" );
	}
	LazyInitializer li = ( (HibernateProxy) proxy ).getHibernateLazyInitializer();
	if ( li.isUnwrap() ) {
		return li.getImplementation();
	}
	Object impl = null;
	if ( !options.isAllowProxyCreation() ) {
		impl = load( event, persister, keyToLoad, options );
		if ( impl == null ) {
			event.getSession()
					.getFactory()
					.getEntityNotFoundDelegate()
					.handleEntityNotFound( persister.getEntityName(), keyToLoad.getIdentifier() );
		}
	}
	return persistenceContext.narrowProxy( proxy, persister, keyToLoad, impl );
}
 
Example 4
Source File: FieldInterceptorImpl.java    From cacheonix-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
public Object readObject(Object target, String name, Object oldValue) {
	Object value = intercept( target, name, oldValue );
	if (value instanceof HibernateProxy) {
		LazyInitializer li = ( (HibernateProxy) value ).getHibernateLazyInitializer();
		if ( li.isUnwrap() ) {
			value = li.getImplementation();
		}
	}
	return value;
}
 
Example 5
Source File: FieldInterceptorImpl.java    From cacheonix-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
public Object readObject(Object target, String name, Object oldValue) {
	Object value = intercept( target, name, oldValue );
	if (value instanceof HibernateProxy) {
		LazyInitializer li = ( (HibernateProxy) value ).getHibernateLazyInitializer();
		if ( li.isUnwrap() ) {
			value = li.getImplementation();
		}
	}
	return value;
}