(no commit message)
[utils] / test / enterprise / src / main / java / org / wamblee / test / persistence / ExternalDatabase.java
1 /*
2  * Copyright 2005-2010 the original author or authors.
3  * 
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  * 
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  * 
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 package org.wamblee.test.persistence;
17
18 /**
19  * Database that encapsulates connection to an external database. Database
20  * connection details can be configured through system properties and
21  * environment variables, see {@link #DB_URL_PROP}, {@link #DB_USER_PROP}, and
22  * {@link #DB_PASSWORD_PROP|.
23  * 
24  * This class assumes modern database drivers that work together with
25  * java.util.ServiceLoader so that explicitly doing a Class.forName() is not
26  * necessary to load the database driver.
27  */
28 public class ExternalDatabase extends AbstractDatabase {
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     public ExternalDatabase() {
50         // Empty
51     }
52
53     public String getExternalJdbcUrl() {
54         return itsUrl;
55     }
56
57     public String getJdbcUrl() {
58         return itsUrl;
59     }
60
61     public String getPassword() {
62         return itsPassword;
63     }
64
65     public String getUsername() {
66         return itsUser;
67     }
68
69     public void doStart() {
70         itsUrl = getProperty(DB_URL_PROP);
71         itsUser = getProperty(DB_USER_PROP);
72         itsPassword = getProperty(DB_PASSWORD_PROP);
73
74         createDataSource();
75     }
76
77     public void doStop() {
78         // Empty.
79     }
80
81 }