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 {
/**
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();
/**
// / BELOW THIS LINE IS NOT OF INTEREST TO SUBCLASSES.
+ /**
+ * Starts the database.
+ */
public final DataSource start() {
if (started) {
throw new RuntimeException("Database already started");
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.