예제 #1
0
    /** {@inheritDoc} */
    @Override
    public void visit(DeleteStatement expression) {

      DeleteAllQuery query = queryContext.getDatabaseQuery();

      // Create and prepare the query
      if (query == null) {
        query = new DeleteAllQuery();
        queryContext.setDatabasQuery(query);
        query.setJPQLString(jpqlQuery);
        ((JPQLCallQueryMechanism) query.getQueryMechanism()).getJPQLCall().setIsParsed(true);
      }

      query.setSession(queryContext.getSession());
      query.setShouldDeferExecutionInUOW(false);

      // Now populate it
      DeleteQueryVisitor visitor = new DeleteQueryVisitor(queryContext, query);
      expression.accept(visitor);
    }
 /**
  * PUBLIC: The default delete all call for this mapping can be overridden by specifying the new
  * call. This call is responsible for doing the deletion required by the mapping, such as
  * optimized delete all of target objects for 1-M.
  */
 public void setDeleteAllCall(Call call) {
   DeleteAllQuery deleteAllQuery = new DeleteAllQuery();
   deleteAllQuery.setCall(call);
   setDeleteAllQuery(deleteAllQuery);
   setHasCustomDeleteAllQuery(true);
 }
예제 #3
0
 /**
  * INTERNAL Returns a DatabaseQuery instance representing the owning ParseTree. This
  * implementation returns a DeleteAllQuery instance.
  */
 public DatabaseQuery createDatabaseQuery(ParseTreeContext context) {
   DeleteAllQuery query = new DeleteAllQuery();
   query.setShouldDeferExecutionInUOW(false);
   return query;
 }
  public void testMultipleUnrelatedResultWithOneToManyJoins() {
    if (getServerSession("fieldaccess").getPlatform().isSymfoware()) {
      getServerSession("fieldaccess")
          .logMessage(
              "Test testMultipleUnrelatedResultWithOneToManyJoins 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().notEmpty("phoneNumbers"));
    Employee emp = (Employee) ((Vector) getDbSession().executeQuery(raq)).firstElement();
    emp.getPhoneNumbers();
    for (Iterator iterator = emp.getPhoneNumbers().iterator(); iterator.hasNext(); ) {
      ((PhoneNumber) 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 iterator = addr.getEmployees().iterator(); iterator.hasNext(); ) {
      Employee addrEmp = (Employee) iterator.next();
      addrEmp.getAddress();
      addrEmp
          .getPhoneNumbers()
          .size(); // as the report query will join in all phones to all emps, make sure we can
                   // compare.
    }

    getDbSession().getIdentityMapAccessor().initializeAllIdentityMaps();

    ReportQuery query = new ReportQuery();
    query.setShouldReturnWithoutReportQueryResult(true);
    query.setReferenceClass(Address.class);

    ExpressionBuilder eb = new ExpressionBuilder(Employee.class);

    List list = new ArrayList();
    list.add(eb.anyOf("phoneNumbers"));
    query.addItem("employee", eb, list);

    list = new ArrayList();
    list.add(query.getExpressionBuilder().anyOf("employees"));
    query.addItem("address", query.getExpressionBuilder(), list);

    query.setSelectionCriteria(query.getExpressionBuilder().get("id").equal(addr.getId()));

    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 = null;
      Address addr2 = null;
      for (Iterator iterator = result.iterator(); iterator.hasNext(); ) {
        Object[] items = (Object[]) iterator.next();
        emp2 = (Employee) items[0];
        if (emp2.getId().equals(emp.getId())) {
          addr2 = (Address) items[1];
          break;
        }
      }
      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();
    }
  }