public void updateAllTest() { if ((JUnitTestCase.getServerSession()).getPlatform().isSymfoware()) { getServerSession() .logMessage( "Test updateAllTest skipped for this platform, " + "Symfoware doesn't support UpdateAll/DeleteAll on multi-table objects (see rfe 298193)."); return; } EntityManager em = createEntityManager(); String empName = "Saunders"; String manName = "Smitty"; String ejbqlString = "SELECT DISTINCT e FROM Employee e WHERE e.lastName = '" + empName + "'"; Employee employee = (Employee) em.createQuery(ejbqlString).getSingleResult(); Address addr = em.find(Address.class, employee.getAddress().getID()); String ejbqlString2 = "SELECT DISTINCT e FROM Employee e WHERE e.lastName = '" + manName + "'"; Employee manager = (Employee) em.createQuery(ejbqlString2).getSingleResult(); beginTransaction(em); em.createQuery("UPDATE Employee e SET e.manager = :manager " + "WHERE e.address = :addr ") .setParameter("manager", manager) .setParameter("addr", addr) .executeUpdate(); commitTransaction(em); String ejbqlString3 = "SELECT DISTINCT e.manager FROM Employee e WHERE e.lastName = '" + empName + "'"; String result = ((Employee) em.createQuery(ejbqlString3).getSingleResult()).getLastName(); Assert.assertTrue("UpdateAll test failed", result.equals(manName)); }
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 void testUpdateExpression() { if ((JUnitTestCase.getServerSession()).getPlatform().isSymfoware()) { getServerSession() .logMessage( "Test testUpdateExpression skipped for this platform, " + "Symfoware doesn't support UpdateAll/DeleteAll on multi-table objects (see rfe 298193)."); return; } EntityManager em = createEntityManager(); Number result = null; beginTransaction(em); try { String ejbqlString = "UPDATE Customer c SET c.name = 'Test Case' WHERE c.name = 'Jane Smith' " + "AND 0 < (SELECT COUNT(o) FROM Customer cust JOIN cust.orders o)"; result = em.createQuery(ejbqlString).executeUpdate(); commitTransaction(em); } finally { if (isTransactionActive(em)) { rollbackTransaction(em); } } Assert.assertEquals("Update expression test failed", 1, result); }
protected void clear() { UnitOfWork uow = acquireUnitOfWork(); // use alternate way for Symfoware as it doesn't support UpdateAll/DeleteAll on multi-table // objects (see rfe 298193) if (!(JUnitTestCase.getServerSession("fieldaccess")).getPlatform().isSymfoware()) { UpdateAllQuery updateEmployees = new UpdateAllQuery(Employee.class); updateEmployees.addUpdate("manager", null); updateEmployees.addUpdate("address", null); uow.executeQuery(updateEmployees); uow.executeQuery(new DeleteAllQuery(Employee.class)); } else { Iterator<Employee> emps = uow.readAllObjects(Employee.class).iterator(); while (emps.hasNext()) { Employee emp = emps.next(); emp.setManager(null); emp.setAddress(null); uow.deleteObject(emp); } ; } UpdateAllQuery updateProjects = new UpdateAllQuery(Project.class); updateProjects.addUpdate("teamLeader", null); uow.executeQuery(updateProjects); uow.executeQuery(new DeleteAllQuery(PhoneNumber.class)); uow.executeQuery(new DeleteAllQuery(Address.class)); uow.executeQuery(new DeleteAllQuery(Project.class)); uow.commit(); dbSessionClearCache(); }
/** * The setup is done as a test, both to record its failure, and to allow execution in the server. */ public void testSetup() { clearCache(); // get session to start setup DatabaseSession session = JUnitTestCase.getServerSession(); // create a new EmployeePopulator EmployeePopulator employeePopulator = new EmployeePopulator(); RelationshipsExamples relationshipExamples = new RelationshipsExamples(); new AdvancedTableCreator().replaceTables(session); new RelationshipsTableManager().replaceTables(session); // initialize the global comparer object comparer = new JUnitDomainObjectComparer(); // set the session for the comparer to use comparer.setSession((AbstractSession) session.getActiveSession()); // Populate the advanced model employeePopulator.buildExamples(); // populate the relationships model and persist as well relationshipExamples.buildExamples(session); // Persist the advanced model examples in the database employeePopulator.persistExample(session); }
public void testColumnUpdatableAndInsertableThroughQuery() { if ((JUnitTestCase.getServerSession()).getPlatform().isSymfoware()) { getServerSession() .logMessage( "Test testColumnUpdatableAndInsertableThroughQuery skipped for this platform, " + "Symfoware doesn't support UpdateAll/DeleteAll on multi-table objects (see rfe 298193)."); return; } EntityManager em = createEntityManager(); try { // Create an official beginTransaction(em); Official initialOfficial = new Official(); initialOfficial.setName("Gui Pelletier"); em.persist(initialOfficial); commitTransaction(em); // Close the EM, clear cache and get new EM. closeEntityManager(em); clearCache(); em = createEntityManager(); // Update the official using a named query. beginTransaction(em); Query query = em.createNamedQuery("UpdateXMLOfficalName"); query.setParameter("name", "Guy"); query.setParameter("id", initialOfficial.getId()); query.executeUpdate(); Official modifiedOfficial = em.find(Official.class, initialOfficial.getId()); assertTrue( "The name was not updated after executing the named query", modifiedOfficial.getName().equals("Guy")); commitTransaction(em); // Close the EM, clear cache and get new EM. closeEntityManager(em); clearCache(); em = createEntityManager(); Official refreshedOfficial = em.find(Official.class, modifiedOfficial.getId()); assertTrue( "The refreshedOfficial did not match the modified", getServerSession().compareObjects(modifiedOfficial, refreshedOfficial)); } catch (Exception e) { if (isTransactionActive(em)) { rollbackTransaction(em); } fail("Update query failed: " + e.getMessage()); } finally { closeEntityManager(em); } }
public void setUp(boolean overrideEMFCachingForTesting) { super.setUp(); initialize(); ServerSession session = JUnitTestCase.getServerSession(PERSISTENCE_UNIT_NAME); // if(!isDatabaseSchemaCreated | overrideEMFCachingForTesting) { if (null == entityManagerFactory || (null != entityManagerFactory && !entityManagerFactory.isOpen())) { new MetamodelTableCreator().replaceTables(session); isDatabaseSchemaCreated = true; } }
public void testSetup() { supported = getServerSession(STRUCT_CONVERTER_PU).getPlatform().isOracle(); if (!supported) { return; } clearCache(STRUCT_CONVERTER_PU); getServerSession(STRUCT_CONVERTER_PU) .executeNonSelectingSQL( "DELETE FROM USER_SDO_GEOM_METADATA WHERE TABLE_NAME = 'JPA_JGEOMETRY'"); new JGeometryTableCreator().replaceTables(JUnitTestCase.getServerSession(STRUCT_CONVERTER_PU)); getServerSession(STRUCT_CONVERTER_PU) .executeNonSelectingSQL( "INSERT INTO USER_SDO_GEOM_METADATA(TABLE_NAME, COLUMN_NAME, DIMINFO) VALUES('JPA_JGEOMETRY', 'JGEOMETRY'," + " mdsys.sdo_dim_array(mdsys.sdo_dim_element('X', -100, 100, 0.005), mdsys.sdo_dim_element('Y', -100, 100, 0.005)))"); getServerSession(STRUCT_CONVERTER_PU) .executeNonSelectingSQL( "CREATE INDEX jpa_test_idx on JPA_JGEOMETRY(jgeometry) indextype is mdsys.spatial_index parameters ('sdo_level=5 sdo_numtiles=6')"); }
public void updateEmbeddedFieldTest() { if ((JUnitTestCase.getServerSession()).getPlatform().isSymfoware()) { getServerSession() .logMessage( "Test updateEmbeddedFieldTest skipped for this platform, " + "Symfoware doesn't support UpdateAll/DeleteAll on multi-table objects (see rfe 298193)."); return; } EntityManager em = createEntityManager(); Calendar startCalendar = Calendar.getInstance(); startCalendar.set(1905, 11, 31, 0, 0, 0); java.sql.Date startDate = new java.sql.Date(startCalendar.getTime().getTime()); beginTransaction(em); em.createQuery("UPDATE Employee e SET e.period.startDate= :startDate") .setParameter("startDate", startDate) .executeUpdate(); commitTransaction(em); }
/** * The setup is done as a test, both to record its failure, and to allow execution in the server. */ public void testSetup() { new AdvancedTableCreator().replaceTables(JUnitTestCase.getServerSession(m_persistenceUnit)); clearCache(m_persistenceUnit); }
/** * The setup is done as a test, both to record its failure, and to allow execution in the server. */ public void testSetup() { DatabaseSession session = JUnitTestCase.getServerSession(); new InheritedTableManager().replaceTables(session); clearCache(); }
/** * The setup is done as a test, both to record its failure, and to allow execution in the server. */ public void testSetup() { new InheritanceTableCreator().replaceTables(JUnitTestCase.getServerSession()); clearCache(); }
/** * The setup is done as a test, both to record its failure, and to allow execution in the server. */ public void testSetup() { new AdvancedTableCreator().replaceTables(JUnitTestCase.getServerSession("fieldaccess")); clearCache("fieldaccess"); }
public void testSetup() { new TimestampTableCreator().replaceTables(JUnitTestCase.getServerSession("timestamptz")); }
/** * The setup is done as a test, both to record its failure, and to allow execution in the server. */ public void testSetup() { new AdvancedFetchGroupTableCreator().replaceTables(JUnitTestCase.getServerSession()); clearCache(); }