Skip to content

Commit

Permalink
activejdbc-369 Display JDBC URL when attaching a connection to thread…
Browse files Browse the repository at this point in the history
…. Also updated versions of AJ in db-migrator-integration-test projects
  • Loading branch information
Igor Polevoy committed Feb 24, 2015
1 parent b95b40c commit 110a732
Show file tree
Hide file tree
Showing 6 changed files with 14 additions and 14 deletions.
Expand Up @@ -53,13 +53,12 @@ static Connection getConnection(String dbName){
* @param dbName
* @param connection
*/
static void attach(String dbName, Connection connection) {
static void attach(String dbName, Connection connection, String extraInfo) {
if(ConnectionsAccess.getConnectionMap().get(dbName) != null){
throw new InternalException("You are opening a connection " + dbName + " without closing a previous one. Check your logic. Connection still remains on thread: " + ConnectionsAccess.getConnectionMap().get(dbName));
}
LogFilter.log(logger, "Attaching connection: {}", connection);
ConnectionsAccess.getConnectionMap().put(dbName, connection);
LogFilter.log(logger, "Attached connection: {} named: {} to thread: {}", connection, dbName, Thread.currentThread());
LogFilter.log(logger, "Attached connection: {} named: {} to current thread. Extra info: {}", connection, dbName, extraInfo);
}

static void detach(String dbName){
Expand Down
15 changes: 8 additions & 7 deletions activejdbc/src/main/java/org/javalite/activejdbc/DB.java
Expand Up @@ -70,7 +70,7 @@ public void open(String driver, String url, String user, String password) {
try {
Class.forName(driver);
Connection connection = DriverManager.getConnection(url, user, password);
ConnectionsAccess.attach(dbName, connection);
ConnectionsAccess.attach(dbName, connection, url);
} catch (Exception e) {
throw new InitException("Failed to connect to JDBC URL: " + url, e);
}
Expand All @@ -88,7 +88,7 @@ public void open(String driver, String url, Properties props) {
try {
Class.forName(driver);
Connection connection = DriverManager.getConnection(url, props);
ConnectionsAccess.attach(dbName, connection);
ConnectionsAccess.attach(dbName, connection, url);
} catch (Exception e) {
throw new InitException("Failed to connect to JDBC URL: " + url, e);
}
Expand All @@ -106,7 +106,7 @@ public void open(String jndiName) {
Context ctx = new InitialContext();
DataSource ds = (DataSource) ctx.lookup(jndiName);
Connection connection = ds.getConnection();
ConnectionsAccess.attach(dbName, connection);
ConnectionsAccess.attach(dbName, connection, jndiName);
} catch (Exception e) {
throw new InitException("Failed to connect to JNDI name: " + jndiName, e);
}
Expand All @@ -118,7 +118,7 @@ public void open(String jndiName) {
* @param connection instance of connection to attach to current thread.
*/
public void attach(Connection connection){
ConnectionsAccess.attach(dbName, connection);
ConnectionsAccess.attach(dbName, connection, "");
}

/**
Expand Down Expand Up @@ -151,7 +151,7 @@ public void open(DataSource datasource){
checkExistingConnection(dbName);
try {
Connection connection = datasource.getConnection();
ConnectionsAccess.attach(dbName, connection);
ConnectionsAccess.attach(dbName, connection, datasource.toString());
} catch (SQLException e) {
throw new InitException(e);
}
Expand All @@ -171,7 +171,8 @@ public void open(String jndiName, Properties jndiProperties) {
Context ctx = new InitialContext(jndiProperties);
DataSource ds = (DataSource) ctx.lookup(jndiName);
Connection connection = ds.getConnection();
ConnectionsAccess.attach(dbName, connection);
ConnectionsAccess.attach(dbName, connection,
jndiProperties.contains("url") ? jndiProperties.getProperty("url") : jndiName);
} catch (Exception e) {
throw new InitException("Failed to connect to JNDI name: " + jndiName, e);
}
Expand Down Expand Up @@ -238,7 +239,7 @@ private void openContext(InitialContext context, String jndiName) {
try {
DataSource ds = (DataSource) context.lookup(jndiName);
Connection connection = ds.getConnection();
ConnectionsAccess.attach(dbName, connection);
ConnectionsAccess.attach(dbName, connection, jndiName);
} catch (Exception e) {
throw new InitException("Failed to connect to JNDI name: " + jndiName, e);
}
Expand Down
Expand Up @@ -15,7 +15,7 @@
<plugin>
<groupId>org.javalite</groupId>
<artifactId>db-migrator-maven-plugin</artifactId>
<version>1.4.10-SNAPSHOT</version>
<version>1.4.11-SNAPSHOT</version>
<configuration>
<configFile>${basedir}/db.properties</configFile>
<environments>development, staging</environments>
Expand Down
Expand Up @@ -15,7 +15,7 @@
<plugin>
<groupId>org.javalite</groupId>
<artifactId>db-migrator-maven-plugin</artifactId>
<version>1.4.10-SNAPSHOT</version>
<version>1.4.11-SNAPSHOT</version>
<configuration>
<environments>development</environments>
</configuration>
Expand Down
Expand Up @@ -15,7 +15,7 @@
<plugin>
<groupId>org.javalite</groupId>
<artifactId>db-migrator-maven-plugin</artifactId>
<version>1.4.10-SNAPSHOT</version>
<version>1.4.11-SNAPSHOT</version>
<configuration>
<driver>com.mysql.jdbc.Driver</driver>
<url>jdbc:mysql://localhost/test_project</url>
Expand Down
2 changes: 1 addition & 1 deletion db-migrator/src/test/test-project/pom.xml
Expand Up @@ -15,7 +15,7 @@
<plugin>
<groupId>org.javalite</groupId>
<artifactId>db-migrator-maven-plugin</artifactId>
<version>1.4.10-SNAPSHOT</version>
<version>1.4.11-SNAPSHOT</version>
<configuration>
<driver>com.mysql.jdbc.Driver</driver>
<url>jdbc:mysql://localhost/test_project</url>
Expand Down

0 comments on commit 110a732

Please sign in to comment.