Package oracle.toplink.sessions

Examples of oracle.toplink.sessions.Session


    TopLinkTransactionObject txObject = (TopLinkTransactionObject) transaction;
    return (txObject.getSessionHolder() != null);
  }

  protected void doBegin(Object transaction, TransactionDefinition definition) {
    Session session = null;

    try {
      if (!definition.isReadOnly()) {
        logger.debug("Creating managed TopLink Session with active UnitOfWork for read-write transaction");
        session = getSessionFactory().createManagedClientSession();
      }
      else {
        logger.debug("Creating plain TopLink Session without active UnitOfWork for read-only transaction");
        session = getSessionFactory().createSession();
      }

      if (logger.isDebugEnabled()) {
        logger.debug("Opened new session [" + session + "] for TopLink transaction");
      }

      TopLinkTransactionObject txObject = (TopLinkTransactionObject) transaction;
      txObject.setSessionHolder(new SessionHolder(session));
      txObject.getSessionHolder().setSynchronizedWithTransaction(true);

      // Check isolation level.
      switch (definition.getIsolationLevel()) {
        case TransactionDefinition.ISOLATION_READ_UNCOMMITTED:
          // TODO warn when queries are executed without the conformResultsInUnitOfWork setting
          break;
        case TransactionDefinition.ISOLATION_REPEATABLE_READ:
          // TODO warn when queries are executed against a read-only Session
          break;
        case TransactionDefinition.ISOLATION_SERIALIZABLE:
          // TODO warn if the TransactionIsolation settings on the DatabaseLogin are wrong
          break;
      }

      // Register transaction timeout.
      int timeout = determineTimeout(definition);
      if (timeout != TransactionDefinition.TIMEOUT_DEFAULT) {
        txObject.getSessionHolder().setTimeoutInSeconds(timeout);
      }

      // Enforce early database transaction for TopLink read-write transaction,
      // unless we are explicitly told to use lazy transactions.
      if (!definition.isReadOnly() && !isLazyDatabaseTransaction()) {
        session.getActiveUnitOfWork().beginEarlyTransaction();
      }

      // Register the TopLink Session's JDBC Connection for the DataSource, if set.
      if (getDataSource() != null) {
        Connection con = getJdbcConnection(session);
View Full Code Here


    // Remove the JDBC connection holder from the thread, if exposed.
    if (txObject.hasConnectionHolder()) {
      TransactionSynchronizationManager.unbindResource(getDataSource());
    }

    Session session = txObject.getSessionHolder().getSession();
    if (logger.isDebugEnabled()) {
      logger.debug("Releasing TopLink Session [" + session + "] after transaction");
    }
    try {
      session.release();
    }
    catch (Throwable ex) {
      // just log it, to keep a transaction-related exception
      logger.debug("Could not release TopLink Session after transaction", ex);
    }
View Full Code Here

      throw new IllegalStateException("No TopLink Session bound to thread, " +
          "and configuration does not allow creation of non-transactional one here");
    }

    logger.debug("Creating TopLink Session");
    Session session = sessionFactory.createSession();

    if (TransactionSynchronizationManager.isSynchronizationActive()) {
      logger.debug("Registering new Spring transaction synchronization for new TopLink Session");
      // Use same Session for further TopLink actions within the transaction.
      // Thread object will get removed by synchronization at transaction completion.
View Full Code Here


  public Object execute(TopLinkCallback action) throws DataAccessException {
    Assert.notNull(action, "Callback object must not be null");

    Session session = SessionFactoryUtils.getSession(getSessionFactory(), this.allowCreate);
    try {
      return action.doInTopLink(session);
    }
    catch (TopLinkException ex) {
      throw convertTopLinkAccessException(ex);
View Full Code Here

*/
public class TopLinkTemplateTests extends TestCase {

  public void testTemplateNotAllowingCreate() {
    MockControl sessionControl = MockControl.createControl(Session.class);
    Session session = (Session) sessionControl.getMock();

    SessionFactory factory = new SingleSessionFactory(session);

    TopLinkTemplate template = new TopLinkTemplate();
    template.setAllowCreate(false);
View Full Code Here

    }
  }

  public void testTemplateWithCreate() {
    MockControl sessionControl = MockControl.createControl(Session.class);
    Session session = (Session) sessionControl.getMock();

    SessionFactory factory = new SingleSessionFactory(session);

    session.release();
    sessionControl.setVoidCallable(1);

    sessionControl.replay();

    TopLinkTemplate template = new TopLinkTemplate();
View Full Code Here

    sessionControl.verify();
  }

  public void testTemplateWithExistingSessionAndNoCreate() {
    MockControl sessionControl = MockControl.createControl(Session.class);
    Session session = (Session) sessionControl.getMock();

    SessionFactory factory = new SingleSessionFactory(session);

    sessionControl.replay();
View Full Code Here

    TransactionSynchronizationManager.unbindResource(factory);
  }

  public void testTemplateWithExistingSessionAndCreateAllowed() {
    MockControl sessionControl = MockControl.createControl(Session.class);
    Session session = (Session) sessionControl.getMock();

    SessionFactory factory = new SingleSessionFactory(session);

    sessionControl.replay();
View Full Code Here

    SessionBroker broker = new MockServerSessionBroker(client);
    SessionBrokerSessionFactory factory = new SessionBrokerSessionFactory(broker);

    assertEquals(client, factory.createSession());

    Session session = factory.createManagedClientSession();
    assertEquals(client, session.getActiveSession());
        assertNotNull(session.getActiveUnitOfWork());
    assertEquals(session.getActiveUnitOfWork(), session.getActiveUnitOfWork());
  }
View Full Code Here

    TransactionManager tm = (TransactionManager) tmControl.getMock();
    MockControl tx1Control = MockControl.createControl(javax.transaction.Transaction.class);
    javax.transaction.Transaction tx1 = (javax.transaction.Transaction) tx1Control.getMock();

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

    ut.getStatus();
    utControl.setReturnValue(Status.STATUS_NO_TRANSACTION, 1);
    ut.getStatus();
    utControl.setReturnValue(Status.STATUS_ACTIVE, 5);
    ut.begin();
    utControl.setVoidCallable(2);
    tm.suspend();
    tmControl.setReturnValue(tx1, 1);
    tm.resume(tx1);
    tmControl.setVoidCallable(1);
    ut.commit();
    utControl.setVoidCallable(2);

//    session1.hasExternalTransactionController();
//    session1Control.setReturnValue(true,1);
    session1.release();
    session1Control.setVoidCallable(1);
//    session2.hasExternalTransactionController();
//    session2Control.setReturnValue(true,1);
    session2.release();
    session2Control.setVoidCallable(1);

    utControl.replay();
    tmControl.replay();
    session1Control.replay();
View Full Code Here

TOP

Related Classes of oracle.toplink.sessions.Session

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.