/** INTERNAL: Select all objects for a concrete descriptor. */
  protected Object selectAllObjects(ReadAllQuery query) {
    ReadAllQuery concreteQuery = (ReadAllQuery) query.deepClone();
    concreteQuery.setReferenceClass(descriptor.getJavaClass());
    concreteQuery.setDescriptor(descriptor);

    // Avoid cloning the query again ...
    concreteQuery.setIsExecutionClone(true);
    concreteQuery
        .getExpressionBuilder()
        .setQueryClassAndDescriptor(descriptor.getJavaClass(), descriptor);

    // Update the selection criteria if needed as well and don't lose
    // the translation row.
    if (concreteQuery.getQueryMechanism().getSelectionCriteria() != null) {
      // make sure query builder is used for the selection criteria as deepClone will create
      // two separate builders.
      concreteQuery.setSelectionCriteria(
          concreteQuery
              .getQueryMechanism()
              .getSelectionCriteria()
              .rebuildOn(concreteQuery.getExpressionBuilder()));
      return query.getSession().executeQuery(concreteQuery, query.getTranslationRow());
    }

    return query.getSession().executeQuery(concreteQuery);
  }
 protected static boolean verifyField(
     AbstractSession session, DatabaseField field, ClassDescriptor descriptor) {
   boolean ok = true;
   if (field.equals(descriptor.getSequenceNumberField())) {
     ok = false;
     session
         .getIntegrityChecker()
         .handleError(
             DescriptorException.returningPolicyFieldNotSupported(field.getName(), descriptor));
   } else if (descriptor.hasInheritance()
       && field.equals(descriptor.getInheritancePolicy().getClassIndicatorField())) {
     ok = false;
     session
         .getIntegrityChecker()
         .handleError(
             DescriptorException.returningPolicyFieldNotSupported(field.getName(), descriptor));
   } else if (descriptor.usesOptimisticLocking()) {
     OptimisticLockingPolicy optimisticLockingPolicy = descriptor.getOptimisticLockingPolicy();
     if (optimisticLockingPolicy instanceof VersionLockingPolicy) {
       VersionLockingPolicy versionLockingPolicy = (VersionLockingPolicy) optimisticLockingPolicy;
       if (field.equals(versionLockingPolicy.getWriteLockField())) {
         ok = false;
         session
             .getIntegrityChecker()
             .handleError(
                 DescriptorException.returningPolicyFieldNotSupported(
                     field.getName(), descriptor));
       }
     }
   }
   return ok;
 }
  /** INTERNAL: Select one object of any concrete subclass. */
  public Object selectOneObjectUsingMultipleTableSubclassRead(ReadObjectQuery query)
      throws DatabaseException, QueryException {
    Object object = null;
    for (Enumeration childDescriptors = getChildDescriptors().elements();
        childDescriptors.hasMoreElements() && (object == null); ) {
      ClassDescriptor descriptor = (ClassDescriptor) childDescriptors.nextElement();
      object = descriptor.getInterfacePolicy().selectOneObject(query);
    }

    return object;
  }
 /** INTERNAL: Select one object of any concrete subclass. */
 protected Object selectOneObject(ReadObjectQuery query) throws DescriptorException {
   ReadObjectQuery concreteQuery = (ReadObjectQuery) query.clone();
   Class javaClass = descriptor.getJavaClass();
   concreteQuery.setReferenceClass(javaClass);
   concreteQuery.setDescriptor(descriptor);
   return query.getSession().executeQuery(concreteQuery, concreteQuery.getTranslationRow());
 }
  /**
   * INTERNAL: Select all objects for an interface descriptor. This is accomplished by selecting for
   * all of the concrete classes and then merging the objects.
   *
   * @return Vector containing all objects.
   * @exception DatabaseException - an error has occurred on the database.
   */
  public Object selectAllObjectsUsingMultipleTableSubclassRead(ReadAllQuery query)
      throws DatabaseException {
    org.eclipse.persistence.internal.queries.ContainerPolicy containerPolicy =
        query.getContainerPolicy();
    Object objects = containerPolicy.containerInstance(1);

    for (Enumeration childDescriptors = getChildDescriptors().elements();
        childDescriptors.hasMoreElements(); ) {
      ClassDescriptor descriptor = (ClassDescriptor) childDescriptors.nextElement();
      objects =
          containerPolicy.concatenateContainers(
              objects, descriptor.getInterfacePolicy().selectAllObjects(query));
    }

    return objects;
  }
  public void addDescriptors(DatabaseSession session) {
    // Oracle has bug in outjoins that require outerjoin of inheritance type.
    // This should really be handled by the platform during expression normalization...
    // Id for Entomologist can be negative (millis cast to int wraps...)
    project.getDescriptor(Entomologist.class).setIdValidation(IdValidation.NONE);

    session.addDescriptors(project);

    // For using read all subclasses views.
    DatabasePlatform platform = session.getLogin().getPlatform();
    if (platform.isOracle() || platform.isSybase()) {
      ClassDescriptor computerDescriptor = session.getDescriptor(Computer.class);
      ClassDescriptor vehicleDescriptor = session.getDescriptor(Vehicle.class);
      computerDescriptor.getInheritancePolicy().setReadAllSubclassesViewName("AllComputers");
      vehicleDescriptor.getInheritancePolicy().setReadAllSubclassesViewName("AllVehicles");
    }

    // Enable outer-join on AnimalMatt hierarchy.
    session
        .getDescriptor(Animal_Matt.class)
        .getInheritancePolicy()
        .setShouldOuterJoinSubclasses(true);
  }
 protected static boolean verifyFieldAndMapping(
     AbstractSession session,
     DatabaseField field,
     ClassDescriptor descriptor,
     DatabaseMapping mapping) {
   verifyField(session, field, descriptor);
   while (mapping.isAggregateObjectMapping()) {
     ClassDescriptor referenceDescriptor =
         ((AggregateObjectMapping) mapping).getReferenceDescriptor();
     mapping = referenceDescriptor.getObjectBuilder().getMappingForField(field);
     verifyFieldAndMapping(session, field, referenceDescriptor, mapping);
   }
   if (!mapping.isDirectToFieldMapping() && !mapping.isTransformationMapping()) {
     String mappingTypeName = Helper.getShortClassName(mapping);
     session
         .getIntegrityChecker()
         .handleError(
             DescriptorException.returningPolicyMappingNotSupported(
                 field.getName(), mappingTypeName, mapping));
     return false;
   } else {
     return true;
   }
 }
  /** INTERNAL: */
  public void initialize(AbstractSession session) {
    clearInitialization();
    main = new Collection[NUM_OPERATIONS][MAIN_SIZE];

    // The order of descriptor initialization guarantees initialization of Parent before children.
    // main array is copied from Parent's ReturningPolicy
    if (getDescriptor().isChildDescriptor()) {
      ClassDescriptor parentDescriptor =
          getDescriptor().getInheritancePolicy().getParentDescriptor();
      if (parentDescriptor.hasReturningPolicy()) {
        copyMainFrom(parentDescriptor.getReturningPolicy());
      }
    }

    if (!infos.isEmpty()) {
      Hashtable infoHashtable = removeDuplicateAndValidateInfos(session);
      Hashtable infoHashtableUnmapped = (Hashtable) infoHashtable.clone();
      for (Enumeration fields = getDescriptor().getFields().elements();
          fields.hasMoreElements(); ) {
        DatabaseField field = (DatabaseField) fields.nextElement();
        Info info = (Info) infoHashtableUnmapped.get(field);
        if (info != null) {
          infoHashtableUnmapped.remove(field);
          if (verifyFieldAndMapping(session, field)) {
            if (info.getField().getType() == null) {
              addMappedFieldToMain(field, info);
            } else {
              addMappedFieldToMain(info.getField(), info);
              fieldIsNotFromDescriptor(info.getField());
            }
          }
        }
      }

      if (!infoHashtableUnmapped.isEmpty()) {
        Enumeration fields = infoHashtableUnmapped.keys();
        while (fields.hasMoreElements()) {
          DatabaseField field = (DatabaseField) fields.nextElement();
          Info info = (Info) infoHashtableUnmapped.get(field);
          if (verifyField(session, field, getDescriptor())) {
            if (field.getType() != null) {
              addUnmappedFieldToMain(field, info);
              fieldIsNotFromDescriptor(field);
              session.log(
                  SessionLog.FINEST,
                  SessionLog.QUERY,
                  "added_unmapped_field_to_returning_policy",
                  info.toString(),
                  getDescriptor().getJavaClassName());
            } else {
              if (getDescriptor().isReturnTypeRequiredForReturningPolicy()) {
                session
                    .getIntegrityChecker()
                    .handleError(
                        DescriptorException.returningPolicyUnmappedFieldTypeNotSet(
                            field.getName(), getDescriptor()));
              }
            }
          }
        }
      }
    }

    initializeIsUsedToSetPrimaryKey();
  }