@@ -0,0 +1,2350 @@
+package com.github.aureliano.evtbridge.core.jdbc;%0A%0Aimport java.sql.Connection;%0Aimport java.sql.DriverManager;%0Aimport java.sql.SQLException;%0Aimport java.util.HashMap;%0Aimport java.util.Map;%0A%0Aimport org.apache.log4j.Logger;%0A%0Aimport com.github.aureliano.evtbridge.common.exception.EventBridgeException;%0Aimport com.github.aureliano.evtbridge.common.helper.StringHelper;%0A%0Apublic class ConnectionPool %7B%0A%0A%09private static ConnectionPool instance;%0A%09private static final Logger logger = Logger.getLogger(ConnectionPool.class);%0A%09%0A%09private Map%3CJdbcConnectionModel, Connection%3E pool;%0A%09%0A%09private ConnectionPool() %7B%0A%09%09logger.info(%22Initializing JDBC connection pool.%22);%0A%09%09this.pool = new HashMap%3C%3E();%0A%09%7D%0A%09%0A%09public final static synchronized ConnectionPool instance() %7B%0A%09%09if (instance == null) %7B%0A%09%09%09instance = new ConnectionPool();%0A%09%09%7D%0A%09%09%0A%09%09return instance;%0A%09%7D%0A%09%0A%09public static boolean isInitialized() %7B%0A%09%09return (instance != null);%0A%09%7D%0A%09%0A%09public synchronized Connection getConnection(JdbcConnectionModel schema) %7B%0A%09%09Connection connection = this.pool.get(schema);%0A%09%09%0A%09%09if (connection == null) %7B%0A%09%09%09connection = this.openConnection(schema);%0A%09%09%09this.pool.put(schema, connection);%0A%09%09%7D%0A%09%09%0A%09%09return connection;%0A%09%7D%0A%09%0A%09public synchronized void closeConnections() %7B%0A%09%09logger.info(%22Closing %22 + this.pool.size() + %22 JDBC connection(s) in the pool.%22);%0A%09%09%0A%09%09for (Connection connection : this.pool.values()) %7B%0A%09%09%09try %7B%0A%09%09%09%09connection.close();%0A%09%09%09%7D catch (SQLException ex) %7B%0A%09%09%09%09logger.error(ex.getMessage(), ex);%0A%09%09%09%7D%0A%09%09%7D%0A%09%09%0A%09%09this.pool.clear();%0A%09%7D%0A%0A%09private Connection openConnection(JdbcConnectionModel schema) %7B%0A%09%09try %7B%0A%09%09%09logger.info(%22Registrating JDBC driver %22 + schema.getDriver());%0A%09%09%09Class.forName(schema.getDriver());%0A%09%09%09%0A%09%09%09Connection connection = null;%0A%09%09%09if (!StringHelper.isEmpty(schema.getUser())) %7B%0A%09%09%09%09logger.info(%22Connecting to %22 + schema.getUrl() + %22 with user %22 + schema.getUser() + %22 and password %22 + schema.getPassword());%0A%09%09%09%09connection = DriverManager.getConnection(%0A%09%09%09%09%09schema.getUrl(),%0A%09%09%09%09%09schema.getUser(),%0A%09%09%09%09%09schema.getPassword()%0A%09%09%09%09);%0A%09%09%09%7D else %7B%0A%09%09%09%09logger.info(%22Connecting to %22 + schema.getUrl());%0A%09%09%09%09connection = DriverManager.getConnection(schema.getUrl());%0A%09%09%09%7D%0A%09%09%09%0A%09%09%09return connection;%0A%09%09%7D catch (ClassNotFoundException ex) %7B%0A%09%09%09throw new EventBridgeException(ex);%0A%09%09%7D catch (SQLException ex) %7B%0A%09%09%09throw new EventBridgeException(ex);%0A%09%09%7D%0A%09%7D%0A%7D

Create connection pool.