public void testEL254937() { EntityManager em = createEntityManager(m_persistenceUnit); beginTransaction(em); LargeProject lp1 = new LargeProject(); lp1.setName("one"); em.persist(lp1); commitTransaction(em); em = createEntityManager(m_persistenceUnit); beginTransaction(em); em.remove(em.find(LargeProject.class, lp1.getId())); em.flush(); JpaEntityManager eclipselinkEm = (JpaEntityManager) em.getDelegate(); RepeatableWriteUnitOfWork uow = (RepeatableWriteUnitOfWork) eclipselinkEm.getActiveSession(); // duplicate the beforeCompletion call uow.issueSQLbeforeCompletion(); // commit the transaction uow.setShouldTerminateTransaction(true); uow.commitTransaction(); // duplicate the AfterCompletion call. This should merge, removing the LargeProject from the // shared cache uow.mergeClonesAfterCompletion(); em = createEntityManager(m_persistenceUnit); LargeProject cachedLargeProject = em.find(LargeProject.class, lp1.getId()); closeEntityManager(em); assertTrue( "Entity removed during flush was not removed from the shared cache on commit", cachedLargeProject == null); }
public List<Reservation> retrieveAll() { em = factory.createEntityManager(); em.getTransaction().begin(); ReadAllQuery query = new ReadAllQuery(); Reservation obj = new Reservation(); query.setExampleObject(obj); JpaEntityManager jpa = (JpaEntityManager) em.getDelegate(); List<Reservation> results = (List<Reservation>) jpa.getServerSession().acquireClientSession().executeQuery(query); return results; }
public void update(Object[] data, String[] keys) throws Exception { if ((data != null) && (data.length > 0)) { try { if (transaction) { start(); } for (Object o : data) { Object example = o.getClass().newInstance(); this.copy(o, example, keys); BaseBean entity = (BaseBean) find(example); if (entity != null) { entity.assign(o); jpa.merge(entity); data = null; } } if (transaction) { commit(); } } catch (Exception e) { rollback(); throw e; } } }
public String getLastModifiedDate(Object sample) { String modifiedDate = null; ExpressionBuilder builder = new ExpressionBuilder(sample.getClass()); ReportQuery report = new ReportQuery(sample.getClass(), builder); report.addMaximum("modifiedDate"); jpa.getSession().executeQuery(report); List l = (List) jpa.getSession().executeQuery(report); if (l != null && l.size() > 0) { ReportQueryResult o = (ReportQueryResult) l.get(0); modifiedDate = (String) o.getByIndex(0); } return modifiedDate; }
public Object[] find(ReadAllQuery dbQuery) { Query query = jpa.createQuery(dbQuery); List l = query.getResultList(); if ((l != null) && (l.size() > 0)) { return l.toArray(); } else { return null; } }
public void testDeleteExpression() { if (isOnServer()) { // Not work on server. return; } if ((JUnitTestCase.getServerSession()).getPlatform().isSymfoware()) { getServerSession() .logMessage( "Test testDeleteExpression skipped for this platform, " + "Symfoware doesn't support UpdateAll/DeleteAll on multi-table objects (see rfe 298193)."); return; } JpaEntityManager em = (org.eclipse.persistence.jpa.JpaEntityManager) createEntityManager(); try { beginTransaction(em); String orderString = "DELETE FROM OrderBean o WHERE o.customer.name ='Karen McDonald' "; em.createQuery(orderString).executeUpdate(); orderString = "DELETE FROM OrderBean o WHERE o.billedCustomer.name ='Karen McDonald' "; em.createQuery(orderString).executeUpdate(); String ejbqlString = "DELETE FROM Customer c WHERE c.name='Karen McDonald' "; int result = em.createQuery(ejbqlString).executeUpdate(); Assert.assertEquals("Delete Expression test failed: customer to delete not found", 1, result); em.flush(); ReadAllQuery raq = new ReadAllQuery(Customer.class, new ExpressionBuilder()); Expression whereClause = raq.getExpressionBuilder().get("name").equal("Karen McDonald"); raq.setSelectionCriteria(whereClause); List customerFound = (List) em.getActiveSession().executeQuery(raq); Assert.assertEquals("Delete Expression test failed", 0, customerFound.size()); } finally { rollbackTransaction(em); } }
public Object[] find(Object example, int count) { Query q = jpa.createQueryByExample(example); q.setMaxResults(count); List l = q.getResultList(); if ((l != null) && (l.size() > 0)) { return l.toArray(); } else { return null; } }
public void execute(String sql) throws Exception { start(); try { Query q = jpa.createNativeQuery(sql); q.executeUpdate(); commit(); } catch (Exception e) { rollback(); throw e; } }
public void delete(Object[] data) throws Exception { if ((data != null) && (data.length > 0)) { try { if (transaction) { start(); } for (Object o : data) { jpa.remove(o); } if (transaction) { commit(); } } catch (Exception e) { rollback(); throw e; } } }
public void append(Object[] data) throws Exception { if ((data != null) && (data.length > 0)) { if (transaction) { start(); } try { start(); for (Object o : data) { jpa.persist(o); } if (transaction) { commit(); } } catch (Exception e) { rollback(); throw e; } } }
public DataAccessObject(String unitName) { jpa = JpaHelper.getEntityManager( Persistence.createEntityManagerFactory(unitName).createEntityManager()); jpa.setFlushMode(FlushModeType.COMMIT); }
public void rollback() { if (jpa.getTransaction().isActive()) { jpa.getTransaction().rollback(); } }
public void commit() { if (jpa.getTransaction().isActive()) { jpa.getTransaction().commit(); } }
public void start() { if (!jpa.getTransaction().isActive()) { jpa.getTransaction().begin(); } }