Java 类org.hibernate.proxy.pojo.javassist.JavassistLazyInitializer 实例源码

项目:jbromo    文件:JpaHibernateProvider.java   
@Override
public Class<?> getPersistentClass(final Object object) {
    if (object == null) {
        return null;
    }
    try {
        final Field field = InvocationUtil.getField(object.getClass(), "handler");
        if (field != null) {
            final JavassistLazyInitializer handler = InvocationUtil.getValue(object, field, AccessType.FIELD, false);
            return handler.getPersistentClass();
        }
    } catch (final InvocationException e) {
        log.warn("Cannot run invocation for {}", object, e);
    }
    return object.getClass();
}
项目:javers    文件:HibernateUnproxyObjectAccessHook.java   
@Override
public Optional<ObjectAccessProxy<T>> createAccessor(T entity) {
    if (entity instanceof HibernateProxy) {
        LazyInitializer lazyInitializer = ((HibernateProxy) entity).getHibernateLazyInitializer();

        return fromLazyInitializer(lazyInitializer);
    }
    if (entity instanceof JavassistLazyInitializer){
        JavassistLazyInitializer proxy = (JavassistLazyInitializer) entity;
        return fromLazyInitializer(proxy);
    }

    return Optional.empty();
}
项目:jbromo    文件:JpaHibernateProviderTest.java   
/**
 * Default constructor.
 */
public HibernateEntityHandler() {
    super();
    this.handler = PowerMockito.mock(JavassistLazyInitializer.class);
    PowerMockito.when(this.handler.getPersistentClass()).thenReturn(Integer.class);
}