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

   * client Session created for this factory.
   * @see #createClientSession()
   */
  public Session createManagedClientSession() throws TopLinkException {
    logger.debug("Creating managed TopLink client Session");
    Session target = createClientSession();
    return (Session) Proxy.newProxyInstance(target.getClass().getClassLoader(),
        new Class[] {Session.class}, new ManagedClientInvocationHandler(target));
  }
View Full Code Here

   * @see #getMasterSession()
   * @see oracle.toplink.sessions.Session#getActiveSession()
   * @see oracle.toplink.sessions.Session#getActiveUnitOfWork()
   */
  public Session createTransactionAwareSession(SessionFactory sessionFactory) throws TopLinkException {
    Session target = getMasterSession();
    return (Session) Proxy.newProxyInstance(
        target.getClass().getClassLoader(), new Class[] {Session.class},
        new TransactionAwareInvocationHandler(sessionFactory, target));
  }
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

    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);

      // 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) {
        Session mostSpecificSession = (!definition.isReadOnly() ? session.getActiveUnitOfWork() : session);
        Connection con = getJdbcConnection(mostSpecificSession);
        if (con != null) {
          ConnectionHolder conHolder = new ConnectionHolder(con);
          if (timeout != TransactionDefinition.TIMEOUT_DEFAULT) {
            conHolder.setTimeoutInSeconds(timeout);
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

  }


  public Object invoke(MethodInvocation methodInvocation) throws Throwable {
    boolean existingTransaction = false;
    Session session = SessionFactoryUtils.getSession(getSessionFactory(), true);
    if (TransactionSynchronizationManager.hasResource(getSessionFactory())) {
      logger.debug("Found thread-bound Session for TopLink interceptor");
      existingTransaction = true;
    }
    else {
View Full Code Here

   * Determines the Session to work on (either the active UnitOfWork
   * or the plain Session) and delegates to <code>readFromSession</code>.
   * @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;
      }
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.