/**
   * INTERNAL: Execute the query. Get the rows and build the object from the rows.
   *
   * @exception DatabaseException - an error has occurred on the database
   * @return java.lang.Object collection of objects resulting from execution of query.
   */
  protected Object executeObjectLevelReadQuery() throws DatabaseException {
    Object result = null;

    if (getContainerPolicy().overridesRead()) {
      return getContainerPolicy().execute();
    }

    if (this.descriptor.isDescriptorForInterface()) {
      Object returnValue =
          this.descriptor.getInterfacePolicy().selectAllObjectsUsingMultipleTableSubclassRead(this);
      setExecutionTime(System.currentTimeMillis());
      return returnValue;
    }

    List rows = getQueryMechanism().selectAllRows();
    setExecutionTime(System.currentTimeMillis());

    // If using 1-m joins, must set all rows.
    if (hasJoining() && this.joinedAttributeManager.isToManyJoin()) {
      this.joinedAttributeManager.setDataResults(rows, this.session);
    }

    if (this.session.isUnitOfWork()) {
      result =
          registerResultInUnitOfWork(
              rows, (UnitOfWorkImpl) this.session, this.translationRow, true); //
    } else {
      result = getContainerPolicy().containerInstance(rows.size());
      this.descriptor.getObjectBuilder().buildObjectsInto(this, rows, result);
    }

    if (this.shouldIncludeData) {
      ComplexQueryResult complexResult = new ComplexQueryResult();
      complexResult.setResult(result);
      complexResult.setData(rows);
      return complexResult;
    }

    // Add the other (already registered) results and return them.
    if (getDescriptor().hasTablePerClassPolicy()) {
      result =
          containerPolicy.concatenateContainers(
              result,
              getDescriptor()
                  .getTablePerClassPolicy()
                  .selectAllObjectsUsingMultipleTableSubclassRead(this));
    }

    return result;
  }
  public void populate(DatabaseSession session) {
    PopulationManager manager = PopulationManager.getDefaultManager();

    Cat cat = Cat.example1();
    session.writeObject(cat);
    manager.registerObject(cat, "catExample1");

    Dog dog = Dog.example1();
    session.writeObject(dog);
    manager.registerObject(dog, "dogExample1");

    cat = Cat.example2();
    session.writeObject(cat);
    manager.registerObject(cat, "catExample2");

    dog = Dog.example2();
    session.writeObject(dog);
    manager.registerObject(dog, "dogExample2");

    cat = Cat.example3();
    session.writeObject(cat);
    manager.registerObject(cat, "catExample3");

    dog = Dog.example3();
    session.writeObject(dog);
    manager.registerObject(dog, "dogExample3");

    Company company = Company.example1();
    session.writeObject(company);
    manager.registerObject(company, "example1");

    manager.registerObject(((Vector) company.getVehicles().getValue()).firstElement(), "example1");

    company = Company.example2();
    session.writeObject(company);
    manager.registerObject(company, "example2");

    company = Company.example3();
    session.writeObject(company);
    manager.registerObject(company, "example3");

    Person person = Person.example1();
    session.writeObject(person);
    manager.registerObject(person, "example1");

    // populate the data for duplicate field testing
    session.writeObject(A_King2.exp1());
    session.writeObject(A_King2.exp2());
    session.writeObject(A_1_King2.exp3());
    session.writeObject(A_2_King2.exp4());
    session.writeObject(A_2_1_King2.exp5());

    UnitOfWork unitOfWork = session.acquireUnitOfWork();
    person = Person.example2();
    unitOfWork.registerObject(person);
    unitOfWork.commit();
    manager.registerObject(person, "example2");
    manager.registerObject(person.bestFriend, "example5");
    manager.registerObject(person.representitive, "example4");

    person = Person.example3();
    session.writeObject(person);
    manager.registerObject(person, "example3");

    Computer computer = Computer.example1();
    session.writeObject(computer);
    manager.registerObject(computer, "example1");

    computer = Computer.example2();
    session.writeObject(computer);
    manager.registerObject(computer, "example2");

    computer = Computer.example3();
    session.writeObject(computer);
    manager.registerObject(computer, "example3");

    computer = Computer.example4();
    session.writeObject(computer);
    manager.registerObject(computer, "example4");

    computer = Computer.example5();
    session.writeObject(computer);
    manager.registerObject(computer, "example5");

    JavaProgrammer JP = JavaProgrammer.example1();
    session.writeObject(JP);
    manager.registerObject(JP, "example1");

    JP = JavaProgrammer.example2();
    session.writeObject(JP);
    manager.registerObject(JP, "example2");

    // Added to test bug 3019934.
    unitOfWork = session.acquireUnitOfWork();
    Alligator alligator = new Alligator();
    alligator.setFavoriteSwamp("Florida");
    alligator.setLatestVictim(JavaProgrammer.steve());
    unitOfWork.registerObject(alligator);
    manager.registerObject(alligator, "example1");
    unitOfWork.commit();

    // Added to test bug 6111278

    unitOfWork = session.acquireUnitOfWork();
    Entomologist bugguy = new Entomologist();
    bugguy.setId((int) System.currentTimeMillis());
    bugguy.setName("Gary");
    bugguy = (Entomologist) unitOfWork.registerObject(bugguy);
    Insect insect = new GrassHopper();
    insect.setIn_numberOfLegs(4);
    insect.setEntomologist(bugguy);
    bugguy.getInsectCollection().add(insect);
    unitOfWork.commit();
  }