Java Code Examples for org.hibernate.persister.entity.EntityPersister#hasProxy()

The following examples show how to use org.hibernate.persister.entity.EntityPersister#hasProxy() . 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: JoinWalker.java    From lams with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Does the mapping, and Hibernate default semantics, specify that
 * this association should be fetched by outer joining
 */
protected boolean isJoinedFetchEnabledInMapping(FetchMode config, AssociationType type)
		throws MappingException {
	if ( !type.isEntityType() && !type.isCollectionType() ) {
		return false;
	}
	else {
		if ( config == FetchMode.JOIN ) {
			return true;
		}
		if ( config == FetchMode.SELECT ) {
			return false;
		}
		if ( type.isEntityType() ) {
			//TODO: look at the owning property and check that it 
			//      isn't lazy (by instrumentation)
			EntityType entityType = (EntityType) type;
			EntityPersister persister = getFactory().getEntityPersister( entityType.getAssociatedEntityName() );
			return !persister.hasProxy();
		}
		else {
			return false;
		}
	}
}
 
Example 2
Source File: StatelessSessionImpl.java    From lams with GNU General Public License v2.0 6 votes vote down vote up
@Override
public Object internalLoad(
		String entityName,
		Serializable id,
		boolean eager,
		boolean nullable) throws HibernateException {
	checkOpen();
	EntityPersister persister = getFactory().getMetamodel().entityPersister( entityName );
	// first, try to load it from the temp PC associated to this SS
	Object loaded = temporaryPersistenceContext.getEntity( generateEntityKey( id, persister ) );
	if ( loaded != null ) {
		// we found it in the temp PC.  Should indicate we are in the midst of processing a result set
		// containing eager fetches via join fetch
		return loaded;
	}
	if ( !eager && persister.hasProxy() ) {
		// if the metadata allowed proxy creation and caller did not request forceful eager loading,
		// generate a proxy
		return persister.createProxy( id, this );
	}
	// otherwise immediately materialize it
	return get( entityName, id );
}
 
Example 3
Source File: JoinWalker.java    From cacheonix-core with GNU Lesser General Public License v2.1 6 votes vote down vote up
/**
 * Does the mapping, and Hibernate default semantics, specify that
 * this association should be fetched by outer joining
 */
protected boolean isJoinedFetchEnabledInMapping(FetchMode config, AssociationType type) 
throws MappingException {
	if ( !type.isEntityType() && !type.isCollectionType() ) {
		return false;
	}
	else {
		if (config==FetchMode.JOIN) return true;
		if (config==FetchMode.SELECT) return false;
		if ( type.isEntityType() ) {
			//TODO: look at the owning property and check that it 
			//      isn't lazy (by instrumentation)
			EntityType entityType =(EntityType) type;
			EntityPersister persister = getFactory().getEntityPersister( entityType.getAssociatedEntityName() );
			return !persister.hasProxy();
		}
		else {
			return false;
		}
	}
}
 
Example 4
Source File: StatefulPersistenceContext.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
@Override
public Object proxyFor(EntityPersister persister, EntityKey key, Object impl) throws HibernateException {
	if ( !persister.hasProxy() ) {
		return impl;
	}
	final Object proxy = proxiesByKey.get( key );
	return ( proxy != null ) ? narrowProxy( proxy, persister, key, impl ) : impl;
}
 
Example 5
Source File: DefaultLoadEventListener.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Based on configured options, will either return a pre-existing proxy,
 * generate a new proxy, or perform an actual load.
 *
 * @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
 *
 * @return The result of the proxy/load operation.
 */
private Object proxyOrLoad(
		final LoadEvent event,
		final EntityPersister persister,
		final EntityKey keyToLoad,
		final LoadEventListener.LoadType options) {

	if ( traceEnabled ) {
		LOG.tracev(
				"Loading entity: {0}",
				MessageHelper.infoString( persister, event.getEntityId(), event.getSession().getFactory() )
		);
	}

	// this class has no proxies (so do a shortcut)
	if ( !persister.hasProxy() ) {
		return load( event, persister, keyToLoad, options );
	}

	final PersistenceContext persistenceContext = event.getSession().getPersistenceContext();

	// look for a proxy
	Object proxy = persistenceContext.getProxy( keyToLoad );
	if ( proxy != null ) {
		return returnNarrowedProxy( event, persister, keyToLoad, options, persistenceContext, proxy );
	}

	if ( options.isAllowProxyCreation() ) {
		return createProxyIfNecessary( event, persister, keyToLoad, options, persistenceContext );
	}

	// return a newly loaded object
	return load( event, persister, keyToLoad, options );
}
 
Example 6
Source File: StatefulPersistenceContext.java    From cacheonix-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
/**
 * Return the existing proxy associated with the given <tt>EntityKey</tt>, or the
 * third argument (the entity associated with the key) if no proxy exists. Init
 * the proxy to the target implementation, if necessary.
 */
public Object proxyFor(EntityPersister persister, EntityKey key, Object impl) 
throws HibernateException {
	if ( !persister.hasProxy() ) return impl;
	Object proxy = proxiesByKey.get(key);
	if ( proxy != null ) {
		return narrowProxy(proxy, persister, key, impl);
	}
	else {
		return impl;
	}
}
 
Example 7
Source File: DefaultLoadEventListener.java    From cacheonix-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
/** 
 * Based on configured options, will either return a pre-existing proxy,
 * generate a new proxy, or perform an actual load.
 *
 * @return The result of the proxy/load operation.
 * @throws HibernateException
 */
protected Object proxyOrLoad(
	final LoadEvent event, 
	final EntityPersister persister,
	final EntityKey keyToLoad, 
	final LoadEventListener.LoadType options) 
throws HibernateException {
	
	if ( log.isTraceEnabled() ) {
		log.trace(
				"loading entity: " + 
				MessageHelper.infoString( persister, event.getEntityId(), event.getSession().getFactory() )
			);
	}

	if ( !persister.hasProxy() ) {
		// this class has no proxies (so do a shortcut)
		return load(event, persister, keyToLoad, options);
	}
	else {
		final PersistenceContext persistenceContext = event.getSession().getPersistenceContext();

		// look for a proxy
		Object proxy = persistenceContext.getProxy(keyToLoad);
		if ( proxy != null ) {
			return returnNarrowedProxy( event, persister, keyToLoad, options, persistenceContext, proxy );
		}
		else {
			if ( options.isAllowProxyCreation() ) {
				return createProxyIfNecessary( event, persister, keyToLoad, options, persistenceContext );
			}
			else {
				// return a newly loaded object
				return load(event, persister, keyToLoad, options);
			}
		}
		
	}
}
 
Example 8
Source File: StatelessSessionImpl.java    From cacheonix-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
public Object internalLoad(
		String entityName,
        Serializable id,
        boolean eager,
        boolean nullable) throws HibernateException {
	errorIfClosed();
	EntityPersister persister = getFactory().getEntityPersister(entityName);
	if ( !eager && persister.hasProxy() ) {
		return persister.createProxy(id, this);
	}
	Object loaded = temporaryPersistenceContext.getEntity( new EntityKey(id, persister, EntityMode.POJO) );
	//TODO: if not loaded, throw an exception
	return loaded==null ? get( entityName, id ) : loaded;
}