Java 类org.hibernate.jpa.HibernateEntityManager 实例源码

项目:dropwizard-entitymanager    文件:SharedEntityManagerFactoryTest.java   
@Test
public void delegatesToUnwrapForNonProxyClass() {
    HibernateEntityManager mockHibernateEm = mock(HibernateEntityManager.class);
    when(entityManager.unwrap(HibernateEntityManager.class)).thenReturn(mockHibernateEm);

    HibernateEntityManager foundHibernateEm = createProxy().unwrap(HibernateEntityManager.class);
    verify(entityManager).unwrap(HibernateEntityManager.class);
    assertThat(foundHibernateEm).isSameAs(mockHibernateEm);
}
项目:biomojo    文件:DbUtil.java   
/**
 * Log stats.
 *
 * @param comment
 *            the comment
 */
public void logStats(final String comment) {
    if (entityManager instanceof HibernateEntityManager) {
        final Session session = ((HibernateEntityManager) entityManager).getSession();
        logger.info("STATS: " + comment);
        session.getSessionFactory().getStatistics().logSummary();
    } else {
        logger.warn("Entity Manager is not a hibernate entity manager");
    }
}
项目:Biliomi    文件:Managed.java   
public Managed(EntityManagerFactory emf) {
  session = emf.createEntityManager().unwrap(HibernateEntityManager.class).getSession();
}
项目:random-jpa    文件:MockEntityManagerProvider.java   
private MockEntityManagerProvider() {
    this.entityManager = Mockito.mock(HibernateEntityManager.class);
    this.entityManagerFactory = Mockito.mock(HibernateEntityManagerFactory.class);
    this.metamodel = Mockito.mock(Metamodel.class);
}
项目:elide    文件:AbstractHibernateStore.java   
public Builder(final HibernateEntityManager entityManager) {
    this.sessionFactory = null;
    this.isScrollEnabled = true;
    this.scrollMode = ScrollMode.FORWARD_ONLY;
    this.entityManager = entityManager;
}
项目:elide    文件:HibernateEntityManagerStore.java   
public HibernateEntityManagerStore(HibernateEntityManager entityManager,
                                   boolean isScrollEnabled,
                                   ScrollMode scrollMode) {
    super(null, isScrollEnabled, scrollMode);
    this.entityManager = entityManager;
}
项目:dropwizard-entitymanager    文件:UnitOfWorkAspect.java   
private void configureSession() {
    HibernateEntityManager em = (HibernateEntityManager) this.entityManager;
    em.getSession().setDefaultReadOnly(this.unitOfWork.readOnly());
    em.getSession().setCacheMode(this.unitOfWork.cacheMode());
    em.getSession().setFlushMode(this.unitOfWork.flushMode());
}
项目:atom    文件:ServerSingleton.java   
public PersistedFileAttribute saveFileAttribute(ClientSession session, FileItem fileItem, String forClassName, String forAttributeName, Integer forInstanceID) {

    PersistedFileAttribute pfa = null;
    EntityManager em = null;
    EntityTransaction tx = null;

    try {
        em = AtomEMFactory.getEntityManager();
        tx = em.getTransaction();
        tx.begin();

        DomainObject forInstance = null;
        if(forInstanceID != null) {
            //forInstance = getDomainObject(session, forInstanceID, forClassName);
            forInstance = (DomainObject) em.find(ServerTools.getClassForName(forClassName), forInstanceID);
        }

        HibernateEntityManager hem = em.unwrap(HibernateEntityManager.class);
        Session hibernateSession = hem.getSession();
        LobCreator lobCreator = Hibernate.getLobCreator(hibernateSession);
        Blob blob = lobCreator.createBlob(fileItem.getInputStream(), fileItem.getSize());

        pfa = new PersistedFileAttribute(blob, fileItem.getName(), fileItem.getContentType(), forClassName, forAttributeName, forInstance, session.getUser());
        pfa = em.merge(pfa);

        tx.commit();

    } catch (Throwable t) {
        if(tx != null && tx.isActive())
            tx.rollback();
        if (t instanceof AtomException) {
            throw (AtomException) t;
        } else {
            AtomTools.log(Level.SEVERE, "ServerTools.saveFileAttribute exception: " + t.getClass().getSimpleName() + " - " + t.getMessage(), this, t);
        }
    } finally {
        ServerTools.closeDBConnection(tx, em);
    }

    return pfa;
}