// 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(); } }
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); } }
public static void main(final String[] args) { final JFrame frame = new JFrame(); frame.setTitle(Globals.getLocalizedString("programName")); frame.setBackground(VComponentGlobals.BACKGROUND_COLOR); try { frame.setIconImage( ICODecoder.read(ClassLoader.getSystemResourceAsStream("Art Assets/Icons/Frame_Icon.ico")) .get(0)); } catch (final IOException e) { Logger.writeLog( Globals.getLocalizedString("DC_error_UnableToLoadIcon"), Logger.LOG_TYPE_ERROR); } frame.addWindowListener( new WindowListener() { @Override public void windowOpened(WindowEvent e) {} @Override public void windowClosing(WindowEvent e) { System.exit(0); } @Override public void windowClosed(WindowEvent e) { System.exit(0); } @Override public void windowIconified(WindowEvent e) {} @Override public void windowDeiconified(WindowEvent e) {} @Override public void windowActivated(WindowEvent e) {} @Override public void windowDeactivated(WindowEvent e) {} }); frame.addComponentListener( new ComponentAdapter() { public void componentResized(ComponentEvent e) { final Dimension currentDimensions = frame.getSize(); final Dimension minimumDimensions = frame.getMinimumSize(); if (currentDimensions.width < minimumDimensions.width) { currentDimensions.width = minimumDimensions.width; } if (currentDimensions.height < minimumDimensions.height) { currentDimensions.height = minimumDimensions.height; } frame.setSize(currentDimensions); } }); frame.add(new ConnectionScreenController(frame).getView()); frame.setResizable(false); frame.pack(); frame.setLocationRelativeTo(null); frame.setVisible(true); }