diff --git a/gradle.properties b/gradle.properties index 920b92c..111f147 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,3 +1,3 @@ group = org.xbib name = database -version = 2.1.2 +version = 2.2.0 diff --git a/jdbc-query/src/main/java/org/xbib/jdbc/query/DatabaseProvider.java b/jdbc-query/src/main/java/org/xbib/jdbc/query/DatabaseProvider.java index b08851e..e9afa07 100644 --- a/jdbc-query/src/main/java/org/xbib/jdbc/query/DatabaseProvider.java +++ b/jdbc-query/src/main/java/org/xbib/jdbc/query/DatabaseProvider.java @@ -5,13 +5,10 @@ import org.xbib.jdbc.connection.pool.PoolDataSource; import org.xbib.jdbc.query.util.Metric; import javax.sql.DataSource; -import java.io.Closeable; -import java.io.IOException; import java.sql.Connection; import java.sql.DriverManager; import java.sql.SQLException; import java.util.Properties; -import java.util.concurrent.atomic.AtomicBoolean; import java.util.concurrent.atomic.AtomicInteger; import java.util.function.Supplier; import java.util.logging.Level; @@ -23,7 +20,7 @@ import java.util.logging.Logger; * of this laziness, the underlying resources require explicit cleanup by calling either * commitAndClose() or rollbackAndClose(). */ -public final class DatabaseProvider implements Supplier, Closeable { +public final class DatabaseProvider implements Supplier { private static final Logger logger = Logger.getLogger(DatabaseProvider.class.getName()); @@ -47,7 +44,7 @@ public final class DatabaseProvider implements Supplier, Closeable { return new DatabaseProviderBuilderImpl(ds, () -> { try { if (ds == null) { - throw new NullPointerException(); + throw new IllegalArgumentException("data source must not be null"); } return ds.getConnection(); } catch (Exception e) { @@ -287,9 +284,6 @@ public final class DatabaseProvider implements Supplier, Closeable { if (database != null) { return database; } - if (builder.isClosed()) { - throw new DatabaseException("Called get() on a DatabaseProvider after close()"); - } Metric metric = new Metric(logger.isLoggable(Level.FINE)); try { connection = builder.connectionProvider.get(); @@ -393,8 +387,7 @@ public final class DatabaseProvider implements Supplier, Closeable { } } - @Override - public void close() throws IOException { + public void close() { if (connection != null) { try { connection.close(); @@ -402,28 +395,24 @@ public final class DatabaseProvider implements Supplier, Closeable { logger.log(Level.SEVERE, "Unable to close the database connection", e); } } - builder.close(); connection = null; database = null; } - private static class DatabaseProviderBuilderImpl implements DatabaseProviderBuilder, Closeable { + private static class DatabaseProviderBuilderImpl implements DatabaseProviderBuilder { - private DataSource dataSource; + private final DataSource dataSource; private final Supplier connectionProvider; private final Options options; - private final AtomicBoolean closed; - private DatabaseProviderBuilderImpl(DataSource dataSource, Supplier connectionProvider, Options options) { this.dataSource = dataSource; this.connectionProvider = connectionProvider; this.options = options; - this.closed = new AtomicBoolean(false); } @Override @@ -511,20 +500,5 @@ public final class DatabaseProvider implements Supplier, Closeable { this.build().transact(tx); } - @Override - public void close() throws IOException { - if (closed.compareAndSet(false, true)) { - if (dataSource != null) { - if (dataSource instanceof Closeable) { - ((Closeable) dataSource).close(); - } - dataSource = null; - } - } - } - - public boolean isClosed() { - return closed.get(); - } } } diff --git a/settings.gradle b/settings.gradle index d9a4a27..97b4ef6 100644 --- a/settings.gradle +++ b/settings.gradle @@ -29,6 +29,7 @@ dependencyResolutionManagement { } include 'jdbc-connection-pool' +include 'jdbc-pool' include 'jdbc-query' include 'jdbc-test' include 'jdbc-mariadb'