Package org.g4studio.core.orm.xibatis.sqlmap.client

Examples of org.g4studio.core.orm.xibatis.sqlmap.client.SqlMapSession


    // 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

TOP

Related Classes of org.g4studio.core.orm.xibatis.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.