public void test() {
    // test readAll
    getSession().readAllObjects(Employee.class);
    getSession().getIdentityMapAccessor().initializeIdentityMap(Employee.class);

    // test readObject
    Employee employee =
        (Employee)
            getSession().readObject(Employee.class, new ExpressionBuilder().get("id").equal(99));

    // test delete with an employee read from the database
    employee = (Employee) getSession().readObject(Employee.class);
    try {
      getAbstractSession().deleteObject(employee);
    } catch (DatabaseException exc) {
      // if we get an integrity exception here, the query went to the DB and was not redirected
      redirectedDeleteObject = false;
    }

    UnitOfWork uow = getSession().acquireUnitOfWork();
    // test update with an employee read from the database
    employee = (Employee) uow.readObject(Employee.class);
    employee.setFirstName(employee.getFirstName() + "-changed");

    // insert an employee to test the insert behavior
    employee = new Employee();
    employee.setFirstName("Paul");
    employee.setLastName("Sheldon");
    uow.registerObject(employee);

    uow.commit();
  }
 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();
 }
  protected void test() {
    // Read in a Country.
    aCountry = (Country) uow.readObject(Country.class);
    oldName = aCountry.getName();

    // Update the country and commit. Nothing should be written to the db.
    uow.registerObject(aCountry);
    aCountry.setName(aCountry.getName() + " 22");
    uow.commit();
  }
  /** This method was created in VisualAge. */
  public void test() {
    // READ A GRASSHOPPER
    GrassHopper grassHopper = (GrassHopper) getSession().readObject(GrassHopper.class);

    // MODIFY THE GRASSHOPPER
    UnitOfWork uow = getSession().acquireUnitOfWork();
    GrassHopper tempGrassHopper = (GrassHopper) uow.registerObject(grassHopper);
    tempGrassHopper.setGh_maximumJump(new Integer(150));
    uow.commit();
  }
  protected void setup() {
    beginTransaction();

    // Acquire a unit of work with a class read-only.
    Vector readOnlyClasses = new Vector();
    readOnlyClasses.addElement(Country.class);
    uow = getSession().acquireUnitOfWork();
    uow.removeAllReadOnlyClasses();
    uow.addReadOnlyClasses(readOnlyClasses);
  }
  public void test() {
    UnitOfWork uow = getSession().acquireUnitOfWork();
    this.fieldOfficeClone = (FieldOffice) uow.readObject(FieldOffice.class);

    for (Iterator objects = this.fieldOfficeClone.getSalespeople().iterator();
        objects.hasNext(); ) {
      this.sales = (SalesPerson) objects.next();
      break;
    }
    this.fieldOfficeClone.getSalespeople().remove(this.sales);
  }
  public void reset() {
    // Compatibility for Oracle 9 and above is checked in the setup() method
    Oracle9Platform platform = (Oracle9Platform) getSession().getPlatform();
    //        platform.setPrintCalendarIntoTimestampTZ(this.oldPrintingValue);
    platform.setShouldBindAllParameters(this.oldBindingValue);

    // delete myself
    UnitOfWork uow = getSession().acquireUnitOfWork();
    uow.deleteObject(this);
    uow.commit();
  }
  /** This method was created in VisualAge. */
  protected void setup() {
    getAbstractSession().beginTransaction();

    // CREATE A GRASSHOPPER
    GrassHopper grassHopper = new GrassHopper();
    grassHopper.setIn_numberOfLegs(new Integer(6));
    grassHopper.setGh_maximumJump(new Integer(100));

    // ADD THE GRASSHOPPER TO THE DATABASE
    UnitOfWork uow = getSession().acquireUnitOfWork();
    uow.registerObject(grassHopper);
    uow.commit();
  }
 /** Insert address and then reset database/cache. */
 public void test() throws Exception {
   UnitOfWork uow = getSession().acquireUnitOfWork();
   Address address = new Address();
   address.setCity("NewCity");
   address.setPostalCode("N5J2N5");
   address.setProvince("ON");
   address.setStreet("1111 Mountain Blvd. Floor 13, suite 1");
   address.setCountry("Canada");
   uow.registerObject(address);
   uow.commit();
   getSession().getIdentityMapAccessor().initializeAllIdentityMaps();
   getSession().executeNonSelectingCall(new SQLCall("Delete from ADDRESS where CITY = 'NewCity'"));
 }
  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);
  }
Exemple #11
0
  public void doFilter(
      final ServletRequest servletRequest,
      final ServletResponse servletResponse,
      final FilterChain filterChain)
      throws IOException, ServletException {

    unitOfWork.begin();
    try {
      filterChain.doFilter(servletRequest, servletResponse);
    } finally {
      unitOfWork.end();
    }
  }
 public void test() {
   ReadAllQuery q = new ReadAllQuery();
   q.setBatchFetchType(batchType);
   q.setReferenceClass(Shipment.class);
   q.addBatchReadAttribute("employee");
   q.setSelectionCriteria(
       q.getExpressionBuilder()
           .get("employee")
           .get("address")
           .equal(q.getExpressionBuilder().getParameter("ADDRESS")));
   q.addArgument("ADDRESS");
   Vector r = new Vector();
   r.addElement("885 Meadowlands Dr.");
   UnitOfWork uow = getSession().acquireUnitOfWork();
   v = (java.util.Vector) uow.executeQuery(q, r);
 }
 private void commitTransaction(Session session) {
   if (unitOfWork.transactional()) {
     final Transaction txn = session.getTransaction();
     if (txn != null && txn.isActive()) {
       txn.commit();
     }
   }
 }
  public void test() {
    UnitOfWork uow = getSession().acquireUnitOfWork();
    Employee_XML emp =
        (Employee_XML)
            uow.readObject(
                Employee_XML.class, new ExpressionBuilder().get("firstName").equal("Frank"));
    Document resume = emp.resume;
    // System.out.println(resume);
    NodeList nodes = resume.getElementsByTagName("last-name");
    // System.out.println(nodes);
    Node lastName = nodes.item(0);
    Node lastNameText = lastName.getFirstChild();
    lastNameText.setNodeValue("Williams");
    emp.payroll_xml = "<payroll><salary>50000</salary><pay-period>weekly</pay-period></payroll>";

    uow.commit();
  }
  public void setup() {
    if (!(getSession().getPlatform() instanceof Oracle9Platform)) {
      throw new TestWarningException(
          "Test is only supported on Oracle9 platform and above, as TIMESTAMPTZ is used");
    }
    Oracle9Platform platform = (Oracle9Platform) getSession().getPlatform();

    //        this.oldPrintingValue = platform.getPrintCalendarIntoTimestampTZ();
    this.oldBindingValue = platform.shouldBindAllParameters();

    //        platform.setPrintCalendarIntoTimestampTZ(Boolean.TRUE);
    platform.setShouldBindAllParameters(true);

    // write myself out
    UnitOfWork uow = getSession().acquireUnitOfWork();
    uow.registerObject(this);
    uow.commit();
  }
Exemple #16
0
 public void perform(UnitOfWork work) throws Exception {
   Transaction transaction = session.beginTransaction();
   try {
     work.work(session);
     transaction.commit();
   } catch (Exception e) {
     transaction.rollback();
     throw e;
   }
 }
 public void test() {
   UnitOfWork uow = getSession().acquireUnitOfWork();
   employee = (Employee) uow.readObject(Employee.class);
   originalReadTime =
       ((AbstractSession) getSession())
           .getIdentityMapAccessorInstance()
           .getCacheKeyForObject(employee)
           .getReadTime();
   employee.setFirstName(employee.getFirstName() + "-mutated");
   try {
     Thread.sleep(100);
   } catch (InterruptedException exc) {
   }
   uow.commit();
   secondReadTime =
       getAbstractSession()
           .getIdentityMapAccessorInstance()
           .getCacheKeyForObject(employee)
           .getReadTime();
 }
 public void test() {
   UnitOfWork uow = getSession().acquireUnitOfWork();
   this.emp = Employee.example1();
   this.emp.asset1.asset = Vehicle.example1();
   uow.registerObject(this.emp);
   uow.commit();
   uow = getSession().acquireUnitOfWork();
   Employee empClone = (Employee) uow.registerObject(this.emp);
   Employee newClone = (Employee) empClone.clone();
   ((Vehicle) newClone.asset1.asset).make = "Beamer";
   uow.deepMergeClone(newClone);
   uow.commit();
   if (!((AbstractSession) getSession()).compareObjects(newClone, this.emp)) {
     throw new TestErrorException("Failed to merge the Variable 1 to 1 properly");
   }
 }
  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();
  }
 private void beginTransaction(Session session) {
   if (unitOfWork.transactional()) {
     session.beginTransaction();
   }
 }
 private void configureSession(Session session) {
   session.setDefaultReadOnly(unitOfWork.readOnly());
   session.setCacheMode(unitOfWork.cacheMode());
   session.setFlushMode(unitOfWork.flushMode());
 }
  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();
  }
  private void clearRepository() {
    // cleanup session cache
    if (!this.sessions.isEmpty()) {
      final Iterator<Entry<Session, UnitOfWork>> itr = this.sessions.entrySet().iterator();

      while (itr.hasNext()) {
        final Entry<Session, UnitOfWork> entry = itr.next();
        final Session session = entry.getKey();

        // rollback and close all leftover sessions
        if (session.isLive()) {
          final UnitOfWork uow = entry.getValue();
          LOGGER.debug(
              "LocalRepository.stopRepository: closing session for transaction {0}",
              uow.getName()); // $NON-NLS-1$

          // rollback any session that is in an incomplete state
          if (!uow.getState().isFinal()) {
            try {
              session.refresh(false);
            } catch (final RepositoryException e) {
              LOGGER.error(
                  "LocalRepository.stopRepository(): Exception rolling back transaction \"{0}\"", //$NON-NLS-1$
                  e, uow.getName());
            }
          }

          // does not hurt to call logout if already called
          session.logout();
        }

        itr.remove();
      }
    }

    RequestCallback callback =
        new RequestCallback() {

          /**
           * {@inheritDoc}
           *
           * @see
           *     org.komodo.repository.internal.ModeshapeEngineThread.RequestCallback#errorOccurred(java.lang.Throwable)
           */
          @Override
          public void errorOccurred(final Throwable error) {
            throw new RuntimeException(error);
          }

          /**
           * {@inheritDoc}
           *
           * @see
           *     org.komodo.repository.internal.ModeshapeEngineThread.RequestCallback#respond(java.lang.Object)
           */
          @Override
          public void respond(final Object results) {
            notifyObservers();
          }
        };

    KLog.getLogger().debug("LocalRepository.clearRepository() post clear request"); // $NON-NLS-1$
    this.engineThread.accept(new Request(RequestType.CLEAR, callback));
  }