FileDocCategorySizeDatePackage
ProxyInterceptor.javaAPI DocHibernate 3.2.52141Tue Nov 29 07:38:48 GMT 2005org.hibernate.test.dynamicentity.interceptor

ProxyInterceptor

public class ProxyInterceptor extends org.hibernate.EmptyInterceptor
Our custom {@link org.hibernate.Interceptor} impl which performs the interpretation of entity-name -> proxy instance and vice-versa.
author
Steve Ebersole

Fields Summary
Constructors Summary
Methods Summary
public java.lang.StringgetEntityName(java.lang.Object object)
The callback from Hibernate to determine the entity name given a presumed entity instance.

param
object The presumed entity instance.
return
The entity name (pointing to the proper entity mapping).

		String entityName = ProxyHelper.extractEntityName( object );
		if ( entityName == null ) {
			entityName = super.getEntityName( object );
		}
		return entityName;
	
public java.lang.Objectinstantiate(java.lang.String entityName, org.hibernate.EntityMode entityMode, java.io.Serializable id)
The callback from Hibernate in order to build an instance of the entity represented by the given entity name. Here, we build a {@link Proxy} representing the entity.

param
entityName The entity name for which to create an instance. In our setup, this is the interface name.
param
entityMode The entity mode in which to create an instance. Here, we are only interestes in custom behavior for the POJO entity mode.
param
id The identifier value for the given entity.
return
The instantiated instance.

		if ( entityMode == EntityMode.POJO ) {
			if ( Customer.class.getName().equals( entityName ) ) {
				return ProxyHelper.newCustomerProxy( id );
			}
			else if ( Company.class.getName().equals( entityName ) ) {
				return ProxyHelper.newCompanyProxy( id );
			}
		}
		return super.instantiate( entityName, entityMode, id );