Java 类org.hibernate.proxy.pojo.BasicLazyInitializer 实例源码

项目:gorm-hibernate5    文件:JavassistEntityProxyUtils.java   
static Class<?> createProxyClass(Class<?> persistentClass, Class<?>[] interfaces) throws HibernateException {
    // note: interfaces is assumed to already contain HibernateProxy.class

    try {
        Set<Class<?>> allInterfaces = new HashSet<>();
        if(interfaces != null) {
            allInterfaces.addAll(Arrays.asList(interfaces));
        }
        allInterfaces.add(GroovyObject.class);
        allInterfaces.add(EntityProxy.class);
        ProxyFactory factory = createJavassistProxyFactory(persistentClass, allInterfaces.toArray(new Class<?>[allInterfaces.size()]));
        Class<?> proxyClass = factory.createClass();
        HibernateUtils.enhanceProxyClass(proxyClass);
        return proxyClass;
    }
    catch (Throwable t) {
        LogFactory.getLog(BasicLazyInitializer.class).error(
                "Javassist Enhancement failed: " + persistentClass.getName(), t);
        throw new HibernateException("Javassist Enhancement failed: " + persistentClass.getName(), t);
    }
}
项目:gorm-hibernate5    文件:GroovyAwareJavassistLazyInitializer.java   
private static Class<?> getProxyFactory(Class<?> persistentClass, Class<?>[] interfaces) throws HibernateException {
    // note: interfaces is assumed to already contain HibernateProxy.class

    try {
        Set<Class<?>> allInterfaces = new HashSet<Class<?>>();
        if(interfaces != null) {
            allInterfaces.addAll(Arrays.asList(interfaces));
        }
        allInterfaces.add(GroovyObject.class);
        allInterfaces.add(EntityProxy.class);
        ProxyFactory factory = createProxyFactory(persistentClass, allInterfaces.toArray(new Class<?>[allInterfaces.size()]));
        Class<?> proxyClass = factory.createClass();
        HibernateUtils.enhanceProxyClass(proxyClass);
        return proxyClass;
    }
    catch (Throwable t) {
        LogFactory.getLog(BasicLazyInitializer.class).error(
                "Javassist Enhancement failed: " + persistentClass.getName(), t);
        throw new HibernateException("Javassist Enhancement failed: " + persistentClass.getName(), t);
    }
}
项目:cacheonix-core    文件:JavassistLazyInitializer.java   
public static Class getProxyFactory(
        Class persistentClass,
        Class[] interfaces) throws HibernateException {
    // note: interfaces is assumed to already contain HibernateProxy.class

    try {
        ProxyFactory factory = new ProxyFactory();
        factory.setSuperclass( interfaces.length == 1 ? persistentClass : null );
        factory.setInterfaces( interfaces );
        factory.setFilter( FINALIZE_FILTER );
        return factory.createClass();
    }
    catch ( Throwable t ) {
        LogFactory.getLog( BasicLazyInitializer.class ).error(
                "Javassist Enhancement failed: "
                + persistentClass.getName(), t
        );
        throw new HibernateException(
                "Javassist Enhancement failed: "
                + persistentClass.getName(), t
        );
    }
}
项目:cacheonix-core    文件:CGLIBLazyInitializer.java   
static HibernateProxy getProxy(final String entityName, final Class persistentClass,
        final Class[] interfaces, final Method getIdentifierMethod,
        final Method setIdentifierMethod, AbstractComponentType componentIdType,
        final Serializable id, final SessionImplementor session) throws HibernateException {
    // note: interfaces is assumed to already contain HibernateProxy.class

    try {
        final CGLIBLazyInitializer instance = new CGLIBLazyInitializer(
                entityName,
                persistentClass,
                interfaces,
                id,
                getIdentifierMethod,
                setIdentifierMethod,
                componentIdType,
                session 
            );

        final HibernateProxy proxy;
        Class factory = getProxyFactory(persistentClass,  interfaces);
        proxy = getProxyInstance(factory, instance);
        instance.constructed = true;
        return proxy;
    }
    catch (Throwable t) {
        LogFactory.getLog( BasicLazyInitializer.class )
            .error( "CGLIB Enhancement failed: " + entityName, t );
        throw new HibernateException( "CGLIB Enhancement failed: " + entityName, t );
    }
}
项目:cacheonix-core    文件:JavassistLazyInitializer.java   
public static HibernateProxy getProxy(
        final String entityName,
        final Class persistentClass,
        final Class[] interfaces,
        final Method getIdentifierMethod,
        final Method setIdentifierMethod,
        AbstractComponentType componentIdType,
        final Serializable id,
        final SessionImplementor session) throws HibernateException {
    // note: interface is assumed to already contain HibernateProxy.class
    try {
        final JavassistLazyInitializer instance = new JavassistLazyInitializer(
                entityName,
                persistentClass,
                interfaces,
                id,
                getIdentifierMethod,
                setIdentifierMethod,
                componentIdType,
                session
        );
        ProxyFactory factory = new ProxyFactory();
        factory.setSuperclass( interfaces.length == 1 ? persistentClass : null );
        factory.setInterfaces( interfaces );
        factory.setFilter( FINALIZE_FILTER );
        Class cl = factory.createClass();
        final HibernateProxy proxy = ( HibernateProxy ) cl.newInstance();
        ( ( ProxyObject ) proxy ).setHandler( instance );
        instance.constructed = true;
        return proxy;
    }
    catch ( Throwable t ) {
        LogFactory.getLog( BasicLazyInitializer.class ).error(
                "Javassist Enhancement failed: " + entityName, t
        );
        throw new HibernateException(
                "Javassist Enhancement failed: "
                + entityName, t
        );
    }
}