Package com.ibatis.sqlmap.client

Examples of com.ibatis.sqlmap.client.SqlMapSession


    conControl.setVoidCallable(1);
    dsControl.replay();
    conControl.replay();

    MockControl sessionControl = MockControl.createControl(SqlMapSession.class);
    final SqlMapSession session = (SqlMapSession) sessionControl.getMock();
    MockControl clientControl = MockControl.createControl(SqlMapClient.class);
    SqlMapClient client = (SqlMapClient) clientControl.getMock();
    client.openSession();
    clientControl.setReturnValue(session, 1);
    session.getCurrentConnection();
    sessionControl.setReturnValue(null, 1);
    session.setUserConnection(con);
    sessionControl.setVoidCallable(1);
    session.close();
    sessionControl.setVoidCallable(1);
    sessionControl.replay();
    clientControl.replay();

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


    final Connection con = (Connection) conControl.getMock();
    dsControl.replay();
    conControl.replay();

    MockControl sessionControl = MockControl.createControl(SqlMapSession.class);
    final SqlMapSession session = (SqlMapSession) sessionControl.getMock();
    MockControl clientControl = MockControl.createControl(SqlMapClient.class);
    SqlMapClient client = (SqlMapClient) clientControl.getMock();
    client.openSession();
    clientControl.setReturnValue(session, 1);
    session.getCurrentConnection();
    sessionControl.setReturnValue(con, 1);
    sessionControl.replay();
    clientControl.replay();

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

    MockControl conControl = MockControl.createControl(Connection.class);
    Connection con = (Connection) conControl.getMock();
    MockControl clientControl = MockControl.createControl(SqlMapClient.class);
    SqlMapClient client = (SqlMapClient) clientControl.getMock();
    MockControl sessionControl = MockControl.createControl(SqlMapSession.class);
    SqlMapSession session = (SqlMapSession) sessionControl.getMock();

    ds.getConnection();
    dsControl.setReturnValue(con, 1);
    con.close();
    conControl.setVoidCallable(1);
    client.getDataSource();
    clientControl.setReturnValue(ds, 2);
    client.openSession();
    clientControl.setReturnValue(session, 1);
    session.getCurrentConnection();
    sessionControl.setReturnValue(null, 1);
    session.setUserConnection(con);
    sessionControl.setVoidCallable(1);
    session.queryForObject("myStatement", "myParameter");
    sessionControl.setReturnValue("myResult", 1);
    session.close();
    sessionControl.setVoidCallable(1);

    dsControl.replay();
    conControl.replay();
    clientControl.replay();
View Full Code Here

    // we run against a TransactionAwareDataSourceProxy underneath, but unfortunately
    // we still need it to make iBATIS batch execution work properly: If iBATIS
    // doesn't recognize an existing transaction, it automatically executes the
    // batch for every single statement...

    SqlMapSession session = this.sqlMapClient.openSession();
    Connection ibatisCon = null;
    try {
      if (logger.isDebugEnabled()) {
        logger.debug("Opened SqlMapSession [" + session + "] for iBATIS operation");
      }
      Connection springCon = null;
      try {
        ibatisCon = session.getCurrentConnection();
        if (ibatisCon == null) {
          springCon = DataSourceUtils.getConnection(getDataSource());
          session.setUserConnection(springCon);
          if (logger.isDebugEnabled()) {
            logger.debug("Obtained JDBC Connection [" + springCon + "] for iBATIS operation");
          }
        }
        else {
          if (logger.isDebugEnabled()) {
            logger.debug("Reusing JDBC Connection [" + ibatisCon + "] for iBATIS operation");
          }
        }
        return action.doInSqlMapClient(session);
      }
      catch (SQLException ex) {
        throw getExceptionTranslator().translate("SqlMapClient operation", null, ex);
      }
      finally {
        DataSourceUtils.releaseConnection(springCon, getDataSource());
      }
    }
    finally {
      // Only close SqlMapSession if we know we've actually opened it
      // at the present level.
      if (ibatisCon == null) {
        session.close();
      }
    }
  }
View Full Code Here

    // we run against a TransactionAwareDataSourceProxy underneath, but unfortunately
    // we still need it to make iBATIS batch execution work properly: If iBATIS
    // doesn't recognize an existing transaction, it automatically executes the
    // batch for every single statement...

    SqlMapSession session = this.sqlMapClient.openSession();
    if (logger.isDebugEnabled()) {
      logger.debug("Opened SqlMapSession [" + session + "] for iBATIS operation");
    }
    Connection ibatisCon = null;

    try {
      Connection springCon = null;
      DataSource dataSource = getDataSource();
      boolean transactionAware = (dataSource instanceof TransactionAwareDataSourceProxy);

      // Obtain JDBC Connection to operate on...
      try {
        ibatisCon = session.getCurrentConnection();
        if (ibatisCon == null) {
          springCon = (transactionAware ?
              dataSource.getConnection() : DataSourceUtils.doGetConnection(dataSource));
          session.setUserConnection(springCon);
          if (logger.isDebugEnabled()) {
            logger.debug("Obtained JDBC Connection [" + springCon + "] for iBATIS operation");
          }
        }
        else {
          if (logger.isDebugEnabled()) {
            logger.debug("Reusing JDBC Connection [" + ibatisCon + "] for iBATIS operation");
          }
        }
      }
      catch (SQLException ex) {
        throw new CannotGetJdbcConnectionException("Could not get JDBC Connection", ex);
      }

      // Execute given callback...
      try {
        return action.doInSqlMapClient(session);
      }
      catch (SQLException ex) {
        throw getExceptionTranslator().translate("SqlMapClient operation", null, ex);
      }
      finally {
        try {
          if (springCon != null) {
            if (transactionAware) {
              springCon.close();
            }
            else {
              DataSourceUtils.doReleaseConnection(springCon, dataSource);
            }
          }
        }
        catch (Throwable ex) {
          logger.debug("Could not close JDBC Connection", ex);
        }
      }

      // Processing finished - potentially session still to be closed.
    }
    finally {
      // Only close SqlMapSession if we know we've actually opened it
      // at the present level.
      if (ibatisCon == null) {
        session.close();
      }
    }
  }
View Full Code Here

  public void testSessionUserConnection() throws SQLException {
    DataSource ds = sqlMap.getDataSource();
    Connection conn = ds.getConnection();
    ((SqlMapClientImpl) sqlMap).getTransactionManager().getTrasactionConfig().setDataSource(null);
    SqlMapSession session = sqlMap.openSession(conn);
    Account account = (Account) session.queryForObject("getAccountViaColumnName", new Integer(1));
    session.close();
    conn.close();
    assertAccount1(account);
    ((SqlMapClientImpl) sqlMap).getTransactionManager().getTrasactionConfig().setDataSource(ds);
  }
View Full Code Here

  public void testSessionUserConnectionFailures() throws SQLException {
    DataSource ds = sqlMap.getDataSource();
    Connection conn = ds.getConnection();
    ((SqlMapClientImpl) sqlMap).getTransactionManager().getTrasactionConfig().setDataSource(null);
    try {
      SqlMapSession session = sqlMap.openSession(conn);

      Exception expected = null;
      try {
        session.startTransaction();
      } catch (Exception e) {
        expected = e;
      }
      assertNotNull("Expected exception from startTransaction() was not detected.", expected);
      expected = null;

      Account account = (Account) session.queryForObject("getAccountViaColumnName", new Integer(1));
      session.close();
      conn.close();
      assertAccount1(account);
    } finally {
      ((SqlMapClientImpl) sqlMap).getTransactionManager().getTrasactionConfig().setDataSource(ds);
    }
View Full Code Here

      this.statementName = statementName;
    }

    public void run() {
      try {
        SqlMapSession session = sqlMap.openSession();
        List list = session.queryForList(statementName, null);
        int firstId = System.identityHashCode(list);
        list = session.queryForList(statementName, null);
        int secondId = System.identityHashCode(list);
        //assertEquals(firstId, secondId);
        results.put("id", new Integer(System.identityHashCode(list)));
        results.put("list", list);
        session.close();
      } catch (SQLException e) {
        throw new RuntimeException("Error.  Cause: " + e);
      }
    }
View Full Code Here

      throw new IllegalStateException(e.getMessage(), e);
    }
  }

  public SqlMapSession openSession(Connection conn) {
    SqlMapSession session = raw.openSession(conn);
    IbatisUtils.setClientImpl(session, this);
    return new SqlMapSessionWrapper(raw, session);
  }
View Full Code Here

    IbatisUtils.setClientImpl(session, this);
    return new SqlMapSessionWrapper(raw, session);
  }

  public SqlMapSession getSession() {
    SqlMapSession session = raw.getSession();
    IbatisUtils.setClientImpl(session, this);
    return new SqlMapSessionWrapper(raw, session);
  }
View Full Code Here

TOP

Related Classes of com.ibatis.sqlmap.client.SqlMapSession

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.