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

项目:eMonocot    文件:BaseTest.java   
/**
 * Another problem with
 * http://build.e-monocot.org/bugzilla/show_bug.cgi?id=262 Unexpected Taxon
 * Exception in DwC Harvesting even though the taxon is expected. Comparing
 * HibernateProxies with non-proxies means you can't use o1.getClass() ==
 * o2.getClass().
 * @throws Exception if there is a problem
 */
@Test
public final void testEqualsWithHibernateProxies() throws Exception {
    b2.setIdentifier("test");
    b2.setId(1L);
    b1.setIdentifier("test");
    b1.setId(1L);
    SessionImplementor sessionImplementor = EasyMock
            .createMock(SessionImplementor.class);
    SessionFactoryImplementor sessionFactoryImplementor = EasyMock
            .createMock(SessionFactoryImplementor.class);
    EntityPersister entityPersister = EasyMock
            .createMock(EntityPersister.class);
    PersistenceContext persistenceContext = EasyMock
            .createMock(PersistenceContext.class);
    EasyMock.expect(sessionImplementor.getFactory())
    .andReturn(sessionFactoryImplementor).anyTimes();
    EasyMock.expect(
            sessionFactoryImplementor.getEntityPersister((String) EasyMock
                    .eq("Annotation"))).andReturn(entityPersister)
                    .anyTimes();
    EasyMock.expect(sessionImplementor.getPersistenceContext()).andReturn(
            persistenceContext);
    EasyMock.expect(persistenceContext.isDefaultReadOnly())
    .andReturn(Boolean.TRUE).anyTimes();
    EasyMock.expect(entityPersister.isMutable()).andReturn(Boolean.TRUE)
    .anyTimes();
    EasyMock.expect(sessionImplementor.isClosed()).andReturn(Boolean.FALSE)
    .anyTimes();
    EasyMock.expect(sessionImplementor.isOpen()).andReturn(Boolean.TRUE)
    .anyTimes();
    EasyMock.expect(sessionImplementor.isConnected())
    .andReturn(Boolean.TRUE).anyTimes();
    EasyMock.expect(
            sessionImplementor.immediateLoad(EasyMock.eq("Annotation"),
                    EasyMock.eq(1L))).andReturn(b2).anyTimes();

    EasyMock.replay(sessionImplementor, sessionFactoryImplementor,
            entityPersister, persistenceContext);

    JavassistProxyFactory javassistProxyFactory = new JavassistProxyFactory();
    Set interfaces = new HashSet();
    interfaces.add(HibernateProxy.class);
    interfaces.add(Serializable.class);
    interfaces.add(Identifiable.class);
    interfaces.add(SecuredObject.class);

    javassistProxyFactory.postInstantiate("Annotation", Annotation.class,
            interfaces, Annotation.class.getDeclaredMethod("getId"),
            Annotation.class.getDeclaredMethod("setId", Long.class), null);

    b3 = javassistProxyFactory.getProxy(1L, sessionImplementor);

    EasyMock.verify(sessionImplementor, sessionFactoryImplementor,
            entityPersister, persistenceContext);
    assertTrue("Equals should return true", b1.equals(b3));
}
项目:powop    文件:BaseTest.java   
/**
 * Another problem with
 * http://build.e-monocot.org/bugzilla/show_bug.cgi?id=262 Unexpected Taxon
 * Exception in DwC Harvesting even though the taxon is expected. Comparing
 * HibernateProxies with non-proxies means you can't use o1.getClass() ==
 * o2.getClass().
 * @throws Exception if there is a problem
 */
@Test
public final void testEqualsWithHibernateProxies() throws Exception {
    b2.setIdentifier("test");
    b2.setId(1L);
    b1.setIdentifier("test");
    b1.setId(1L);
    SessionImplementor sessionImplementor = EasyMock
            .createMock(SessionImplementor.class);
    SessionFactoryImplementor sessionFactoryImplementor = EasyMock
            .createMock(SessionFactoryImplementor.class);
    EntityPersister entityPersister = EasyMock
            .createMock(EntityPersister.class);
    PersistenceContext persistenceContext = EasyMock
            .createMock(PersistenceContext.class);
    EasyMock.expect(sessionImplementor.getFactory())
    .andReturn(sessionFactoryImplementor).anyTimes();
    EasyMock.expect(
            sessionFactoryImplementor.getEntityPersister((String) EasyMock
                    .eq("Annotation"))).andReturn(entityPersister)
                    .anyTimes();
    EasyMock.expect(sessionImplementor.getPersistenceContext()).andReturn(
            persistenceContext);
    EasyMock.expect(persistenceContext.isDefaultReadOnly())
    .andReturn(Boolean.TRUE).anyTimes();
    EasyMock.expect(entityPersister.isMutable()).andReturn(Boolean.TRUE)
    .anyTimes();
    EasyMock.expect(sessionImplementor.isClosed()).andReturn(Boolean.FALSE)
    .anyTimes();
    EasyMock.expect(sessionImplementor.isOpen()).andReturn(Boolean.TRUE)
    .anyTimes();
    EasyMock.expect(sessionImplementor.isConnected())
    .andReturn(Boolean.TRUE).anyTimes();
    EasyMock.expect(
            sessionImplementor.immediateLoad(EasyMock.eq("Annotation"),
                    EasyMock.eq(1L))).andReturn(b2).anyTimes();

    EasyMock.replay(sessionImplementor, sessionFactoryImplementor,
            entityPersister, persistenceContext);

    JavassistProxyFactory javassistProxyFactory = new JavassistProxyFactory();
    Set interfaces = new HashSet();
    interfaces.add(HibernateProxy.class);
    interfaces.add(Serializable.class);
    interfaces.add(Identifiable.class);
    interfaces.add(SecuredObject.class);

    javassistProxyFactory.postInstantiate("Annotation", Annotation.class,
            interfaces, Annotation.class.getDeclaredMethod("getId"),
            Annotation.class.getDeclaredMethod("setId", Long.class), null);

    b3 = javassistProxyFactory.getProxy(1L, sessionImplementor);

    EasyMock.verify(sessionImplementor, sessionFactoryImplementor,
            entityPersister, persistenceContext);
    assertTrue("Equals should return true", b1.equals(b3));
}
项目:lams    文件:ProxyFactoryFactoryImpl.java   
/**
 * Builds a Javassist-based proxy factory.
 *
 * @return a new Javassist-based proxy factory.
 */
public ProxyFactory buildProxyFactory() {
    return new JavassistProxyFactory();
}
项目:cacheonix-core    文件:ProxyFactoryFactoryImpl.java   
/**
 * Builds a Javassist-based proxy factory.
 *
 * @return a new Javassist-based proxy factory.
 */
public ProxyFactory buildProxyFactory() {
    return new JavassistProxyFactory();
}