X-Git-Url: http://wamblee.org/gitweb/?a=blobdiff_plain;f=test%2Fenterprise%2Fsrc%2Fmain%2Fjava%2Forg%2Fwamblee%2Fsupport%2Fpersistence%2FAbstractDatabase.java;h=12c82c41177b7fe9f66d239d1d642d4218c0a1b9;hb=ec9582b50e9c74b08b14c79d7d16de5d0fc2851e;hp=6eaba50b880f9a218e35ed54a0a3d22aea8168e4;hpb=c63e76e400f06f51ba235b9e6658bfa3149c1d48;p=utils diff --git a/test/enterprise/src/main/java/org/wamblee/support/persistence/AbstractDatabase.java b/test/enterprise/src/main/java/org/wamblee/support/persistence/AbstractDatabase.java index 6eaba50b..12c82c41 100644 --- a/test/enterprise/src/main/java/org/wamblee/support/persistence/AbstractDatabase.java +++ b/test/enterprise/src/main/java/org/wamblee/support/persistence/AbstractDatabase.java @@ -28,6 +28,14 @@ import org.apache.commons.dbcp.PoolableConnectionFactory; import org.apache.commons.dbcp.PoolingDataSource; import org.apache.commons.pool.impl.GenericObjectPool; +/** + * Abstract database class providing the creation of the datasource, + * preventing duplicate starts of the same database, and checking + * for connection leaks when the database is stopped. + * + * @author Erik Brakkee + * + */ public abstract class AbstractDatabase implements Database { /** @@ -47,12 +55,21 @@ public abstract class AbstractDatabase implements Database { private boolean started; + /** + * Constructs the database. + */ protected AbstractDatabase() { started = false; } + /** + * To be implemented by subclasses to start the database. + */ protected abstract void doStart(); + /** + * To be implemented by subclasses to stop the database. + */ protected abstract void doStop(); /** @@ -83,6 +100,9 @@ public abstract class AbstractDatabase implements Database { // / BELOW THIS LINE IS NOT OF INTEREST TO SUBCLASSES. + /** + * Starts the database. + */ public final DataSource start() { if (started) { throw new RuntimeException("Database already started"); @@ -92,6 +112,11 @@ public abstract class AbstractDatabase implements Database { return getDatasource(); } + /** + * Stops the database and tests for connection leaks. + * In cast the system property with the name given by {@link #IGNORE_CONNECTION_LEAK_PROPERTY} + * is set then the connection leaks are not checked. + */ public final void stop() { if (!started) { return; // nothing to do.