public void createTables(DatabaseSession session) {
    dropTableConstraints(session);
    new InheritanceTableCreator().replaceTables(session);

    SchemaManager schemaManager = new SchemaManager(session);
    if (session.getLogin().getPlatform().isOracle()) {
      schemaManager.replaceObject(Computer.oracleView());
      schemaManager.replaceObject(Vehicle.oracleView());
    } else if (session.getLogin().getPlatform().isSybase()) {
      schemaManager.replaceObject(Computer.sybaseView());
      schemaManager.replaceObject(Vehicle.sybaseView());
      // CREATE VIEW statement was added in MySQL 5.0.1.  Uncomment it when we support MySQL 5
      // } else if (session.getLogin().getPlatform().isMySQL()) {
      // schemaManager.replaceObject(Computer.sybaseView());
      // schemaManager.replaceObject(Vehicle.mySQLView());
    }
  }
  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);
  }
  public void setup() {
    oldSession = getSession();
    DatabaseLogin login = (DatabaseLogin) oldSession.getLogin().clone();
    if (login.getConnector() instanceof JNDIConnector) {
      login.setConnector(new JNDIConnector("jdbc/OracleCoreAQ"));
    } else {
      login.setUserName("aquser");
      login.setPassword("aquser");
    }
    DatabaseSession session = new Project(login).createDatabaseSession();
    session.setSessionLog(getSession().getSessionLog());
    try {
      session.login();
    } catch (Exception exception) {
      throw new TestProblemException(
          "Database needs to be setup for AQ, with the aquser", exception);
    }

    /**
     * to setup aquser, need to execute, 1 - login as sys (default password is password) - login as
     * scott tiger connect sys/password@james as sysdba
     *
     * <p>2 - might need to install aq procesures? - in sqlplus
     * - @@<orahome>\ora92\rdbms\admin\catproc.sql
     *
     * <p>3 - create a aq user (i.e aquser) grant connect, resource , aq_administrator_role to
     * aquser identified by aquser grant execute on dbms_aq to aquser grant execute on dbms_aqadm to
     * aquser grant execute on dbms_lock to aquser connect aquser/aquser
     */
    try {
      session.executeNonSelectingCall(
          new SQLCall("begin DBMS_AQADM.STOP_QUEUE (queue_name => 'order_queue'); end;"));
    } catch (Exception notThere) {
    }
    try {
      session.executeNonSelectingCall(
          new SQLCall("begin DBMS_AQADM.DROP_QUEUE (queue_name => 'order_queue'); end;"));
    } catch (Exception notThere) {
    }
    try {
      session.executeNonSelectingCall(
          new SQLCall(
              "begin DBMS_AQADM.DROP_QUEUE_TABLE (queue_table => 'order_queue_table'); end;"));
    } catch (Exception notThere) {
    }
    try {
      session.executeNonSelectingCall(
          new SQLCall("begin DBMS_AQADM.STOP_QUEUE (queue_name => 'order_topic'); end;"));
    } catch (Exception notThere) {
    }
    try {
      session.executeNonSelectingCall(
          new SQLCall("begin DBMS_AQADM.DROP_QUEUE (queue_name => 'order_topic'); end;"));
    } catch (Exception notThere) {
    }
    try {
      session.executeNonSelectingCall(
          new SQLCall(
              "begin DBMS_AQADM.DROP_QUEUE_TABLE (queue_table => 'order_topic_table'); end;"));
    } catch (Exception notThere) {
    }
    try {
      session.executeNonSelectingCall(
          new SQLCall("begin DBMS_AQADM.STOP_QUEUE (queue_name => 'raw_order_queue'); end;"));
    } catch (Exception notThere) {
    }
    try {
      session.executeNonSelectingCall(
          new SQLCall("begin DBMS_AQADM.DROP_QUEUE (queue_name => 'raw_order_queue'); end;"));
    } catch (Exception notThere) {
    }
    try {
      session.executeNonSelectingCall(
          new SQLCall(
              "begin DBMS_AQADM.DROP_QUEUE_TABLE (queue_table => 'raw_order_queue_table'); end;"));
    } catch (Exception notThere) {
    }

    session.executeNonSelectingCall(
        new SQLCall(
            "begin DBMS_AQADM.CREATE_QUEUE_TABLE (queue_table => 'order_queue_table', multiple_consumers => FALSE, queue_payload_type => 'SYS.AQ$_JMS_TEXT_MESSAGE'); end;"));
    session.executeNonSelectingCall(
        new SQLCall(
            "begin DBMS_AQADM.CREATE_QUEUE (queue_name => 'order_queue', queue_table => 'order_queue_table'); end;"));
    session.executeNonSelectingCall(
        new SQLCall("begin DBMS_AQADM.START_QUEUE (queue_name => 'order_queue'); end;"));

    session.executeNonSelectingCall(
        new SQLCall(
            "begin DBMS_AQADM.CREATE_QUEUE_TABLE (queue_table => 'order_topic_table', multiple_consumers => TRUE, queue_payload_type => 'SYS.AQ$_JMS_TEXT_MESSAGE'); end;"));
    session.executeNonSelectingCall(
        new SQLCall(
            "begin DBMS_AQADM.CREATE_QUEUE (queue_name => 'order_topic', queue_table => 'order_topic_table'); end;"));
    session.executeNonSelectingCall(
        new SQLCall("begin DBMS_AQADM.START_QUEUE (queue_name => 'order_topic'); end;"));

    session.executeNonSelectingCall(
        new SQLCall(
            "begin DBMS_AQADM.CREATE_QUEUE_TABLE (queue_table => 'raw_order_queue_table', multiple_consumers => FALSE, queue_payload_type => 'RAW'); end;"));
    session.executeNonSelectingCall(
        new SQLCall(
            "begin DBMS_AQADM.CREATE_QUEUE (queue_name => 'raw_order_queue', queue_table => 'raw_order_queue_table'); end;"));
    session.executeNonSelectingCall(
        new SQLCall("begin DBMS_AQADM.START_QUEUE (queue_name => 'raw_order_queue'); end;"));

    session =
        XMLProjectReader.read(
                "org/eclipse/persistence/testing/models/order/eis/aq/order-project.xml",
                getClass().getClassLoader())
            .createDatabaseSession();
    session.setSessionLog(getSession().getSessionLog());

    // String url = oldSession.getLogin().getConnectionString();
    String url;
    try {
      url = ((AbstractSession) getSession()).getAccessor().getConnection().getMetaData().getURL();
    } catch (java.sql.SQLException se) {
      se.printStackTrace();
      throw new TestErrorException("There is SQLException");
    }
    EISLogin eisLogin = (EISLogin) session.getDatasourceLogin();
    eisLogin.setConnectionSpec(new AQEISConnectionSpec());
    eisLogin.setProperty(AQEISConnectionSpec.URL, url);
    eisLogin.setUserName("aquser");
    eisLogin.setPassword("aquser");
    session.login();

    getExecutor().setSession(session);
  }
  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();
  }
 public void test() {
   DatabaseSession session = (DatabaseSession) getSession();
   session.getEventManager().addListener(new StoredProcedureOutputListener(this.events));
   session.writeObject(this.employee);
 }