Removed DOCUMENT ME comments that were generated and applied source code
[utils] / test / enterprise / src / main / java / org / wamblee / support / persistence / ExternalDatabase.java
1 package org.wamblee.support.persistence;
2
3 import java.util.Arrays;
4 import java.util.List;
5 import java.util.logging.Logger;
6
7 import javax.sql.DataSource;
8
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;
14
15 /**
16  * Database that encapsulates connection to an external database. Database
17  * connection details can be configured through system properties and
18  * environment variables, see {@link #DB_URL_PROP}, {@link #DB_USER_PROP}, and
19  * {@link #DB_PASSWORD_PROP|.
20  * 
21  * This class assumes modern database drivers that work together with
22  * java.util.ServiceLoader so that explicitly doing a Class.forName() is not
23  * necessary to load the database driver.
24  */
25 public class ExternalDatabase extends AbstractDatabase {
26
27     private static final Logger LOGGER = Logger
28         .getLogger(ExternalDatabase.class.getName());
29
30     /**
31      * System property/environment variable that defines the database URL.
32      */
33     public static final String DB_URL_PROP = "TEST_DB_URL";
34
35     /**
36      * System property/environment variable that defines the database user.
37      */
38     public static final String DB_USER_PROP = "TEST_DB_USER";
39
40     /**
41      * System property/environment variable that defines the database password.
42      */
43     public static final String DB_PASSWORD_PROP = "TEST_DB_PASSWORD";
44
45     private String itsUrl;
46     private String itsUser;
47     private String itsPassword;
48
49     private DataSource itsDataSource;
50
51     public ExternalDatabase() {
52         // Empty
53     }
54
55     public String getExternalJdbcUrl() {
56         return itsUrl;
57     }
58
59     public String getJdbcUrl() {
60         return itsUrl;
61     }
62
63     public String getPassword() {
64         return itsPassword;
65     }
66
67     public String getUsername() {
68         return itsUser;
69     }
70
71     public void doStart() {
72         itsUrl = getProperty(DB_URL_PROP);
73         itsUser = getProperty(DB_USER_PROP);
74         itsPassword = getProperty(DB_PASSWORD_PROP);
75
76         createDataSource();
77     }
78
79     public void doStop() {
80         // Empty.
81     }
82
83 }