/**
   * protected Hashtable[] doJDBC(String dbname_, String sql_, // Connection con, boolean goNative_,
   * long offset_, int maxsize_, boolean robotquery_, Connection con) throws SQLException
   */
  public void init() throws Exception {

    try {
      if (!outcon) {
        tx = TransactionManager.getTransaction();
        if (tx == null) {
          con = SQLUtil.getSQLManager().requestConnection(dbname); // 事务无处理,批处理的默认事务处理需要设定
          if (needTransaction) {
            this.oldautocommit = con.getAutoCommit();
            con.setAutoCommit(false);
          }
        } else {
          try {
            con = tx.getConnection(dbname);
          } catch (TransactionException e) {
            try {
              tx.setRollbackOnly();
            } catch (Exception ei) {

            }
            throw e;
          }
        }
      } else {
        if (this.con != null && this.con instanceof TXConnection) {
          tx = TransactionManager.getTransaction();
        }
      }
    } catch (Exception e) {
      throw e;
    }
  }
Exemple #2
0
  /**
   * 同步当前缓冲中存放的对应表的最大值与数据库表中最大值
   *
   * @throws SQLException
   */
  protected void synchroDB(Connection con) throws SQLException {
    //		Connection con = null;
    Statement stmt = null;
    ResultSet rs = null;
    JDBCTransaction tx = null;
    boolean outcon = true;

    try {
      if (con == null) {
        tx = TransactionManager.getTransaction();
        if (tx == null) {
          con = SQLManager.getInstance().requestConnection(dbname);
        } else {
          con = tx.getConnection(dbname);
        }
        outcon = false;
      }
      stmt = con.createStatement();

      rs = stmt.executeQuery(maxSql);
      long temp = 0;
      if (rs.next()) {
        temp = rs.getLong(1);
      }
      if (temp >= this.curValue) {
        curValue = temp + 1;
      }

      //			else if(temp < this.curValue )
      //			{
      //
      //				curValue = temp + 1;
      //
      //				System.out.println("curValue=========:" + curValue);
      //			}
    } catch (SQLException e) {
      //			log.error("同步当前缓冲中表[" + tableName + "]的主键[" + primaryKeyName
      //					+ "]最大值与数据库该表主键最大值失败,系统采用自动产生的主键:" + e.getMessage());
      throw new NestedSQLException(
          "同步当前缓冲中表[" + tableName + "]的主键[" + primaryKeyName + "]最大值与数据库该表主键最大值失败,系统采用自动产生的主键:", e);
    } catch (TransactionException e) {

      //			e.printStackTrace();
      //			log.error("同步当前缓冲中表[" + tableName + "]的主键[" + primaryKeyName
      //					+ "]最大值与数据库该表主键最大值失败,系统采用自动产生的主键:" + e.getMessage());
      throw new NestedSQLException(
          "同步当前缓冲中表[" + tableName + "]的主键[" + primaryKeyName + "]最大值与数据库该表主键最大值失败,系统采用自动产生的主键:", e);
      //			throw new SQLException(e.getMessage());
    } finally {
      if (con != null) {
        JDBCPool.closeResources(stmt, rs);
        if (!outcon) {

          if (tx == null) {
            JDBCPool.closeConnection(con);
          }
        }
      }
      con = null;
    }
  }