1 package org.wamblee.support.persistence;
3 import java.util.Arrays;
5 import java.util.logging.Logger;
7 import javax.sql.DataSource;
9 import org.apache.commons.dbcp.ConnectionFactory;
10 import org.apache.commons.dbcp.DriverManagerConnectionFactory;
11 import org.apache.commons.dbcp.PoolableConnectionFactory;
12 import org.apache.commons.dbcp.PoolingDataSource;
13 import org.apache.commons.pool.impl.GenericObjectPool;
16 * Database that encapsulates connection to an external database.
17 * Database connection details can be configured through system properties
18 * and environment variables, see {@link #DB_URL_PROP}, {@link #DB_USER_PROP}, and
19 * {@link #DB_PASSWORD_PROP|.
21 * This class assumes modern database drivers that work together with java.util.ServiceLoader
22 * so that explicitly doing a Class.forName() is not necessary to load the database driver.
24 public class ExternalDatabase extends AbstractDatabase {
26 private static final Logger LOGGER = Logger.getLogger(ExternalDatabase.class.getName());
29 * System property/environment variable that defines the database URL.
31 public static final String DB_URL_PROP = "TEST_DB_URL";
34 * System property/environment variable that defines the database user.
36 public static final String DB_USER_PROP = "TEST_DB_USER";
39 * System property/environment variable that defines the database password.
41 public static final String DB_PASSWORD_PROP = "TEST_DB_PASSWORD";
44 private String itsUrl;
45 private String itsUser;
46 private String itsPassword;
48 private DataSource itsDataSource;
50 public ExternalDatabase() {
54 public String getExternalJdbcUrl() {
58 public String getJdbcUrl() {
62 public String getPassword() {
66 public String getUsername() {
70 public void doStart() {
71 itsUrl = getProperty(DB_URL_PROP);
72 itsUser = getProperty(DB_USER_PROP);
73 itsPassword = getProperty(DB_PASSWORD_PROP);
78 public void doStop() {