@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); }
/** * 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"); } }
public Managed(EntityManagerFactory emf) { session = emf.createEntityManager().unwrap(HibernateEntityManager.class).getSession(); }
private MockEntityManagerProvider() { this.entityManager = Mockito.mock(HibernateEntityManager.class); this.entityManagerFactory = Mockito.mock(HibernateEntityManagerFactory.class); this.metamodel = Mockito.mock(Metamodel.class); }
public Builder(final HibernateEntityManager entityManager) { this.sessionFactory = null; this.isScrollEnabled = true; this.scrollMode = ScrollMode.FORWARD_ONLY; this.entityManager = entityManager; }
public HibernateEntityManagerStore(HibernateEntityManager entityManager, boolean isScrollEnabled, ScrollMode scrollMode) { super(null, isScrollEnabled, scrollMode); this.entityManager = entityManager; }
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()); }
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; }