LOG.info("Initializing SQL connection [" + partition + "]");
try {
PortLock portLock = PortUtils.getNextAvailablePort(EmbeddedMySQLConfig.DEFAULT_PORT);
EmbeddedMySQL mySQL = null;
EmbeddedMySQLConfig config = null;
try {
File mysqlDir = new File(mysqlDb.toString());
LOG.info("Going to instantiate a MySQLD in: " + mysqlDir + ", port [" + portLock.getPort()
+ "] (partition: " + partition + ")");
config = new EmbeddedMySQLConfig(portLock.getPort(), EmbeddedMySQLConfig.DEFAULT_USER,
EmbeddedMySQLConfig.DEFAULT_PASS, mysqlDir, null);
mySQL = new EmbeddedMySQL(config);
mySQL.start(true);
} catch(Exception e) {
throw e;
} finally {
portLock.release();
}
mySQLs.put(partition, mySQL);
// MySQL is successfully started at this point, or an Exception would have been thrown.
Class.forName(EmbeddedMySQL.DRIVER);
Connection conn = DriverManager.getConnection(config.getLocalJDBCConnection(GENERATED_DB_NAME),
config.getUser(), config.getPass());
conn.setAutoCommit(false);
connCache.put(partition, conn);
Statement st = conn.createStatement();
// Init transaction