use of org.eclipse.persistence.queries.UpdateAllQuery in project eclipselink by eclipse-ee4j.
the class ReportQueryAdvancedJUnitTest method clear.
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()).getPlatform().isSymfoware()) {
UpdateAllQuery updateEmployees = new UpdateAllQuery(Employee.class);
updateEmployees.addUpdate("manager", null);
updateEmployees.addUpdate("address", null);
uow.executeQuery(updateEmployees);
} else {
Iterator<Employee> emps = uow.readAllObjects(Employee.class).iterator();
while (emps.hasNext()) {
Employee emp = emps.next();
emp.setManager(null);
emp.setAddress((String) 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));
if (!(JUnitTestCase.getServerSession()).getPlatform().isSymfoware()) {
uow.executeQuery(new DeleteAllQuery(Employee.class));
}
uow.executeQuery(new DeleteAllQuery(Project.class));
uow.commit();
clearCache();
}
use of org.eclipse.persistence.queries.UpdateAllQuery in project eclipselink by eclipse-ee4j.
the class UpdateAllQueryAdvancedJunitTest method clear.
protected void clear() {
UnitOfWork uow = acquireUnitOfWork();
UpdateAllQuery updateEmployees = new UpdateAllQuery(Employee.class);
updateEmployees.addUpdate("manager", null);
updateEmployees.addUpdate("address", null);
uow.executeQuery(updateEmployees);
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(Employee.class));
uow.executeQuery(new DeleteAllQuery(Project.class));
uow.commit();
clearCache();
}
use of org.eclipse.persistence.queries.UpdateAllQuery in project eclipselink by eclipse-ee4j.
the class UpdateAllQueryAdvancedJunitTest method testDoubleSalaryForAll.
public void testDoubleSalaryForAll() {
if (getServerSession("fieldaccess").getPlatform().isSymfoware()) {
warning("UpdateAllQueryAdvancedJunitTest skipped for this platform, " + "Symfoware doesn't support UpdateAll/DeleteAll on multi-table objects (see rfe 298193).");
return;
}
EntityManager em = createEntityManager("fieldaccess");
beginTransaction(em);
try {
ExpressionBuilder builder = new ExpressionBuilder();
UpdateAllQuery updateQuery = new UpdateAllQuery(Employee.class);
updateQuery.addUpdate("salary", ExpressionMath.multiply(builder.get("salary"), Integer.valueOf(2)));
updateAllQueryInternal(updateQuery);
} finally {
if (isTransactionActive(em)) {
rollbackTransaction(em);
}
closeEntityManager(em);
}
}
use of org.eclipse.persistence.queries.UpdateAllQuery in project eclipselink by eclipse-ee4j.
the class UpdateAllQueryAdvancedJunitTest method testFirstNamePrefixBLADoubleSalaryForSalary.
public void testFirstNamePrefixBLADoubleSalaryForSalary() {
if (getServerSession("fieldaccess").getPlatform().isSymfoware()) {
warning("UpdateAllQueryAdvancedJunitTest skipped for this platform, " + "Symfoware doesn't support UpdateAll/DeleteAll on multi-table objects (see rfe 298193).");
return;
}
EntityManager em = createEntityManager("fieldaccess");
beginTransaction(em);
try {
ExpressionBuilder builder = new ExpressionBuilder();
Expression selectionExpression = builder.get("salary").lessThan(20000);
UpdateAllQuery updateQuery = new UpdateAllQuery(Employee.class, selectionExpression);
updateQuery.addUpdate("firstName", Expression.fromLiteral("'BLA'", null).concat(builder.get("firstName")));
updateQuery.addUpdate("salary", ExpressionMath.multiply(builder.get("salary"), Integer.valueOf(2)));
updateAllQueryInternal(updateQuery);
} finally {
if (isTransactionActive(em)) {
rollbackTransaction(em);
}
closeEntityManager(em);
}
}
use of org.eclipse.persistence.queries.UpdateAllQuery in project eclipselink by eclipse-ee4j.
the class UpdateAllQueryAdvancedJunitTest method testAssignObjectToAddress.
public void testAssignObjectToAddress() {
if (getServerSession("fieldaccess").getPlatform().isSymfoware()) {
warning("UpdateAllQueryAdvancedJunitTest skipped for this platform, " + "Symfoware doesn't support UpdateAll/DeleteAll on multi-table objects (see rfe 298193).");
return;
}
EntityManager em = createEntityManager("fieldaccess");
if (isOnServer()) {
warning("Warning: The test uses UnitOfWork directly, not JPA, so will not work correctly with JTA. For details, see https://bugs.eclipse.org/bugs/show_bug.cgi?id=305040");
return;
}
beginTransaction(em);
try {
Address address = new Address();
address.setCountry("Canada");
address.setProvince("Ontario");
address.setCity("Ottawa");
address.setStreet("O'Connor");
UnitOfWork uow = acquireUnitOfWork();
uow.registerNewObject(address);
uow.commit();
UpdateAllQuery updateQuery = new UpdateAllQuery(Employee.class);
updateQuery.addUpdate("address", address);
updateAllQueryInternal(updateQuery);
} finally {
if (isTransactionActive(em)) {
rollbackTransaction(em);
}
closeEntityManager(em);
}
}
Aggregations