Ejemplo n.º 1
0
  public void populate(DatabaseSession session) {
    Employee instance;
    PopulationManager manager = PopulationManager.getDefaultManager();

    instance = Employee.example1();
    session.writeObject(instance);
    manager.registerObject(instance, "example1");
    manager.registerObject(instance.computer, "example1");
    manager.registerObject(instance.shipments.firstElement(), "example1");
    manager.registerObject(
        ((Shipment) instance.shipments.firstElement()).orders.firstElement(), "example1");

    instance = Employee.example2();
    session.writeObject(instance);
    manager.registerObject(instance, "example2");
    manager.registerObject(instance.computer, "example2");
    manager.registerObject(instance.shipments.firstElement(), "example2");
    manager.registerObject(
        ((Shipment) instance.shipments.firstElement()).orders.firstElement(), "example2");

    instance = Employee.example3();
    session.writeObject(instance);
    manager.registerObject(instance, "example3");
    manager.registerObject(instance.computer, "example3");
    manager.registerObject(instance.shipments.firstElement(), "example3");
    manager.registerObject(
        ((Shipment) instance.shipments.firstElement()).orders.firstElement(), "example3");
  }
  public void addDescriptors(DatabaseSession session) {
    session.logout();
    super.addDescriptors(session);

    // Force re-initialize.
    session.login();
  }
  /**
   * The setup is done as a test, both to record its failure, and to allow execution in the server.
   */
  public void testSetup() {
    clearCache();
    // get session to start setup
    DatabaseSession session = JUnitTestCase.getServerSession();

    // create a new EmployeePopulator
    EmployeePopulator employeePopulator = new EmployeePopulator();

    RelationshipsExamples relationshipExamples = new RelationshipsExamples();

    new AdvancedTableCreator().replaceTables(session);

    new RelationshipsTableManager().replaceTables(session);

    // initialize the global comparer object
    comparer = new JUnitDomainObjectComparer();

    // set the session for the comparer to use
    comparer.setSession((AbstractSession) session.getActiveSession());

    // Populate the advanced model
    employeePopulator.buildExamples();
    // populate the relationships model and persist as well
    relationshipExamples.buildExamples(session);

    // Persist the advanced model examples in the database
    employeePopulator.persistExample(session);
  }
  /** Return a connected session using the default login. */
  public DatabaseSession login() {
    DatabaseSession session;

    session = new DatabaseSessionImpl(project);
    session.login();

    return session;
  }
 public void reset() {
   // Remove the transport added for this test
   DatabaseSession session = (DatabaseSession) getSession();
   UnitOfWork uow = session.acquireUnitOfWork();
   ExpressionBuilder transport = new ExpressionBuilder();
   Expression expression = transport.get("id").equal(transportId);
   uow.deleteAllObjects(uow.readAllObjects(Transport.class, expression));
   uow.commit();
 }
  public void test() {
    transport = Transport.example6();
    UnitOfWork uow = getSession().acquireUnitOfWork();
    uow.registerObject(transport);
    uow.commit();

    transportId = transport.getId();

    DatabaseSession session = (DatabaseSession) getSession();
    ExpressionBuilder exp = new ExpressionBuilder();
    Expression expression = exp.get("id").equal(transportId);
    transport = (Transport) session.readObject(Transport.class, expression);
  }
  /**
   * This method will instantiate all of the example instances and insert them into the database
   * using the given session.
   */
  public void populate(DatabaseSession session) {
    UnitOfWork unitOfWork = session.acquireUnitOfWork();

    unitOfWork.registerObject(Dist_Employee.example1());
    unitOfWork.registerObject(Company.example1());
    unitOfWork.commit();
  }
  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) {
    if (project == null) {
      project =
          XMLProjectReader.read(
              "org/eclipse/persistence/testing/models/employee/eis/xmlfile/employee-ns-project.xml",
              getClass().getClassLoader());
    }

    session.addDescriptors(project);
  }
 public void updateProject(Project project, Session session) {
   verifySession(session);
   if (generator == null) {
     generator =
         new StoredProcedureGeneratorForAdapter(new SchemaManager((DatabaseSession) session));
     generator.setUseTableNames(true);
   }
   removeOptimisticLocking(project);
   ((DatabaseSession) session).addDescriptors(project);
   generator.generateStoredProceduresDefinitionsForProject(project);
   generator.amendDescriptors();
 }
  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 addDescriptors(DatabaseSession session) {
    if (project == null) {
      if (getAdapter().isOriginalSetupRequired()) {
        try {
          // If called twice, method TestSystem.addDescriptors(Session)
          // may behave wrong during the second call
          // (typically because during the second call project value is no longer null,
          // which causes problems in case more than one project is used).
          // Therefore another instance of TestSystem is created - not to spoil the original.
          TestSystem tempTestSystem = getTestSystem().getClass().newInstance();
          tempTestSystem.addDescriptors(session);
          try {
            tempTestSystem.createTables(session);
          } catch (Exception ex2) {
            throw new TestProblemException(
                "Exception thrown by "
                    + Helper.getShortClassName(tempTestSystem)
                    + ".createTables() ",
                ex2);
          }
        } catch (Exception ex1) {
          throw new TestProblemException(
              "Failed to create an instance of " + getTestSystem().getClass() + " ", ex1);
        }
      }
      // This trick stores all descriptors used by testSystem into project
      DatabaseSession dummyDatabaseSession =
          new Project((Login) session.getLogin().clone()).createDatabaseSession();
      getTestSystem().addDescriptors(dummyDatabaseSession);
      project = dummyDatabaseSession.getProject();

      getAdapter().updateProject(project, session);
    }
    (session).addDescriptors(project);
    afterAddDescriptors(session, getTestSystem());
  }
  /** Also creates the procs. */
  public void createTables(DatabaseSession session) {
    super.createTables(session);
    org.eclipse.persistence.internal.databaseaccess.DatabasePlatform platform =
        session.getLogin().getPlatform();
    SchemaManager schema = new SchemaManager((session));

    if (platform.isSQLServer()) {}

    if (platform.isSybase() || platform.isSQLAnywhere()) {}
    if (platform.isOracle()) {

      schema.replaceObject(buildOracleStoredProcedureInsertPolicyHolders());
      schema.replaceObject(buildOracleStoredProcedureReadFromPolicyHolders());
      schema.replaceObject(buildOracleStoredProcedureDeletePolicyHolders());
    }
    if (platform.isDB2()) {}
  }
  public void test() {
    Vector sessions = new Vector();

    try {
      for (int i = 0; i < stressLevel; i++) {
        Session session =
            new Project(getSession().getDatasourceLogin().clone()).createDatabaseSession();
        ((DatabaseSession) session).login();
        sessions.addElement(session);
      }
      getSession().readObject(Address.class);
    } finally {
      for (Enumeration sessionEnum = sessions.elements(); sessionEnum.hasMoreElements(); ) {
        ((DatabaseSession) sessionEnum.nextElement()).logout();
      }
    }
    getSession().readObject(Address.class);
  }
  public void populate(DatabaseSession session) {
    MapPopulator system = new MapPopulator();
    UnitOfWork unitOfWork = session.acquireUnitOfWork();

    system.buildExamples();
    Vector allObjects = new Vector();
    PopulationManager.getDefaultManager()
        .addAllObjectsForClass(EntityEntity1MMapHolder.class, allObjects);
    PopulationManager.getDefaultManager()
        .addAllObjectsForClass(EntityDirectMapHolder.class, allObjects);
    PopulationManager.getDefaultManager()
        .addAllObjectsForClass(EntityAggregateMapHolder.class, allObjects);
    PopulationManager.getDefaultManager()
        .addAllObjectsForClass(DirectEntityU1MMapHolder.class, allObjects);
    PopulationManager.getDefaultManager()
        .addAllObjectsForClass(DirectEntityMapHolder.class, allObjects);
    PopulationManager.getDefaultManager()
        .addAllObjectsForClass(DirectEntity1MMapHolder.class, allObjects);
    PopulationManager.getDefaultManager()
        .addAllObjectsForClass(DirectDirectMapHolder.class, allObjects);
    PopulationManager.getDefaultManager()
        .addAllObjectsForClass(DirectAggregateMapHolder.class, allObjects);
    PopulationManager.getDefaultManager()
        .addAllObjectsForClass(AggregateEntityU1MMapHolder.class, allObjects);
    PopulationManager.getDefaultManager()
        .addAllObjectsForClass(AggregateEntityMapHolder.class, allObjects);
    PopulationManager.getDefaultManager()
        .addAllObjectsForClass(AggregateEntity1MMapHolder.class, allObjects);
    PopulationManager.getDefaultManager()
        .addAllObjectsForClass(AggregateDirectMapHolder.class, allObjects);
    PopulationManager.getDefaultManager()
        .addAllObjectsForClass(AggregateAggregateMapHolder.class, allObjects);
    PopulationManager.getDefaultManager()
        .addAllObjectsForClass(EntityEntityMapHolder.class, allObjects);
    PopulationManager.getDefaultManager()
        .addAllObjectsForClass(EntityEntityU1MMapHolder.class, allObjects);

    unitOfWork.registerAllObjects(allObjects);
    unitOfWork.commit();
  }
  public void test() {
    EmployeeProjectForIntegrityChecker project = new EmployeeProjectForIntegrityChecker();
    project.setDatasourceLogin(getSession().getDatasourceLogin());
    DatabaseSession session =
        new Project(getSession().getDatasourceLogin()).createDatabaseSession();
    session.dontLogMessages();
    boolean caughtError = false;
    try {
      session.login();
      session.setIntegrityChecker(new IntegrityChecker());
      session.getIntegrityChecker().dontCatchExceptions();
      session.addDescriptors(project);
    } catch (DescriptorException exception) {
      caughtError = true;
    } finally {
      session.logout();
    }

    if (!caughtError) {
      throw new TestErrorException("Test is Failed, no exception was thrown");
    }
  }
Ejemplo n.º 17
0
  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);
  }
 /** Dropping old foreign keys from schema change. */
 @Override
 public void replaceTables(DatabaseSession session) {
   if (session.getPlatform().supportsUniqueKeyConstraints()
       && !session.getPlatform().requiresUniqueConstraintCreationOnTableCreate()) {
     try {
       if (session.getPlatform().isMySQL()) {
         session.executeNonSelectingSQL(
             "Alter table JPA_OR_SPARK_PLUG drop foreign key JPA_OR_SPARK_PLUG_ENGINE_ID");
         session.executeNonSelectingSQL(
             "Alter table JPA_OR_VEHICLE drop foreign key FK_JPA_OR_VEHICLE_ENGINE_ID");
         session.executeNonSelectingSQL(
             "Alter table JPA_OR_VEHICLE drop foreign key FK_JPA_OR_VEHICLE_CHASSIS_ID");
         session.executeNonSelectingSQL(
             "Alter table JPA_OR_WHEEL drop foreign key FK_JPA_OR_WHEEL_WHEELRIM_ID");
         session.executeNonSelectingSQL(
             "Alter table JPA_OR_WHEEL drop foreign key FK_JPA_OR_WHEEL_CHASSIS_ID");
         session.executeNonSelectingSQL(
             "Alter table JPA_OR_WHEEL_NUT drop foreign key FK_JPA_OR_WHEEL_NUT_WHEEL_ID");
       } else {
         session.executeNonSelectingSQL(
             "Alter table JPA_OR_SPARK_PLUG drop constraint JPA_OR_SPARK_PLUG_ENGINE_ID");
         session.executeNonSelectingSQL(
             "Alter table JPA_OR_VEHICLE drop constraint FK_JPA_OR_VEHICLE_ENGINE_ID");
         session.executeNonSelectingSQL(
             "Alter table JPA_OR_VEHICLE drop constraint FK_JPA_OR_VEHICLE_CHASSIS_ID");
         session.executeNonSelectingSQL(
             "Alter table JPA_OR_WHEEL drop constraint FK_JPA_OR_WHEEL_WHEELRIM_ID");
         session.executeNonSelectingSQL(
             "Alter table JPA_OR_WHEEL drop constraint FK_JPA_OR_WHEEL_CHASSIS_ID");
         session.executeNonSelectingSQL(
             "Alter table JPA_OR_WHEEL_NUT drop constraint FK_JPA_OR_WHEEL_NUT_WHEEL_ID");
       }
     } catch (Exception ignore) {
     }
   }
   super.replaceTables(session);
 }
 public void addDescriptors(DatabaseSession session) {
   session.addDescriptors(project);
 }
  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();
  }
Ejemplo n.º 21
0
  @Override
  public void buildSessions() {
    XRDynamicClassLoader xrdecl = new XRDynamicClassLoader(parentClassLoader);
    DatasourceLogin login = new DatabaseLogin();
    login.setUserName(username);
    login.setPassword(password);
    ((DatabaseLogin) login).setConnectionString(url);
    ((DatabaseLogin) login).setDriverClassName(DATABASE_PLATFORM);
    Platform platform = builder.getDatabasePlatform();
    ConversionManager conversionManager = platform.getConversionManager();
    if (conversionManager != null) {
      conversionManager.setLoader(xrdecl);
    }
    login.setDatasourcePlatform(platform);
    ((DatabaseLogin) login).bindAllParameters();
    ((DatabaseLogin) login).setUsesStreamsForBinding(true);

    Project orProject = null;
    if (DBWS_OR_STREAM.size() != 0) {
      MetadataProcessor processor =
          new MetadataProcessor(
              new XRPersistenceUnitInfo(xrdecl),
              new DatabaseSessionImpl(login),
              xrdecl,
              false,
              true,
              false,
              false,
              false,
              null,
              null);
      processor.setMetadataSource(
          new JPAMetadataSource(xrdecl, new StringReader(DBWS_OR_STREAM.toString())));
      PersistenceUnitProcessor.processORMetadata(
          processor, true, PersistenceUnitProcessor.Mode.ALL);
      processor.addNamedQueries();
      orProject = processor.getProject().getProject();
    } else {
      orProject = new Project();
    }
    orProject.setName(builder.getProjectName().concat(OR_PRJ_SUFFIX));
    orProject.setDatasourceLogin(login);
    DatabaseSession databaseSession = orProject.createDatabaseSession();
    if ("off".equalsIgnoreCase(builder.getLogLevel())) {
      databaseSession.dontLogMessages();
    } else {
      databaseSession.setLogLevel(
          AbstractSessionLog.translateStringToLoggingLevel(builder.getLogLevel()));
    }
    xrService.setORSession(databaseSession);
    orProject.convertClassNamesToClasses(xrdecl);

    Project oxProject = null;
    Map<String, OXMMetadataSource> metadataMap = new HashMap<String, OXMMetadataSource>();
    StreamSource xml = new StreamSource(new StringReader(DBWS_OX_STREAM.toString()));
    try {
      JAXBContext jc = JAXBContext.newInstance(XmlBindingsModel.class);
      Unmarshaller unmarshaller = jc.createUnmarshaller();

      JAXBElement<XmlBindingsModel> jaxbElt = unmarshaller.unmarshal(xml, XmlBindingsModel.class);
      XmlBindingsModel model = jaxbElt.getValue();
      for (XmlBindings xmlBindings : model.getBindingsList()) {
        metadataMap.put(xmlBindings.getPackageName(), new OXMMetadataSource(xmlBindings));
      }
    } catch (JAXBException jaxbex) {
      jaxbex.printStackTrace();
    }

    Map<String, Map<String, OXMMetadataSource>> properties =
        new HashMap<String, Map<String, OXMMetadataSource>>();
    properties.put(JAXBContextProperties.OXM_METADATA_SOURCE, metadataMap);
    try {
      org.eclipse.persistence.jaxb.dynamic.DynamicJAXBContext jCtx =
          org.eclipse.persistence.jaxb.dynamic.DynamicJAXBContextFactory.createContextFromOXM(
              parentClassLoader, properties);
      oxProject = jCtx.getXMLContext().getSession(0).getProject();
    } catch (JAXBException e) {
      e.printStackTrace();
    }
    ((XMLLogin) oxProject.getDatasourceLogin()).setPlatformClassName(DOM_PLATFORM_CLASSNAME);
    ((XMLLogin) oxProject.getDatasourceLogin()).setEqualNamespaceResolvers(false);

    prepareDescriptors(oxProject, orProject, xrdecl);
    ProjectHelper.fixOROXAccessors(orProject, oxProject);
    xrService.setORSession(databaseSession);
    xrService.setXMLContext(new XMLContext(oxProject));
    xrService.setOXSession(xrService.getXMLContext().getSession(0));
  }
 public void test() {
   DatabaseSession session = (DatabaseSession) getSession();
   session.getEventManager().addListener(new StoredProcedureOutputListener(this.events));
   session.writeObject(this.employee);
 }
Ejemplo n.º 23
0
 /** Test database session creation. */
 @Test
 public void testDatabaseSession() throws Exception {
   DatabaseSession session = SessionHelper.createDatabaseSession(AQTestSuite.project);
   session.logout();
 }
 public void addDescriptors(DatabaseSession session) {
   if (project == null) {
     project = new MapCollectionsProject();
   }
   session.addDescriptors(project);
 }
 public void addDescriptors(DatabaseSession session) {
   session.logMessage("Project is from generated code");
   (session).addDescriptors(project);
 }
  public void populate(DatabaseSession session) {
    Object instance;
    PopulationManager manager = PopulationManager.getDefaultManager();

    instance = LockInCache.example1();
    session.writeObject(instance);
    manager.registerObject(instance, "Cache example1");

    instance = LockInCache.example2();
    session.writeObject(instance);
    manager.registerObject(instance, "Cache example2");

    instance = LockInCache.example3();
    session.writeObject(instance);
    manager.registerObject(instance, "Cache example3");

    instance = LockInObject.example1();
    session.writeObject(instance);
    manager.registerObject(instance, "Object example1");

    instance = LockInObject.example2();
    session.writeObject(instance);
    manager.registerObject(instance, "Object example2");

    instance = LockInObject.example3();
    session.writeObject(instance);
    manager.registerObject(instance, "Object example3");

    instance = TimestampInCache.example1();
    session.writeObject(instance);
    manager.registerObject(instance, "Cache TS example1");

    instance = TimestampInCache.example2();
    session.writeObject(instance);
    manager.registerObject(instance, "Cache TS example2");

    instance = TimestampInCache.example3();
    session.writeObject(instance);
    manager.registerObject(instance, "Cache TS example3");

    instance = TimestampInObject.example1();
    session.writeObject(instance);
    manager.registerObject(instance, "Object TS example1");

    instance = TimestampInObject.example2();
    session.writeObject(instance);
    manager.registerObject(instance, "Object TS example2");

    instance = TimestampInObject.example3();
    session.writeObject(instance);
    manager.registerObject(instance, "Object TS example3");

    instance = ChangedRow.example1();
    session.writeObject(instance);
    manager.registerObject(instance, "ChangedRow example1");

    instance = ChangedRow.example2();
    session.writeObject(instance);
    manager.registerObject(instance, "ChangedRow example2");

    instance = ChangedRow.example3();
    session.writeObject(instance);
    manager.registerObject(instance, "ChangedRow example3");

    instance = TimestampInAggregateObject.example1();
    session.writeObject(instance);
    manager.registerObject(instance, "Aggregate Object TS example1");

    instance = TimestampInAggregateObject.example2();
    session.writeObject(instance);
    manager.registerObject(instance, "Aggregate Object TS example2");

    instance = TimestampInAggregateObject.example3();
    session.writeObject(instance);
    manager.registerObject(instance, "Aggregate Object TS example3");

    instance = LockInAggregateObject.example1();
    session.writeObject(instance);
    manager.registerObject(instance, "Lock Object TS example1");

    instance = LockInAggregateObject.example2();
    session.writeObject(instance);
    manager.registerObject(instance, "Lock Object TS example2");

    instance = LockInAggregateObject.example3();
    session.writeObject(instance);
    manager.registerObject(instance, "Lock Object TS example3");

    UnitOfWork uow = session.acquireUnitOfWork();
    instance = uow.registerObject(RockBand.example1());
    manager.registerObject(instance, "RockBand example1");
    instance = uow.registerObject(RockBand.example2());
    manager.registerObject(instance, "RockBand example2");
    uow.commit();
  }