Package oracle.toplink.sessions

Examples of oracle.toplink.sessions.Session


    sessionControl.verify();
  }

  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();
    uowControl.replay();
View Full Code Here


    uowControl.verify();
  }

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

    final SessionFactory sf = new MockSessionFactory(session);

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

    sessionControl.replay();

    TopLinkTransactionManager tm = new TopLinkTransactionManager(sf);
View Full Code Here

    sessionControl.verify();
  }

  public void testParticipatingTransactionWithRollbackOnly() {
    MockControl sessionControl = MockControl.createControl(Session.class);
    final Session session = (Session) sessionControl.getMock();
    final SessionFactory sf = new MockSessionFactory(session);

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

    sessionControl.replay();

    TopLinkTransactionManager tm = new TopLinkTransactionManager(sf);
View Full Code Here

    sessionControl.verify();
  }

  public void testParticipatingTransactionWithWithRequiresNew() {
    MockControl session1Control = MockControl.createControl(Session.class);
    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();
    session1Control.setReturnValue(uow1, 2);
    uow1.beginEarlyTransaction();
View Full Code Here

    uow2Control.verify();
  }

  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();
    uowControl.replay();
View Full Code Here

    uowControl.verify();
  }

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

    final SessionFactory sf = new MockSessionFactory(session);

    // not a new transaction, won't start a new one
    session.release();
    sessionControl.setVoidCallable();

    sessionControl.replay();

    PlatformTransactionManager tm = new TopLinkTransactionManager(sf);
View Full Code Here

    sessionControl.verify();
  }

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

    sessionControl.replay();
    uowControl.replay();
View Full Code Here

   */
  @SuppressWarnings("unchecked")
  public ValueList getValueList(String name, ValueListInfo info) {
    int numberPerPage = 0;
    Object tplReturn = null;
    Session tplSession = null;
    List list = null;
    ValueList returnValueList = null;
    Vector<String> params = null;
    String tmpStr = null;

    try {
      if (LOGGER.isDebugEnabled()) {
        LOGGER.debug("ToplinkAdapter.getValueList : '" + name
            + "' start...");
      }

      /* Check factory object validity */
      if (this.sessionFactory == null) {
        throw new IllegalArgumentException(
            "Toplink session factory can't be null !");
      }

      /* Configure ValueListInfo object */
      // Sorting
      if (info.getSortingColumn() == null) {
        info.setPrimarySortColumn(getDefaultSortColumn());
        info.setPrimarySortDirection(getDefaultSortDirectionInteger());
        if (LOGGER.isDebugEnabled()) {
          LOGGER.debug("The default sort column '"
              + getDefaultSortColumn() + "' with direction '"
              + getDefaultSortDirectionInteger() + "' was  set.");
        }
      }

      // Paging
      numberPerPage = info.getPagingNumberPer();
      if (numberPerPage == Integer.MAX_VALUE) {
        numberPerPage = getDefaultNumberPerPage();
        info.setPagingNumberPer(numberPerPage);
        if (LOGGER.isDebugEnabled()) {
          LOGGER.debug("The paging number per page '" + numberPerPage
              + "' was  set.");
        }
      }

      /* Extract data from database */
      // Check type of extraction : DatabaseQuery or NamedQuery
      if ((this.databaseQuery == null)
          && (this.namedQuery == null || "".equals(this.namedQuery))) {
        throw new IllegalArgumentException(
            "One type of database operation must be setted : 'databaseQuery' and 'namedQuery' can't both be null !");
      }
      // Check parameter validty
      if (this.domainClass == null || "".equals(this.domainClass)) {
        throw new IllegalArgumentException(
            "'domainClass' can't be null !");
      }

      // Acquire Toplink session
      tplSession = this.sessionFactory.createSession();
      if (LOGGER.isDebugEnabled()) {
        LOGGER.debug("Toplink session '" + tplSession.getName()
            + "' acquired !");
      }

      // Data extraction using DatabaseQuery
      if (this.databaseQuery != null) {
        tplReturn = tplSession.executeQuery(this.databaseQuery);
      }
      // Data extraction using NamedQuery
      else if (this.namedQuery != null && !"".equals(this.namedQuery)) {
        // We check if NamedQuery use parameter
        if (!this.namedQueryUseParameters) {
          tplReturn = tplSession.executeQuery(this.namedQuery);
        } else {
          // We check to see if NamedQuery parameters are passed by
          // HTTP request instead of XML configuration
          // HTTP request parameter have higher priority on XML
          // configuration. Parameters defined in XML configuration as
          // cons�dered as default parameter if no parameter is find
          // in HTTP request
          if ((info.getFilters().get("namedQueryParameters") != null)
              && !"".equals(info.getFilters().get(
                  "namedQueryParameters"))) {
            tmpStr = (String) info.getFilters().get(
                "namedQueryParameters");
          } else {
            tmpStr = (this.namedQueryParameters == null) ? ""
                : this.namedQueryParameters;
          }
          // Build parameters array
          params = new Vector<String>();
          if (tmpStr.indexOf("|") != -1) {
            for (String str : tmpStr.split("\\|")) {
              params.add(str);
            }
          } else {
            params.add(tmpStr);
          }
          tplReturn = tplSession.executeQuery(this.namedQuery, Class
              .forName(this.domainClass.trim()), params);
        }
      }
      if (LOGGER.isDebugEnabled()) {
        LOGGER.debug("Database request executed !");
      }

      // Process output object
      // The database request have extracted a collection of object
      if (tplReturn instanceof Vector) {
        list = (Vector) tplReturn;
      } else {
        // The database request have extracted a single object or nothing
        list = new Vector();
        if (tplReturn != null) {
          list.add(tplReturn);
        }
      }
      info.setTotalNumberOfEntries(list.size());
      if (LOGGER.isDebugEnabled()) {
        LOGGER.debug("Output object processed !");
      }

      // Prepare returned object
      returnValueList = new DefaultListBackedValueList(list, info);
      if (LOGGER.isDebugEnabled()) {
        LOGGER.debug("Retrieved list was wrapped in valuelist, info = "
            + info);
      }

    } catch (Exception e) {
      // Log exception
      e.printStackTrace();
      LOGGER.error(e);
    } finally {
      // Release session
      if (tplSession != null) {
        tplSession.release();
        if (LOGGER.isDebugEnabled()) {
          LOGGER.debug("Toplink session '" + tplSession.getName()
              + "' released !");
        }
      }
      if (LOGGER.isDebugEnabled()) {
        LOGGER.debug("ToplinkAdapter.getValueList : '" + name
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.