/**
   * INTERNAL: Check to see if a custom query should be used for this query. This is done before the
   * query is copied and prepared/executed. null means there is none.
   */
  protected DatabaseQuery checkForCustomQuery(
      AbstractSession session, AbstractRecord translationRow) {
    checkDescriptor(session);

    // check if user defined a custom query
    DescriptorQueryManager queryManager = this.descriptor.getQueryManager();
    if ((!isCallQuery()) // this is not a hand-coded (custom SQL, SDK etc.) call
        && (!isUserDefined()) // and this is not a user-defined query (in the query manager)
        && queryManager
            .hasInsertQuery()) { // and there is a user-defined query (in the query manager)
      return queryManager.getInsertQuery();
    }

    return null;
  }
 public void buildQueryTimeOutQuery(DescriptorQueryManager queryManager) {
   DataReadQuery namedQuery = new DataReadQuery();
   namedQuery.setSQLString(
       "SELECT SUM(e.EMP_ID) from EMPLOYEE e , EMPLOYEE b, EMPLOYEE c, EMPLOYEE d, EMPLOYEE f, EMPLOYEE g, EMPLOYEE h");
   namedQuery.setQueryTimeout(1);
   queryManager.addQuery("queryTimeOutQuery", namedQuery);
 }
 public void buildJoinSubclassesQuery(DescriptorQueryManager queryManager) {
   ReadAllQuery namedQuery =
       new ReadAllQuery(org.eclipse.persistence.testing.models.employee.domain.Project.class);
   namedQuery.useCursoredStream();
   namedQuery.setShouldOuterJoinSubclasses(true);
   queryManager.addQuery("joinSubclassesQuery", namedQuery);
 }
  protected void buildInitialProject() {
    initialProject = new EmployeeProject();
    Map<Class, ClassDescriptor> descriptors = initialProject.getDescriptors();

    // Amend the employee descriptor
    ClassDescriptor employeeDescriptor = descriptors.get(Employee.class);
    DescriptorQueryManager queryManager = employeeDescriptor.getQueryManager();

    queryManager.addQuery("PersistenceTestGetEqual", buildPersistenceTestGetEqualQuery());
    queryManager.addQuery("PersistenceTestAnyOfEqual", buildPersistenceTestAnyOfEqualQuery());
    queryManager.addQuery(
        "PersistenceTestGetAllowingNullEqual", buildPersistenceTestGetAllowingNullEqualQuery());
    queryManager.addQuery(
        "PersistenceTestAnyOfAllowingNoneEqual", buildPersistenceTestAnyOfAllowingNoneEqualQuery());
    queryManager.addQuery(
        "PersistenceTestGetGreaterThan", buildPersistenceTestGetGreaterThanQuery());
    queryManager.addQuery(
        "PersistenceTestGetGreaterThanEqual", buildPersistenceTestGetGreaterThanEqualQuery());
    queryManager.addQuery("PersistenceTestGetIsNull", buildPersistenceTestGetIsNullQuery());
    queryManager.addQuery(
        "PersistenceTestGetEqualIgnoringCase", buildPersistenceTestGetEqualIgnoringCaseQuery());
    queryManager.addQuery("PersistenceTestGetLessThan", buildPersistenceTestGetLessThanQuery());
    queryManager.addQuery(
        "PersistenceTestGetLessThanEqual", buildPersistenceTestGetLessThanEqualQuery());
    queryManager.addQuery("PersistenceTestGetLike", buildPersistenceTestGetLikeQuery());
    queryManager.addQuery("PersistenceTestGetNot", buildPersistenceTestGetNotQuery());
    queryManager.addQuery("PersistenceTestGetNotEqual", buildPersistenceTestGetNotEqualQuery());
    queryManager.addQuery("PersistenceTestGetNotLike", buildPersistenceTestGetNotLikeQuery());
    queryManager.addQuery("PersistenceTestGetNotNull", buildPersistenceTestGetNotNullQuery());
    queryManager.addQuery(
        "PersistenceTestEmptyStringAndNull", buildPersistenceTestEmptyStringAndNull());
    queryManager.addQuery(
        "PersistenceTestGreaterThanEqualDate", buildPersistenceTestGreaterThanEqualDateQuery());

    // ReportQuery
    queryManager.addQuery("AddAttributeReportQuery", buildAddAttributeReportQueryTest());
    queryManager.addQuery("AddAverageReportQuery", buildAddAverageReportQueryTest());
    queryManager.addQuery("AddCountReportQuery", buildAddCountReportQueryTest());
    queryManager.addQuery("AddFunctionItemReportQuery", buildAddFunctionItemReportQueryTest());
    queryManager.addQuery("AddGroupingReportQuery", buildAddGroupingReportQueryTest());
    queryManager.addQuery("AddItemReportQuery", buildAddItemReportQueryTest());
    queryManager.addQuery("AddMaximumReportQuery", buildAddMaximumReportQueryTest());
    queryManager.addQuery("AddMinimumReportQuery", buildAddMinimumReportQueryTest());
    queryManager.addQuery(
        "AddStandardDeviationReportQuery", buildAddStandardDeviationReportQueryTest());
    queryManager.addQuery("AddSumReportQuery", buildAddSumReportQueryTest());
    queryManager.addQuery("AddVarianceReportQuery", buildAddVarianceReportQueryTest());
    queryManager.addQuery("AddJoinedObjectLevelReadQuery", buildAddJoinedReportQueryTest());
    queryManager.addQuery("AddOrderingReadAllQuery", buildAddOrderingReportQueryTest());
    queryManager.addQuery("AddBatchReadReadAllQuery", buildAddBatchReadReportQueryTest());

    // Query options
    buildMemoryQueryReturnConfirmedQuery(queryManager);
    buildMemoryQueryThrowExceptionQuery(queryManager);
    buildMemoryQueryReturnNotConfirmedQuery(queryManager);
    buildMemoryQueryTriggerIndirectionQuery(queryManager);
    buildCacheQueryResultsQuery(queryManager);
    buildRefreshIdentityMapResultsQuery(queryManager);
    buildMaxRowsQuery(queryManager);
    buildFirstResultQuery(queryManager);
    buildQueryTimeOutQuery(queryManager);
    buildUseDistinctQuery(queryManager);
    buildDoNotUseDistinctQuery(queryManager);
    buildShouldPrepareQuery(queryManager);
    buildReadOnlyQuery(queryManager);

    // Amend the project descriptor
    ClassDescriptor projectDescriptor =
        descriptors.get(org.eclipse.persistence.testing.models.employee.domain.Project.class);
    // Postgres throws an error if you try to set the timeout.
    if (!TestExecutor.getDefaultExecutor().getSession().getPlatform().isPostgreSQL()) {
      projectDescriptor.getQueryManager().setQueryTimeout(QUERY_MANAGER_TIMEOUT);
    }
    projectDescriptor.setCacheSynchronizationType(
        ClassDescriptor
            .SEND_NEW_OBJECTS_WITH_CHANGES); // Setting added for validation only - no tests
                                             // currently run against this setting - Bug 3599101
    projectDescriptor.setCacheInvalidationPolicy(
        new NoExpiryCacheInvalidationPolicy()); // Setting added for validation only - no tests
                                                // currently run against this setting - Bug 3599101

    // Query options
    buildJoinSubclassesQuery(projectDescriptor.getQueryManager());

    // Setting invalidation policies
    employeeDescriptor.setCacheInvalidationPolicy(new TimeToLiveCacheInvalidationPolicy(10000000));
    descriptors
        .get(Address.class)
        .setCacheInvalidationPolicy(new TimeToLiveCacheInvalidationPolicy(10000000));
    descriptors
        .get(PhoneNumber.class)
        .setCacheInvalidationPolicy(new TimeToLiveCacheInvalidationPolicy(10000000));

    GregorianCalendar calendar = new GregorianCalendar();
    calendar.add(Calendar.HOUR_OF_DAY, 2);
    descriptors
        .get(LargeProject.class)
        .setCacheInvalidationPolicy(
            new DailyCacheInvalidationPolicy(
                calendar.get(Calendar.HOUR_OF_DAY),
                calendar.get(Calendar.MINUTE),
                calendar.get(Calendar.SECOND),
                calendar.get(Calendar.MILLISECOND)));
    descriptors
        .get(SmallProject.class)
        .setCacheInvalidationPolicy(
            new DailyCacheInvalidationPolicy(
                calendar.get(Calendar.HOUR_OF_DAY),
                calendar.get(Calendar.MINUTE),
                calendar.get(Calendar.SECOND),
                calendar.get(Calendar.MILLISECOND)));
  }
 public void buildShouldPrepareQuery(DescriptorQueryManager queryManager) {
   ReadObjectQuery namedQuery = new ReadObjectQuery(Employee.class);
   queryManager.addQuery("shouldPrepareQuery", namedQuery);
 }
 public void buildDoNotUseDistinctQuery(DescriptorQueryManager queryManager) {
   ReadAllQuery namedQuery = new ReadAllQuery(Employee.class);
   namedQuery.setDistinctState((short) 2);
   queryManager.addQuery("doNotUseDistinctQuery", namedQuery);
 }
 public void buildFirstResultQuery(DescriptorQueryManager queryManager) {
   ReadAllQuery namedQuery = new ReadAllQuery(Employee.class);
   namedQuery.setFirstResult(2);
   queryManager.addQuery("firstResultQuery", namedQuery);
 }
 public void buildMaxRowsQuery(DescriptorQueryManager queryManager) {
   ReadAllQuery namedQuery = new ReadAllQuery(Employee.class);
   namedQuery.setMaxRows(4);
   queryManager.addQuery("maxRowsQuery", namedQuery);
 }
 public void buildReadOnlyQuery(DescriptorQueryManager queryManager) {
   ReadObjectQuery namedQuery = new ReadObjectQuery(Employee.class);
   namedQuery.setIsReadOnly(true);
   queryManager.addQuery("readOnlyQuery", namedQuery);
 }
 public void buildRefreshIdentityMapResultsQuery(DescriptorQueryManager queryManager) {
   ReadObjectQuery namedQuery = new ReadObjectQuery(Employee.class);
   namedQuery.setShouldRefreshIdentityMapResult(true);
   queryManager.addQuery("refreshIdentityMapResultsQuery", namedQuery);
 }
 public void buildCacheQueryResultsQuery(DescriptorQueryManager queryManager) {
   ReadObjectQuery namedQuery = new ReadObjectQuery(Employee.class);
   namedQuery.setQueryResultsCachePolicy(new QueryResultsCachePolicy());
   queryManager.addQuery("cacheQueryResultsQuery", namedQuery);
 }
 public void buildMemoryQueryTriggerIndirectionQuery(DescriptorQueryManager queryManager) {
   ReadAllQuery namedQuery = new ReadAllQuery(Employee.class);
   namedQuery.setInMemoryQueryIndirectionPolicy(new InMemoryQueryIndirectionPolicy(1));
   queryManager.addQuery("memoryQueryTriggerIndirectionQuery", namedQuery);
 }
 public void buildMemoryQueryThrowExceptionQuery(DescriptorQueryManager queryManager) {
   ReadObjectQuery namedQuery = new ReadObjectQuery(Employee.class);
   namedQuery.setInMemoryQueryIndirectionPolicy(new InMemoryQueryIndirectionPolicy(0));
   queryManager.addQuery("memoryQueryThrowExceptionQuery", namedQuery);
 }
 public void addNamedQueries(DescriptorQueryManager queryManager) {
   queryManager.addQuery("PersistenceTestEqualCalendar", buildPersistenceTestEqualCalendarQuery());
   queryManager.addQuery("PersistenceTestEqualJavaDate", buildPersistenceTestEqualJavaDateQuery());
   queryManager.addQuery("PersistenceTestEqualSqlDate", buildPersistenceTestEqualSqlDateQuery());
   queryManager.addQuery("PersistenceTestEqualTime", buildPersistenceTestEqualTimeQuery());
   queryManager.addQuery(
       "PersistenceTestEqualTimestamp", buildPersistenceTestEqualTimestampQuery());
   queryManager.addQuery(
       "PersistenceTestEqualBigDecimal", buildPersistenceTestEqualBigDecimalQuery());
   queryManager.addQuery(
       "PersistenceTestEqualBigInteger", buildPersistenceTestEqualBigIntegerQuery());
   queryManager.addQuery("PersistenceTestEqualPChar", buildPersistenceTestEqualPCharQuery());
   queryManager.addQuery(
       "PersistenceTestEqualCharacter", buildPersistenceTestEqualCharacterQuery());
   queryManager.addQuery(
       "PersistenceTestEqualPCharArray", buildPersistenceTestEqualPCharArrayQuery());
   queryManager.addQuery("PersistenceTestEqualPByte", buildPersistenceTestEqualPByteQuery());
   queryManager.addQuery(
       "PersistenceTestEqualPByteArray", buildPersistenceTestEqualPByteArrayQuery());
   queryManager.addQuery("PersistenceTestEqualByte", buildPersistenceTestEqualByteQuery());
 }