Package oracle.toplink.sessions

Examples of oracle.toplink.sessions.UnitOfWork


   * temporarily acquired UnitOfWork) and delegates to <code>doInUnitOfWork</code>.
   * @see #doInUnitOfWork(oracle.toplink.sessions.UnitOfWork)
   */
  public final Object doInTopLink(Session session) throws TopLinkException {
    // Fetch active UnitOfWork or acquire temporary UnitOfWork.
    UnitOfWork unitOfWork = session.getActiveUnitOfWork();
    boolean newUnitOfWork = false;
    if (unitOfWork == null) {
      unitOfWork = session.acquireUnitOfWork();
      newUnitOfWork = true;
    }

    // Perform callback operation, committing the UnitOfWork unless
    // it is the active UnitOfWork of an externally managed transaction.
    try {
      Object result = doInUnitOfWork(unitOfWork);
      if (newUnitOfWork) {
        unitOfWork.commit();
      }
      return result;
    }
    finally {
      if (newUnitOfWork) {
        unitOfWork.release();
      }
    }
  }
View Full Code Here


   * @see #readFromSession(oracle.toplink.sessions.Session)
   */
  public final Object doInTopLink(Session session) throws TopLinkException {
    Session sessionToUse = session;
    if (!this.enforceReadOnly) {
      UnitOfWork unitOfWork = session.getActiveUnitOfWork();
      if (unitOfWork != null) {
        sessionToUse = unitOfWork;
      }
    }
    return readFromSession(sessionToUse);
View Full Code Here

  public void testTransactionCommitWithReadOnly() {
    MockControl sessionControl = MockControl.createControl(Session.class);
    final Session session = (Session) sessionControl.getMock();
    MockControl uowControl = MockControl.createControl(UnitOfWork.class);
    UnitOfWork uow = (UnitOfWork) uowControl.getMock();

    final SessionFactory sf = new MockSessionFactory(session);

    session.release();
    sessionControl.setVoidCallable();
View Full Code Here

  public void testTransactionCommit() {
    MockControl sessionControl = MockControl.createControl(Session.class);
    final Session session = (Session) sessionControl.getMock();
    MockControl uowControl = MockControl.createControl(UnitOfWork.class);
    UnitOfWork uow = (UnitOfWork) uowControl.getMock();

    final SessionFactory sf = new MockSessionFactory(session);

    // during commit, TM must get the active UnitOfWork
    session.getActiveUnitOfWork();
    sessionControl.setReturnValue(uow, 2);
    uow.beginEarlyTransaction();
    uowControl.setVoidCallable(1);
    uow.commit();
    uowControl.setVoidCallable();
    // session should be released when it was bound explicitly by the TM
    session.release();
    sessionControl.setVoidCallable();
View Full Code Here

  public void testTransactionRollback() {
    MockControl sessionControl = MockControl.createControl(Session.class);
    final Session session = (Session) sessionControl.getMock();
    MockControl uowControl = MockControl.createControl(UnitOfWork.class);
    UnitOfWork uow = (UnitOfWork) uowControl.getMock();

    final SessionFactory sf = new MockSessionFactory(session);

    session.getActiveUnitOfWork();
    sessionControl.setReturnValue(uow, 1);
    uow.beginEarlyTransaction();
    uowControl.setVoidCallable(1);
    session.release();
    sessionControl.setVoidCallable(1);

    sessionControl.replay();
View Full Code Here

  public void testParticipatingTransactionWithCommit() {
    MockControl sessionControl = MockControl.createControl(Session.class);
    final Session session = (Session) sessionControl.getMock();
    MockControl uowControl = MockControl.createControl(UnitOfWork.class);
    UnitOfWork uow = (UnitOfWork) uowControl.getMock();

    final SessionFactory sf = new MockSessionFactory(session);

    session.getActiveUnitOfWork();
    sessionControl.setReturnValue(uow, 2);
    uow.beginEarlyTransaction();
    uowControl.setVoidCallable(1);
    uow.commit();
    uowControl.setVoidCallable();
    session.release();
    sessionControl.setVoidCallable();

    sessionControl.replay();
View Full Code Here

    final Session session1 = (Session) session1Control.getMock();
    MockControl session2Control = MockControl.createControl(Session.class);
    final Session session2 = (Session) session2Control.getMock();

    MockControl uow1Control = MockControl.createControl(UnitOfWork.class);
    UnitOfWork uow1 = (UnitOfWork) uow1Control.getMock();
    MockControl uow2Control = MockControl.createControl(UnitOfWork.class);
    UnitOfWork uow2 = (UnitOfWork) uow2Control.getMock();

    final MockSessionFactory sf = new MockSessionFactory(session1);

    session2.getActiveUnitOfWork();
    session2Control.setReturnValue(uow2, 2);
    uow2.beginEarlyTransaction();
    uow2Control.setVoidCallable(1);
    uow2.commit();
    uow2Control.setVoidCallable();
    session2.release();
    session2Control.setVoidCallable();

    session1.getActiveUnitOfWork();
View Full Code Here

  public void testParticipatingTransactionWithWithNotSupported() {
    MockControl sessionControl = MockControl.createControl(Session.class);
    final Session session = (Session) sessionControl.getMock();
    MockControl uowControl = MockControl.createControl(UnitOfWork.class);
    UnitOfWork uow = (UnitOfWork) uowControl.getMock();

    final SessionFactory sf = new MockSessionFactory(session);

    session.getActiveUnitOfWork();
    sessionControl.setReturnValue(uow, 2);
    uow.beginEarlyTransaction();
    uowControl.setVoidCallable(1);
    uow.commit();
    uowControl.setVoidCallable();
    session.release();
    sessionControl.setVoidCallable(2);

    sessionControl.replay();
View Full Code Here

  protected UnitOfWork getUnitOfWork() throws DaoException {

    // Get a UnitOfWork using the TransactionManager
    ToplinkDaoTransaction trans = (ToplinkDaoTransaction) daoManager
        .getTransaction(this);
    UnitOfWork uow = trans.getUnitOfWork();

    if ((uow == null) || !uow.isActive()) {

      throw new DaoException("No active unit of work.");

    }
View Full Code Here

TOP

Related Classes of oracle.toplink.sessions.UnitOfWork

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.