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

📄 jahiadbpoolbaseservice.java

📁 java 写的一个新闻发布系统
💻 JAVA
字号:
////  JahiaDBPoolBaseService//  EV      31.10.2000////  initConnectionPool//  getConnection//  freeConnection//package org.jahia.services.database;import org.jahia.utils.*;           // JahiaConsoleimport org.jahia.exceptions.*;      // JahiaInitializationExceptionimport org.jahia.settings.*;        // JahiaPrivateSettingsimport java.sql.*;                      // Statement, ResultSetpublic class JahiaDBPoolBaseService extends JahiaDBPoolService {    private String serviceName;    private static JahiaDBPoolBaseService theObject = null;    private   		 ConnectionPool      theConnectionPool;    public static int count = 0;   /***    * constructor    * EV    31.10.2000    * NK    26.12.2000 Client should always call getInstance() method instead    */    protected JahiaDBPoolBaseService()    {        JahiaConsole.println( "JahiaDBPoolBaseService", "***** Starting the Jahia DB Pool Base Service *****" );    } // end constructor   /***    * getInstance    * EV    31.10.2000    *    */    public static JahiaDBPoolBaseService getInstance()    {        if (theObject == null) {                synchronized ( JahiaDBPoolBaseService.class ){                    if (theObject == null) {                        theObject = new JahiaDBPoolBaseService();                    }                }        }        return theObject;    } // end getInstance   /***    * init    * EV    31.10.2000    * EV    18.11.2000  setting passed through parameters    * @param JahiaPrivateSettings jSettings    */    public void init( JahiaPrivateSettings jSettings )    throws JahiaInitializationException    {      try{           theConnectionPool =            new ConnectionPool( jSettings.db_driver, jSettings.db_url, jSettings.db_username, jSettings.db_password,                jSettings.db_min_connections, jSettings.db_max_connections,                jSettings.db_waitIfBusy, jSettings.db_verbose );      } catch (  SQLException sqle ) {          JahiaConsole.println("JahiaDBPoolBaseService" , "JahiaDBPoolBaseService, SQLException " + sqle.getMessage()  );          String error = sqle.getMessage();          int    comaPoint = error.indexOf(":");          if(comaPoint>0) {            error = error.substring(0, comaPoint);          }          throw new JahiaInitializationException( "Database "+error+"." );      }    } // end init   /***    * getConnection    * EV    31.10.2000    * EV    13.12.2000  New Khue Version !!    *    */    public Connection getConnection(int debugid)    throws SQLException    {        if ( theConnectionPool == null ){            return null;        }        return theConnectionPool.getConnection(debugid);    } // end getConnection   /***    * getConnection    * EV    31.10.2000    * EV    13.12.2000  New Khue Version !!    *    */    public Connection getConnection()    throws SQLException    {        if ( theConnectionPool == null ){            return null;        }        return theConnectionPool.getConnection(0);    } // end getConnection   /***    * freeConnection    * EV    31.10.2000    * EV    13.12.2000  New Khue Version !!    *    */    public void freeConnection( Connection connexion )    throws SQLException    {        if ( connexion != null ){            theConnectionPool.free( connexion );        }    } // end freeConnection    /**     * getNbFreeConnections     * NK Return the number of available connection     * NK 13.12.2000     */     public int getNbFreeConnections(){        if ( theConnectionPool == null ){            return 0;        }        return theConnectionPool.getNbFreeConnections();     }    /**     * Returns the configured minimum size of the connection pool     * @return an integer representing the minimum size of the pool as     * configured via the constructor     */    public int getMinConnections() {        if ( theConnectionPool == null ) { return 0; }        return theConnectionPool.getMinConnections();    }    /**     * Returns the configured maximum size of the connection pool     * @return an integer representing the maximum size of the pool as configured     * via the constructor     */    public int getMaxConnections() {        if ( theConnectionPool == null ) { return 0; }        return theConnectionPool.getMaxConnections();    }    /**     * Returns the number of connections managed by this pool that are not     * available (ie are busy handling SQL queries)     * @return an integer representing the number of busy queries     */    public int getBusyConnections() {        if ( theConnectionPool == null ) { return 0; }        return theConnectionPool.getBusyConnections();    }    /**     * Returns the number of connections both in the busy state and in     * the available pool. Basically this returns the number of connections     * to the database that are handled by this connection pool at the     * current time     * @return an integer representing the sum of the available pool and     * the currently used connections.     */    public int getTotalConnections() {        if ( theConnectionPool == null ) { return 0; }        return theConnectionPool.getTotalConnections();    }   /**    * Method setName<br>    * Set the name of the service    *    * @param String name    */   public void setName(String name){      this.serviceName = name;   }    public int executeUpdate( Statement stmt, String s ) throws SQLException    {//        JahiaConsole.println(">>>["+count+"]>>",s);        count++;        return stmt.executeUpdate(s);    }    public ResultSet executeQuery( Statement stmt, String s ) throws SQLException    {//        JahiaConsole.println(">>>["+count+"]>>",s);         count++;        return stmt.executeQuery(s);    }    } // end ConnectionManager

⌨️ 快捷键说明

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