Exemple #1
0
 // call at end of program to close all physical threads
 public static void shutdownConnectionPool() {
   try {
     BoneCP connectionPool = DatabaseConnection.getConnectionPool();
     Logger.writeLog("Shutting down connection pool.", Logger.LOG_TYPE_VERBOSE);
     if (connectionPool != null) {
       connectionPool.shutdown();
       Logger.writeLog("Connection pooling is destroyed successfully.", Logger.LOG_TYPE_VERBOSE);
     }
   } catch (Exception e) {
     e.printStackTrace();
   }
 }
Exemple #2
0
  public static void initConnectionPool() {
    try {
      Class.forName("com.mysql.jdbc.Driver");

      BoneCPConfig config = new BoneCPConfig();

      // jdbc:mysql://127.0.0.1:3306/"
      String JdbcURL = Config.DATABASE_URL + ":" + Config.DATABASE_PORT;

      config.setJdbcUrl(JdbcURL);
      config.setUsername(Config.DATABASE_LOGIN);
      config.setPassword(Config.DATABASE_PASSWORD);

      config.setMinConnectionsPerPartition(3);
      config.setMaxConnectionsPerPartition(5);
      config.setPartitionCount(1); // 1*2 = 2 connections
      // config.setLazyInit(true); // depends on the application usage
      connectionPool = new BoneCP(config); // setup the connection pool

      Logger.writeLog("Database connection succeeded!", Logger.LOG_TYPE_VERBOSE);

      // Log.log("This many active physical connections: " +
      // connectionPool.getTotalCreatedConnections());
      DatabaseConnection.setConnectionPool(connectionPool);

      /*Boolean exists = DatabaseHandler.databasesExist(Config.DATABASE_AUTH,
      												Config.DATABASE_CHAR,
      												Config.DATABASE_WORLD);

      if (!exists)
               {
      	Logger.writeLog("One or more databases (authDB, charactersDB, or worldDB) do not exist.", Logger.LOG_TYPE_ERROR);
      	System.exit(0);
      }*/

    } catch (Exception e) {
      e.printStackTrace(); // Fix this.. exception wrapping.
      System.exit(0);
    }
  }