예제 #1
0
  @Override
  public void customize(ClassDescriptor descriptor) throws Exception {
    // Direct (basic) query for the Oracle DB's ROWID value
    descriptor.addDirectQueryKey("rowId", "ROWID");

    // 1:M query accessing all projects which have a M:1 teamLeader reference to this employee
    // this can also be used to allow querying of large collections not wanted mapped
    OneToManyQueryKey projectsQueryKey = new OneToManyQueryKey();
    projectsQueryKey.setName("datafiles");
    projectsQueryKey.setReferenceClass(Datafile.class);
    ExpressionBuilder builder = new ExpressionBuilder();
    projectsQueryKey.setJoinCriteria(
        builder
            .getField("DATAFILE.DATAFILEFORMAT")
            .equal(builder.getParameter("DATAFILEFORMAT.ID")));
    descriptor.addQueryKey(projectsQueryKey);
  }
예제 #2
0
  protected void addCustomQueryKeys(ClassDescriptor descriptor) {
    ExpressionBuilder builder;

    // add QueryKeys to Employee descriptor
    if (descriptor.getJavaClass().equals(Employee.class)) {
      // Employee's Address (same as address attribute).
      OneToOneQueryKey queryKey = new OneToOneQueryKey();
      queryKey.setName("addressQK");
      queryKey.setReferenceClass(Address.class);
      builder = new ExpressionBuilder();
      queryKey.setJoinCriteria(
          builder
              .getField("MBR1_ADDRESS.ADDRESS_ID")
              .equal(builder.getParameter("MBR2_EMPLOYEE.ADDR_ID")));
      descriptor.addQueryKey(queryKey);

      // Projects led by Employee.
      OneToManyQueryKey managedProjectsQueryKey = new OneToManyQueryKey();
      managedProjectsQueryKey.setName("managedProjects");
      managedProjectsQueryKey.setReferenceClass(Project.class);
      builder = new ExpressionBuilder();
      managedProjectsQueryKey.setJoinCriteria(
          builder
              .getField("MBR3_PROJECT.LEADER_ID")
              .equal(builder.getParameter("MBR2_EMPLOYEE.EMP_ID")));
      descriptor.addQueryKey(managedProjectsQueryKey);

      // LargeProjects led by Employee.
      OneToManyQueryKey managedLargeProjectsQueryKey = new OneToManyQueryKey();
      managedLargeProjectsQueryKey.setName("managedLargeProjects");
      managedLargeProjectsQueryKey.setReferenceClass(LargeProject.class);
      builder = new ExpressionBuilder();
      managedLargeProjectsQueryKey.setJoinCriteria(
          builder
              .getField("MBR3_PROJECT.LEADER_ID")
              .equal(builder.getParameter("MBR2_EMPLOYEE.EMP_ID")));
      descriptor.addQueryKey(managedLargeProjectsQueryKey);

      // Employee's Projects (same as projects attribute).
      ManyToManyQueryKey projectsQueryKey = new ManyToManyQueryKey();
      projectsQueryKey.setName("projectsQK");
      projectsQueryKey.setReferenceClass(Project.class);
      builder = new ExpressionBuilder();
      projectsQueryKey.setJoinCriteria(
          (builder
              .getParameter("MBR2_EMPLOYEE.EMP_ID")
              .equal(builder.getTable("MBR3_EMP_PROJ").getField("EMPLOYEES_EMP_ID"))
              .and(
                  builder
                      .getTable("MBR3_EMP_PROJ")
                      .getField("PROJECTS_PROJ_ID")
                      .equal(builder.getField("MBR3_PROJECT.PROJ_ID")))));
      descriptor.addQueryKey(projectsQueryKey);

      // Employee's LargeProjects.
      ManyToManyQueryKey largeProjectsQueryKey = new ManyToManyQueryKey();
      largeProjectsQueryKey.setName("largeProjects");
      largeProjectsQueryKey.setReferenceClass(LargeProject.class);
      builder = new ExpressionBuilder();
      largeProjectsQueryKey.setJoinCriteria(
          (builder
              .getParameter("MBR2_EMPLOYEE.EMP_ID")
              .equal(builder.getTable("MBR3_EMP_PROJ").getField("EMPLOYEES_EMP_ID"))
              .and(
                  builder
                      .getTable("MBR3_EMP_PROJ")
                      .getField("PROJECTS_PROJ_ID")
                      .equal(builder.getField("MBR3_PROJECT.PROJ_ID")))));
      descriptor.addQueryKey(largeProjectsQueryKey);

      // Employee's responsibilities (same as responsibilities) - can't make this work so far.
      DirectCollectionQueryKey responsibilitiesQueryKey = new DirectCollectionQueryKey();
      responsibilitiesQueryKey.setName("responsibilitiesQK");
      builder = new ExpressionBuilder();
      responsibilitiesQueryKey.setJoinCriteria(
          builder
              .getField("MBR1_RESPONS.DESCRIPTION")
              .equal(
                  builder
                      .getField("MBR1_RESPONS.EMP_ID")
                      .equal(builder.getParameter("MBR2_EMPLOYEE.EMP_ID"))));
      descriptor.addQueryKey(responsibilitiesQueryKey);

    } else if (descriptor.getJavaClass().equals(Address.class)) {
      // Employee that references Address
      OneToOneQueryKey ownerQueryKey = new OneToOneQueryKey();
      ownerQueryKey.setName("owner");
      ownerQueryKey.setReferenceClass(Employee.class);
      builder = new ExpressionBuilder();
      ownerQueryKey.setJoinCriteria(
          builder
              .getField("MBR2_EMPLOYEE.ADDR_ID")
              .equal(builder.getParameter("MBR1_ADDRESS.ADDRESS_ID")));
      descriptor.addQueryKey(ownerQueryKey);

    } else if (descriptor.getJavaClass().equals(Project.class)) {
      // Project's employees.
      ManyToManyQueryKey employesQueryKey = new ManyToManyQueryKey();
      employesQueryKey.setName("employees");
      employesQueryKey.setReferenceClass(Employee.class);
      builder = new ExpressionBuilder();
      employesQueryKey.setJoinCriteria(
          (builder
              .getParameter("MBR3_PROJECT.PROJ_ID")
              .equal(builder.getTable("MBR3_EMP_PROJ").getField("PROJECTS_PROJ_ID"))
              .and(
                  builder
                      .getTable("MBR3_EMP_PROJ")
                      .getField("EMPLOYEES_EMP_ID")
                      .equal(builder.getField("MBR2_EMPLOYEE.EMP_ID")))));
      descriptor.addQueryKey(employesQueryKey);
    }
  }