コード例 #1
0
  public boolean tryExistsCon(final BackendConnection conn, RouteResultsetNode node) {

    if (conn == null) {
      return false;
    }
    if (!conn.isFromSlaveDB() || node.canRunnINReadDB(this.autocommit)) {
      if (LOGGER.isDebugEnabled()) {
        LOGGER.debug("found connections in session to use " + conn + " for " + node);
      }
      conn.setAttachment(node);
      return true;
    } else {
      // slavedb connection and can't use anymore ,release it
      if (LOGGER.isDebugEnabled()) {
        LOGGER.debug(
            "release slave connection,can't be used in trasaction  " + conn + " for " + node);
      }
      releaseConnection(node, LOGGER.isDebugEnabled(), false);
    }
    return false;
  }
コード例 #2
0
  public void releaseConnection(RouteResultsetNode rrn, boolean debug, final boolean needRollback) {

    BackendConnection c = target.remove(rrn);
    if (c != null) {
      if (debug) {
        LOGGER.debug("release connection " + c);
      }
      if (c.getAttachment() != null) {
        c.setAttachment(null);
      }
      if (!c.isClosed()) {
        if (c.isAutocommit()) {
          c.release();
        } else if (needRollback) {
          c.setResponseHandler(new RollbackReleaseHandler());
          c.rollback();
        } else {
          c.release();
        }
      }
    }
  }