01: package org.claros.commons.db;
02:
03: import javax.sql.DataSource;
04:
05: import org.apache.commons.dbcp.BasicDataSource;
06: import org.claros.commons.configuration.Paths;
07: import org.claros.commons.utility.Utility;
08:
09: public class DbConfig {
10: private String id;
11: private String database;
12: private String driver;
13: private String login;
14: private String password;
15: private DataSource dataSource;
16:
17: public String getDatabase() {
18: return database;
19: }
20:
21: public void setDatabase(String database) {
22: database = Utility.replaceAllOccurances(database, "%dbpath%",
23: Paths.getDbFolder());
24: this .database = database;
25: }
26:
27: public String getDriver() {
28: return driver;
29: }
30:
31: public void setDriver(String driver) {
32: this .driver = driver;
33: }
34:
35: public String getId() {
36: return id;
37: }
38:
39: public void setId(String id) {
40: this .id = id;
41: }
42:
43: public String getLogin() {
44: return login;
45: }
46:
47: public void setLogin(String login) {
48: this .login = login;
49: }
50:
51: public String getPassword() {
52: return password;
53: }
54:
55: public void setPassword(String password) {
56: this .password = password;
57: }
58:
59: /**
60: * Returns the data source or creates a new one.
61: * @return
62: */
63: public DataSource getDataSource() {
64: if (dataSource == null) {
65: BasicDataSource ds = new BasicDataSource();
66: ds.setDriverClassName(driver);
67: ds.setUsername(login);
68: ds.setPassword(password);
69: ds.setUrl(database);
70: // ds.setDefaultTransactionIsolation(Connection.TRANSACTION_READ_UNCOMMITTED);
71: ds.setInitialSize(10);
72: ds.setMaxActive(20);
73: ds.setMaxIdle(20);
74: ds.setMaxWait(5000);
75: dataSource = ds;
76: }
77: return dataSource;
78: }
79:
80: /**
81: * toString implementation
82: */
83: public String toString() {
84: String out = "id=" + id + "\n" + "database=" + database + "\n"
85: + "driver=" + driver + "\n" + "login=" + login + "\n"
86: + "password=" + password + "\n";
87: return out;
88: }
89: }
|