⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 cmsconnection.java

📁 java 编写的程序
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
         */
    public Statement createStatement(int resultSetType, int resultSetConcurrency)
                throws SQLException {
          checkIsClosed();
          String key = C_SIMPLE_STATEMENT_KEY + ":" + resultSetType + ":" + resultSetConcurrency;
          if(!m_statementPool.containsKey(key)) {
            // the pool contains not this statement - create it
            m_statementPool.put(key,
              new CmsStatement(m_originalConnection.createStatement(resultSetType,
              resultSetConcurrency ), this));
          }
          // return the simple statement
          return (Statement) m_statementPool.get(key);
    }

    public java.sql.Statement createStatement(int param, int param1, int param2) throws java.sql.SQLException {
          checkIsClosed();
          String key = C_SIMPLE_STATEMENT_KEY + ":" + param + ":" + param1 + ":" + param2;
          if(!m_statementPool.containsKey(key)) {
            // the pool contains not this statement - create it
            m_statementPool.put(key,
              new CmsStatement(m_originalConnection.createStatement(param, param1, param2), this));
          }
          // return the simple statement
          return (Statement) m_statementPool.get(key);        
    }
        
        /**
         * Creates a new CmsPreparedStatement from the pool.
         */
    public PreparedStatement prepareStatement(String sql) throws SQLException {
          checkIsClosed();
          String key = sql;
          if(!m_statementPool.containsKey(key)) {
            // the pool contains not this statement - create it
            m_statementPool.put(key,
              new CmsPreparedStatement(m_originalConnection.prepareStatement(sql), this));
          }
          return (PreparedStatement) m_statementPool.get(key);
    }

        /**
         * Creates a new CmsPreparedStatement from the pool.
         */
    public PreparedStatement prepareStatement(String sql, int a, int b) throws SQLException {
          checkIsClosed();
          String key = sql + ":" + a + ":" + b;
          if(!m_statementPool.containsKey(key)) {
            // the pool contains not this statement - create it
            m_statementPool.put(key,
              new CmsPreparedStatement(m_originalConnection.prepareStatement(sql, a, b), this));
          }
          return (PreparedStatement) m_statementPool.get(key);
    }
    
    public java.sql.PreparedStatement prepareStatement(String str, int param) throws java.sql.SQLException {
          checkIsClosed();
          String key = str + ":" + param;
          if(!m_statementPool.containsKey(key)) {
            // the pool does not contain this statement - create it
            m_statementPool.put(key,
              new CmsPreparedStatement(m_originalConnection.prepareStatement(str, param), this));
          }
          return (PreparedStatement) m_statementPool.get(key);
    }
    
    public java.sql.PreparedStatement prepareStatement(String str, int[] values) throws java.sql.SQLException {
          checkIsClosed();
          String key = str + ":" + values;
          if(!m_statementPool.containsKey(key)) {
            // the pool does not contain this statement - create it
            m_statementPool.put(key,
              new CmsPreparedStatement(m_originalConnection.prepareStatement(str, values), this));
          }
          return (PreparedStatement) m_statementPool.get(key);
    }
    
    public java.sql.PreparedStatement prepareStatement(String str, String[] str1) throws java.sql.SQLException {
          checkIsClosed();
          String key = str + ":" + str1;
          if(!m_statementPool.containsKey(key)) {
            // the pool does not contain this statement - create it
            m_statementPool.put(key,
              new CmsPreparedStatement(m_originalConnection.prepareStatement(str, str1), this));
          }
          return (PreparedStatement) m_statementPool.get(key);
    }
    
    public java.sql.PreparedStatement prepareStatement(String str, int param, int param2, int param3) throws java.sql.SQLException {
          checkIsClosed();
          String key = str + ":" + param + ":" + param2 + ":" + param3;
          if(!m_statementPool.containsKey(key)) {
            // the pool does not contain this statement - create it
            m_statementPool.put(key,
              new CmsPreparedStatement(m_originalConnection.prepareStatement(str, param, param2, param3), this));
          }
          return (PreparedStatement) m_statementPool.get(key);        
    }
  
        /**
         * Creates a new CmsPreparedStatement from the pool.
         */
    public CallableStatement prepareCall(String sql) throws SQLException {
          String key = sql;
          if(!m_statementPool.containsKey(key)) {
            // the pool contains not this statement - create it
            m_statementPool.put(key,
              new CmsCallableStatement(m_originalConnection.prepareCall(sql), this));
          }
          return (CallableStatement) m_statementPool.get(key);
    }

        /**
         * Creates a new CmsPreparedStatement from the pool.
         */
    public CallableStatement prepareCall(String sql, int a, int b) throws SQLException {
          String key = sql + ":" + a + ":" + b;
          if(!m_statementPool.containsKey(key)) {
            // the pool contains not this statement - create it
            m_statementPool.put(key,
              new CmsCallableStatement(m_originalConnection.prepareCall(sql, a, b), this));
          }
          return (CallableStatement) m_statementPool.get(key);
    }

    public java.sql.CallableStatement prepareCall(String str, int param, int param2, int param3) throws java.sql.SQLException {
         String key = str + ":" + param + ":" + param2 + ":" + param3;
          if(!m_statementPool.containsKey(key)) {
            // the pool does not contains this statement - create it
            m_statementPool.put(key,
              new CmsCallableStatement(m_originalConnection.prepareCall(str, param, param2, param3), this));
          }
          return (CallableStatement) m_statementPool.get(key);
    }
         
    /**
     * Finds out, if this connection was closed.
     */
    public boolean isClosed() throws SQLException {
        return m_isClosed || m_originalConnection.isClosed();
    }

    /**
     * This method don't closes this connection. It puts it back to
     * the pool. Please use it at the end of your database activity.
     */
    public void close() throws SQLException {
        checkIsClosed();
        // set is closed to true
        m_isClosed = true;

        // put the connection back to the pool
        m_pool.putConnection(new CmsConnection(m_originalConnection, m_pool, m_statementPool, m_establishTime));
    }

    /**
     * This method calls close, to put the connection back to the pool.
     */
    protected void finalize() throws Throwable {
        // close the connection (put it back to the pool)
        close();
        super.finalize();
    }

    /**
     * Try to close this connection without putting it back to the pool.
     */
    void closeOriginalConnection() {
          // close all statements
          m_isClosed = true;
          Enumeration keys = m_statementPool.keys();
          while(keys.hasMoreElements()) {
            Object key = keys.nextElement();
            CmsStatement statement = (CmsStatement)m_statementPool.get(key);
            statement.closeOriginalStatement();
          }
          try {
            m_originalConnection.close();
          } catch(SQLException exc) {
            // todo: insert logging here
          }
    }

    /**
     * Returns a string representation of this object.
     */
    public String toString() {
        StringBuffer output=new StringBuffer();
        output.append("[" + this.getClass().getName() + "]:");
        output.append(m_originalConnection);
        output.append(", ");
        output.append("isClosed: " + m_isClosed);
        return output.toString();
    }
    
    public int getHoldability() throws java.sql.SQLException {
        checkIsClosed();
        return m_originalConnection.getHoldability();        
    }
    
    public void releaseSavepoint(java.sql.Savepoint savepoint) throws java.sql.SQLException {
        checkIsClosed();
        m_originalConnection.releaseSavepoint(savepoint);        
    }
    
    public void setHoldability(int param) throws java.sql.SQLException {
        checkIsClosed();
        m_originalConnection.setHoldability(param);
    }
    
    public java.sql.Savepoint setSavepoint() throws java.sql.SQLException {
        checkIsClosed();
        return m_originalConnection.setSavepoint();        
    }
    
    public java.sql.Savepoint setSavepoint(String str) throws java.sql.SQLException {
        checkIsClosed();
        return m_originalConnection.setSavepoint(str);        
    }
    
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -