Search in sources :

Example 26 with DeleteAllQuery

use of org.eclipse.persistence.queries.DeleteAllQuery in project eclipselink by eclipse-ee4j.

the class JoinedAttributeAdvancedJunitTest 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("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();
}
Also used : UnitOfWork(org.eclipse.persistence.sessions.UnitOfWork) DeleteAllQuery(org.eclipse.persistence.queries.DeleteAllQuery) UpdateAllQuery(org.eclipse.persistence.queries.UpdateAllQuery)

Example 27 with DeleteAllQuery

use of org.eclipse.persistence.queries.DeleteAllQuery in project eclipselink by eclipse-ee4j.

the class JoinedAttributeAdvancedJunitTest method testTwoUnrelatedResultWithOneToManyJoins.

public void testTwoUnrelatedResultWithOneToManyJoins() {
    if (getServerSession("fieldaccess").getPlatform().isSymfoware()) {
        getServerSession("fieldaccess").logMessage("Test testTwoUnrelatedResultWithOneToManyJoins skipped for this platform, " + "Symfoware doesn't support UpdateAll/DeleteAll on multi-table objects (see rfe 298193).");
        return;
    }
    ReadAllQuery raq = new ReadAllQuery(Employee.class);
    raq.setSelectionCriteria(raq.getExpressionBuilder().get("lastName").equal("Way").or(raq.getExpressionBuilder().get("lastName").equal("Jones")));
    Employee emp = (Employee) ((Vector) getDbSession().executeQuery(raq)).firstElement();
    emp.getPhoneNumbers();
    for (Iterator<PhoneNumber> iterator = emp.getPhoneNumbers().iterator(); iterator.hasNext(); ) {
        iterator.next().getOwner();
    }
    raq = new ReadAllQuery(Address.class);
    raq.setSelectionCriteria(raq.getExpressionBuilder().get("city").like("%ttawa%"));
    Address addr = (Address) ((Vector) getDbSession().executeQuery(raq)).firstElement();
    addr.getEmployees();
    for (Iterator<Employee> iterator = addr.getEmployees().iterator(); iterator.hasNext(); ) {
        iterator.next().getAddress();
    }
    getDbSession().getIdentityMapAccessor().initializeAllIdentityMaps();
    ReportQuery query = new ReportQuery();
    query.setShouldReturnWithoutReportQueryResult(true);
    query.setReferenceClass(Employee.class);
    ExpressionBuilder eb = new ExpressionBuilder(Address.class);
    query.setSelectionCriteria(query.getExpressionBuilder().get("id").equal(emp.getId()).and(eb.get("id").equal(addr.getId())));
    List list = new ArrayList();
    list.add(query.getExpressionBuilder().anyOf("phoneNumbers"));
    query.addItem("employee", query.getExpressionBuilder(), list);
    list = new ArrayList();
    list.add(eb.anyOf("employees"));
    query.addItem("address", eb, list);
    Vector result = (Vector) getDbSession().executeQuery(query);
    DeleteAllQuery deleteAll = new DeleteAllQuery(PhoneNumber.class);
    deleteAll.setSelectionCriteria(deleteAll.getExpressionBuilder().get("owner").get("id").equal(emp.getId()));
    UnitOfWork uow = getDbSession().acquireUnitOfWork();
    uow.executeQuery(deleteAll);
    UpdateAllQuery updall = new UpdateAllQuery(Employee.class);
    updall.addUpdate("address", null);
    updall.setSelectionCriteria(updall.getExpressionBuilder().get("address").get("id").equal(addr.getId()));
    uow.executeQuery(updall);
    uow.commit();
    try {
        Employee emp2 = (Employee) ((Object[]) result.firstElement())[0];
        Address addr2 = (Address) ((Object[]) result.firstElement())[1];
        assertTrue("PhoneNumbers were not joined correctly, emp.getPhoneNumbers().size = " + emp.getPhoneNumbers().size() + " emp2.getPhoneNumbers().size = " + emp2.getPhoneNumbers().size(), (emp.getPhoneNumbers().size() == emp2.getPhoneNumbers().size()));
        assertTrue("Employees were not joined correctly, addr.employees.size = " + addr.getEmployees().size() + "addr2.employees.size = " + addr2.getEmployees().size(), (addr.getEmployees().size() == addr2.getEmployees().size()));
    } finally {
        testSetup();
    }
}
Also used : DeleteAllQuery(org.eclipse.persistence.queries.DeleteAllQuery) UnitOfWork(org.eclipse.persistence.sessions.UnitOfWork) ReportQuery(org.eclipse.persistence.queries.ReportQuery) ReadAllQuery(org.eclipse.persistence.queries.ReadAllQuery) ArrayList(java.util.ArrayList) ExpressionBuilder(org.eclipse.persistence.expressions.ExpressionBuilder) ArrayList(java.util.ArrayList) List(java.util.List) Vector(java.util.Vector) UpdateAllQuery(org.eclipse.persistence.queries.UpdateAllQuery)

Example 28 with DeleteAllQuery

use of org.eclipse.persistence.queries.DeleteAllQuery in project eclipselink by eclipse-ee4j.

the class DeleteAllQueryInheritanceJunitTest method clearVehiclesCompanies.

protected void clearVehiclesCompanies() {
    UnitOfWork uow = acquireUnitOfWork();
    // delete all Vechicles
    uow.executeQuery(new DeleteAllQuery(Vehicle.class));
    // delete all Companies
    uow.executeQuery(new DeleteAllQuery(Company.class));
    uow.commit();
    clearCache();
}
Also used : UnitOfWork(org.eclipse.persistence.sessions.UnitOfWork) DeleteAllQuery(org.eclipse.persistence.queries.DeleteAllQuery)

Example 29 with DeleteAllQuery

use of org.eclipse.persistence.queries.DeleteAllQuery in project eclipselink by eclipse-ee4j.

the class DeleteNode method createDatabaseQuery.

/**
 * INTERNAL
 * Returns a DatabaseQuery instance representing the owning
 * ParseTree. This implementation returns a DeleteAllQuery instance.
 */
@Override
public DatabaseQuery createDatabaseQuery(ParseTreeContext context) {
    DeleteAllQuery query = new DeleteAllQuery();
    query.setShouldDeferExecutionInUOW(false);
    return query;
}
Also used : DeleteAllQuery(org.eclipse.persistence.queries.DeleteAllQuery)

Aggregations

DeleteAllQuery (org.eclipse.persistence.queries.DeleteAllQuery)29 UnitOfWork (org.eclipse.persistence.sessions.UnitOfWork)16 UpdateAllQuery (org.eclipse.persistence.queries.UpdateAllQuery)12 Vector (java.util.Vector)9 ExpressionBuilder (org.eclipse.persistence.expressions.ExpressionBuilder)6 ArrayList (java.util.ArrayList)5 List (java.util.List)4 ClassDescriptor (org.eclipse.persistence.descriptors.ClassDescriptor)4 ReadAllQuery (org.eclipse.persistence.queries.ReadAllQuery)4 ReportQuery (org.eclipse.persistence.queries.ReportQuery)4 Expression (org.eclipse.persistence.expressions.Expression)3 Iterator (java.util.Iterator)2 ConstantExpression (org.eclipse.persistence.internal.expressions.ConstantExpression)2 ObjectExpression (org.eclipse.persistence.internal.expressions.ObjectExpression)2 DatabaseTable (org.eclipse.persistence.internal.helper.DatabaseTable)2 NonSynchronizedVector (org.eclipse.persistence.internal.helper.NonSynchronizedVector)2 DatabaseRecord (org.eclipse.persistence.sessions.DatabaseRecord)2 HashMap (java.util.HashMap)1 Map (java.util.Map)1 TreeMap (java.util.TreeMap)1