org.hibernate.proxy.ProxyFactory Java Examples

The following examples show how to use org.hibernate.proxy.ProxyFactory. 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: DynamicMapEntityTuplizer.java    From lams with GNU General Public License v2.0 6 votes vote down vote up
@Override
protected ProxyFactory buildProxyFactory(PersistentClass mappingInfo, Getter idGetter, Setter idSetter) {

	ProxyFactory pf = new MapProxyFactory();
	try {
		//TODO: design new lifecycle for ProxyFactory
		pf.postInstantiate(
				getEntityName(),
				null,
				null,
				null,
				null,
				null
		);
	}
	catch (HibernateException he) {
		LOG.unableToCreateProxyFactory( getEntityName(), he );
		pf = null;
	}
	return pf;
}
 
Example #2
Source File: Dom4jEntityTuplizer.java    From cacheonix-core with GNU Lesser General Public License v2.1 6 votes vote down vote up
protected ProxyFactory buildProxyFactory(PersistentClass mappingInfo, Getter idGetter, Setter idSetter) {
	HashSet proxyInterfaces = new HashSet();
	proxyInterfaces.add( HibernateProxy.class );
	proxyInterfaces.add( Element.class );

	ProxyFactory pf = new Dom4jProxyFactory();
	try {
		pf.postInstantiate(
				getEntityName(),
				Element.class,
				proxyInterfaces,
				null,
				null,
				mappingInfo.hasEmbeddedIdentifier() ?
		                (AbstractComponentType) mappingInfo.getIdentifier().getType() :
		                null
		);
	}
	catch ( HibernateException he ) {
		log.warn( "could not create proxy factory for:" + getEntityName(), he );
		pf = null;
	}
	return pf;
}
 
Example #3
Source File: DynamicMapEntityTuplizer.java    From cacheonix-core with GNU Lesser General Public License v2.1 6 votes vote down vote up
protected ProxyFactory buildProxyFactory(PersistentClass mappingInfo, Getter idGetter, Setter idSetter) {

		ProxyFactory pf = new MapProxyFactory();
		try {
			//TODO: design new lifecycle for ProxyFactory
			pf.postInstantiate(
					getEntityName(),
					null,
					null,
					null,
					null,
					null
			);
		}
		catch ( HibernateException he ) {
			log.warn( "could not create proxy factory for:" + getEntityName(), he );
			pf = null;
		}
		return pf;
	}
 
Example #4
Source File: MyEntityTuplizer.java    From cacheonix-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
protected ProxyFactory buildProxyFactory(PersistentClass persistentClass, Getter idGetter, Setter idSetter) {
	// allows defining a custom proxy factory, which is responsible for
	// generating lazy proxies for a given entity.
	//
	// Here we simply use the default...
	return super.buildProxyFactory( persistentClass, idGetter, idSetter );
}
 
Example #5
Source File: ProxyFactoryFactoryImpl.java    From cacheonix-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
public BasicProxyFactoryImpl(Class superClass, Class[] interfaces) {
	if ( superClass == null && ( interfaces == null || interfaces.length < 1 ) ) {
		throw new AssertionFailure( "attempting to build proxy without any superclass or interfaces" );
	}
	javassist.util.proxy.ProxyFactory factory = new javassist.util.proxy.ProxyFactory();
	factory.setFilter( FINALIZE_FILTER );
	if ( superClass != null ) {
		factory.setSuperclass( superClass );
	}
	if ( interfaces != null && interfaces.length > 0 ) {
		factory.setInterfaces( interfaces );
	}
	proxyClass = factory.createClass();
}
 
Example #6
Source File: PojoEntityTuplizer.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
protected ProxyFactory buildProxyFactoryInternal(
			PersistentClass persistentClass,
			Getter idGetter,
			Setter idSetter) {
		// TODO : YUCK!!!  fix after HHH-1907 is complete
		return Environment.getBytecodeProvider().getProxyFactoryFactory().buildProxyFactory( getFactory() );
//		return getFactory().getSettings().getBytecodeProvider().getProxyFactoryFactory().buildProxyFactory();
	}
 
Example #7
Source File: JavassistProxyFactory.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
public static javassist.util.proxy.ProxyFactory buildJavassistProxyFactory(
		final Class persistentClass,
		final Class[] interfaces) {
	javassist.util.proxy.ProxyFactory factory = new javassist.util.proxy.ProxyFactory() {
		@Override
		protected ClassLoader getClassLoader() {
			return persistentClass.getClassLoader();
		}
	};
	factory.setSuperclass( interfaces.length == 1 ? persistentClass : null );
	factory.setInterfaces( interfaces );
	factory.setFilter( EXCLUDE_FILTER );
	return factory;
}
 
Example #8
Source File: ProxyFactoryFactoryImpl.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
public BasicProxyFactoryImpl(Class superClass, Class[] interfaces) {
	if ( superClass == null && ( interfaces == null || interfaces.length < 1 ) ) {
		throw new AssertionFailure( "attempting to build proxy without any superclass or interfaces" );
	}

	final javassist.util.proxy.ProxyFactory factory = new javassist.util.proxy.ProxyFactory();
	factory.setFilter( FINALIZE_FILTER );
	if ( superClass != null ) {
		factory.setSuperclass( superClass );
	}
	if ( interfaces != null && interfaces.length > 0 ) {
		factory.setInterfaces( interfaces );
	}
	proxyClass = factory.createClass();
}
 
Example #9
Source File: ProxyFactoryFactoryImpl.java    From lams with GNU General Public License v2.0 4 votes vote down vote up
@Override
public ProxyFactory buildProxyFactory(SessionFactoryImplementor sessionFactory) {
	return new ByteBuddyProxyFactory( byteBuddyProxyHelper );
}
 
Example #10
Source File: PojoEntityTuplizer.java    From cacheonix-core with GNU Lesser General Public License v2.1 4 votes vote down vote up
protected ProxyFactory buildProxyFactoryInternal(PersistentClass persistentClass, Getter idGetter, Setter idSetter) {
		// TODO : YUCK!!!  finx after HHH-1907 is complete
		return Environment.getBytecodeProvider().getProxyFactoryFactory().buildProxyFactory();
//		return getFactory().getSettings().getBytecodeProvider().getProxyFactoryFactory().buildProxyFactory();
	}
 
Example #11
Source File: PojoEntityTuplizer.java    From cacheonix-core with GNU Lesser General Public License v2.1 4 votes vote down vote up
protected ProxyFactory buildProxyFactory(PersistentClass persistentClass, Getter idGetter, Setter idSetter) {
	// determine the id getter and setter methods from the proxy interface (if any)
       // determine all interfaces needed by the resulting proxy
	HashSet proxyInterfaces = new HashSet();
	proxyInterfaces.add( HibernateProxy.class );
	
	Class mappedClass = persistentClass.getMappedClass();
	Class proxyInterface = persistentClass.getProxyInterface();

	if ( proxyInterface!=null && !mappedClass.equals( proxyInterface ) ) {
		if ( !proxyInterface.isInterface() ) {
			throw new MappingException(
			        "proxy must be either an interface, or the class itself: " + 
			        getEntityName()
				);
		}
		proxyInterfaces.add( proxyInterface );
	}

	if ( mappedClass.isInterface() ) {
		proxyInterfaces.add( mappedClass );
	}

	Iterator iter = persistentClass.getSubclassIterator();
	while ( iter.hasNext() ) {
		Subclass subclass = ( Subclass ) iter.next();
		Class subclassProxy = subclass.getProxyInterface();
		Class subclassClass = subclass.getMappedClass();
		if ( subclassProxy!=null && !subclassClass.equals( subclassProxy ) ) {
			if ( !proxyInterface.isInterface() ) {
				throw new MappingException(
				        "proxy must be either an interface, or the class itself: " + 
				        subclass.getEntityName()
				);
			}
			proxyInterfaces.add( subclassProxy );
		}
	}

	Iterator properties = persistentClass.getPropertyIterator();
	Class clazz = persistentClass.getMappedClass();
	while ( properties.hasNext() ) {
		Property property = (Property) properties.next();
		Method method = property.getGetter(clazz).getMethod();
		if ( method != null && Modifier.isFinal( method.getModifiers() ) ) {
			log.error(
					"Getters of lazy classes cannot be final: " + persistentClass.getEntityName() + 
					"." + property.getName() 
				);
		}
		method = property.getSetter(clazz).getMethod();
           if ( method != null && Modifier.isFinal( method.getModifiers() ) ) {
			log.error(
					"Setters of lazy classes cannot be final: " + persistentClass.getEntityName() + 
					"." + property.getName() 
				);
		}
	}

	Method idGetterMethod = idGetter==null ? null : idGetter.getMethod();
	Method idSetterMethod = idSetter==null ? null : idSetter.getMethod();

	Method proxyGetIdentifierMethod = idGetterMethod==null || proxyInterface==null ? 
			null :
	        ReflectHelper.getMethod(proxyInterface, idGetterMethod);
	Method proxySetIdentifierMethod = idSetterMethod==null || proxyInterface==null  ? 
			null :
	        ReflectHelper.getMethod(proxyInterface, idSetterMethod);

	ProxyFactory pf = buildProxyFactoryInternal( persistentClass, idGetter, idSetter );
	try {
		pf.postInstantiate(
				getEntityName(),
				mappedClass,
				proxyInterfaces,
				proxyGetIdentifierMethod,
				proxySetIdentifierMethod,
				persistentClass.hasEmbeddedIdentifier() ?
		                (AbstractComponentType) persistentClass.getIdentifier().getType() :
		                null
		);
	}
	catch ( HibernateException he ) {
		log.warn( "could not create proxy factory for:" + getEntityName(), he );
		pf = null;
	}
	return pf;
}
 
Example #12
Source File: AbstractEntityTuplizer.java    From cacheonix-core with GNU Lesser General Public License v2.1 4 votes vote down vote up
protected final ProxyFactory getProxyFactory() {
	return proxyFactory;
}
 
Example #13
Source File: QuarkusRuntimeProxyFactoryFactory.java    From quarkus with Apache License 2.0 4 votes vote down vote up
@Override
public ProxyFactory buildProxyFactory(SessionFactoryImplementor sessionFactory) {
    return new QuarkusProxyFactory(proxyClassDefinitions);
}
 
Example #14
Source File: JavassistProxyFactory.java    From lams with GNU General Public License v2.0 4 votes vote down vote up
private javassist.util.proxy.ProxyFactory buildJavassistProxyFactory() {
	return buildJavassistProxyFactory(
			persistentClass,
			interfaces
	);
}
 
Example #15
Source File: PojoEntityTuplizer.java    From lams with GNU General Public License v2.0 4 votes vote down vote up
@Override
protected ProxyFactory buildProxyFactory(PersistentClass persistentClass, Getter idGetter, Setter idSetter) {
	// determine the id getter and setter methods from the proxy interface (if any)
	// determine all interfaces needed by the resulting proxy
	
	/*
	 * We need to preserve the order of the interfaces they were put into the set, since javassist will choose the
	 * first one's class-loader to construct the proxy class with. This is also the reason why HibernateProxy.class
	 * should be the last one in the order (on JBossAS7 its class-loader will be org.hibernate module's class-
	 * loader, which will not see the classes inside deployed apps.  See HHH-3078
	 */
	Set<Class> proxyInterfaces = new java.util.LinkedHashSet<Class>();

	Class mappedClass = persistentClass.getMappedClass();
	Class proxyInterface = persistentClass.getProxyInterface();

	if ( proxyInterface != null && !mappedClass.equals( proxyInterface ) ) {
		if ( !proxyInterface.isInterface() ) {
			throw new MappingException(
					"proxy must be either an interface, or the class itself: " + getEntityName()
			);
		}
		proxyInterfaces.add( proxyInterface );
	}

	if ( mappedClass.isInterface() ) {
		proxyInterfaces.add( mappedClass );
	}

	Iterator<Subclass> subclasses = persistentClass.getSubclassIterator();
	while ( subclasses.hasNext() ) {
		final Subclass subclass = subclasses.next();
		final Class subclassProxy = subclass.getProxyInterface();
		final Class subclassClass = subclass.getMappedClass();
		if ( subclassProxy != null && !subclassClass.equals( subclassProxy ) ) {
			if ( !subclassProxy.isInterface() ) {
				throw new MappingException(
						"proxy must be either an interface, or the class itself: " + subclass.getEntityName()
				);
			}
			proxyInterfaces.add( subclassProxy );
		}
	}

	proxyInterfaces.add( HibernateProxy.class );

	Iterator properties = persistentClass.getPropertyIterator();
	Class clazz = persistentClass.getMappedClass();
	while ( properties.hasNext() ) {
		Property property = (Property) properties.next();
		Method method = property.getGetter( clazz ).getMethod();
		if ( method != null && Modifier.isFinal( method.getModifiers() ) ) {
			LOG.gettersOfLazyClassesCannotBeFinal( persistentClass.getEntityName(), property.getName() );
		}
		method = property.getSetter( clazz ).getMethod();
		if ( method != null && Modifier.isFinal( method.getModifiers() ) ) {
			LOG.settersOfLazyClassesCannotBeFinal( persistentClass.getEntityName(), property.getName() );
		}
	}

	Method idGetterMethod = idGetter == null ? null : idGetter.getMethod();
	Method idSetterMethod = idSetter == null ? null : idSetter.getMethod();

	Method proxyGetIdentifierMethod = idGetterMethod == null || proxyInterface == null ?
			null :
			ReflectHelper.getMethod( proxyInterface, idGetterMethod );
	Method proxySetIdentifierMethod = idSetterMethod == null || proxyInterface == null ?
			null :
			ReflectHelper.getMethod( proxyInterface, idSetterMethod );

	ProxyFactory pf = buildProxyFactoryInternal( persistentClass, idGetter, idSetter );
	try {
		pf.postInstantiate(
				getEntityName(),
				mappedClass,
				proxyInterfaces,
				proxyGetIdentifierMethod,
				proxySetIdentifierMethod,
				persistentClass.hasEmbeddedIdentifier() ?
						(CompositeType) persistentClass.getIdentifier().getType() :
						null
		);
	}
	catch (HibernateException he) {
		LOG.unableToCreateProxyFactory( getEntityName(), he );
		pf = null;
	}
	return pf;
}
 
Example #16
Source File: AbstractEntityTuplizer.java    From lams with GNU General Public License v2.0 4 votes vote down vote up
protected final ProxyFactory getProxyFactory() {
	return proxyFactory;
}
 
Example #17
Source File: AbstractEntityTuplizer.java    From cacheonix-core with GNU Lesser General Public License v2.1 2 votes vote down vote up
/**
 * Build an appropriate ProxyFactory for the given mapped entity.
 *
 * @param mappingInfo The mapping information regarding the mapped entity.
 * @param idGetter The constructed Getter relating to the entity's id property.
 * @param idSetter The constructed Setter relating to the entity's id property.
 * @return An appropriate ProxyFactory instance.
 */
protected abstract ProxyFactory buildProxyFactory(PersistentClass mappingInfo, Getter idGetter, Setter idSetter);
 
Example #18
Source File: ProxyFactoryFactoryImpl.java    From lams with GNU General Public License v2.0 2 votes vote down vote up
/**
 * Builds a Javassist-based proxy factory.
 *
 * @return a new Javassist-based proxy factory.
 */
@Override
public ProxyFactory buildProxyFactory(SessionFactoryImplementor sessionFactory) {
	return new JavassistProxyFactory();
}
 
Example #19
Source File: ProxyFactoryFactory.java    From lams with GNU General Public License v2.0 2 votes vote down vote up
/**
 * Build a proxy factory specifically for handling runtime
 * lazy loading.
 *
 * @return The lazy-load proxy factory.
 */
public ProxyFactory buildProxyFactory(SessionFactoryImplementor sessionFactory);
 
Example #20
Source File: ProxyFactoryFactoryImpl.java    From cacheonix-core with GNU Lesser General Public License v2.1 2 votes vote down vote up
/**
 * Builds a Javassist-based proxy factory.
 *
 * @return a new Javassist-based proxy factory.
 */
public ProxyFactory buildProxyFactory() {
	return new JavassistProxyFactory();
}
 
Example #21
Source File: ProxyFactoryFactoryImpl.java    From cacheonix-core with GNU Lesser General Public License v2.1 2 votes vote down vote up
/**
 * Builds a CGLIB-based proxy factory.
 *
 * @return a new CGLIB-based proxy factory.
 */
public ProxyFactory buildProxyFactory() {
	return new CGLIBProxyFactory();
}
 
Example #22
Source File: ProxyFactoryFactory.java    From cacheonix-core with GNU Lesser General Public License v2.1 2 votes vote down vote up
/**
 * Build a proxy factory specifically for handling runtime
 * lazy loading.
 *
 * @return The lazy-load proxy factory.
 */
public ProxyFactory buildProxyFactory();
 
Example #23
Source File: AbstractEntityTuplizer.java    From lams with GNU General Public License v2.0 2 votes vote down vote up
/**
 * Build an appropriate ProxyFactory for the given mapped entity.
 *
 * @param mappingInfo The mapping information regarding the mapped entity.
 * @param idGetter The constructed Getter relating to the entity's id property.
 * @param idSetter The constructed Setter relating to the entity's id property.
 *
 * @return An appropriate ProxyFactory instance.
 */
protected abstract ProxyFactory buildProxyFactory(PersistentClass mappingInfo, Getter idGetter, Setter idSetter);