import java.sql.Connection;
import java.sql.SQLException;
+import java.util.logging.Level;
+import java.util.logging.Logger;
import javax.naming.InitialContext;
import javax.naming.NamingException;
import javax.sql.DataSource;
public class J2EEConnectionPool implements JDBCConnectionPool {
+ private static final Logger logger = Logger
+ .getLogger(J2EEConnectionPool.class.getName());
private String dataSourceJndiName;
}
public void releaseConnection(Connection conn) {
- try {
- conn.close();
- } catch (SQLException e) {
- e.printStackTrace();
+ if (conn != null) {
+ try {
+ conn.close();
+ } catch (SQLException e) {
+ logger.log(Level.FINE, "Could not release SQL connection", e);
+ }
}
}
ds.getConnection();
EasyMock.expectLastCall().andReturn(connection);
- System.setProperty("java.naming.factory.initial",
+ System.setProperty(
+ "java.naming.factory.initial",
"com.vaadin.tests.server.container.sqlcontainer.connection.MockInitialContextFactory");
Context context = EasyMock.createMock(Context.class);
context.lookup("testDataSource");
EasyMock.replay(context);
J2EEConnectionPool pool = new J2EEConnectionPool("foo");
- Connection c = pool.reserveConnection();
+ pool.reserveConnection();
EasyMock.verify(context);
}
+ @Test
+ public void releaseConnection_null_shouldSucceed() throws SQLException {
+ DataSource ds = EasyMock.createMock(DataSource.class);
+ EasyMock.replay(ds);
+
+ J2EEConnectionPool pool = new J2EEConnectionPool(ds);
+ pool.releaseConnection(null);
+ EasyMock.verify(ds);
+ }
}