Connection unwrappedConn = null;
if (this.connUtil.getDbType() == DbType.ORACLE && connection instanceof Proxy) {
try {
unwrappedConn = connection.unwrap(Connection.class);
} catch (Exception ex) {
throw new JuDbException("Couldn't unwrap Connection", ex);
}
}
final Connection realConn = unwrappedConn != null
? unwrappedConn
: connection;
try {
// Check if we get the same connection. If so, we'll recycle the DatabaseConnection to avoid
// requerying of all the DB meta data
if (this.dbConn == null || this.dbConn.getConnection() != connection) {
this.dbConn = new DatabaseConnection(realConn, this.schemaName);
for (String key : this.configProperties.keySet()) {
this.dbConn.getConfig().setProperty(key, this.configProperties.get(key));
}
logger.debug("Created DatabaseConnection: {}", this.dbConn);
} else {
// Use existing DatabaseConnection
logger.info("Reusing DatabaseConnection {}", this.dbConn.getConnection());
}
work.execute(this.dbConn);
} catch (Exception ex) {
throw new JuDbException("Couldn't execute DbUnitWork", ex);
}
}