Mercurial > dive4elements > framework
annotate artifact-database/src/main/java/de/intevation/artifactdatabase/DBConnection.java @ 91:730ff077a58c
More javadoc, some code formatting.
artifacts/trunk@847 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author | Sascha L. Teichmann <sascha.teichmann@intevation.de> |
---|---|
date | Sun, 28 Mar 2010 10:01:03 +0000 |
parents | d348fe1fd822 |
children | e27cf9c84eb8 |
rev | line source |
---|---|
10
e8626caac353
* Made Artifact life cycle symmetric: setup/endOfLife.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
1 package de.intevation.artifactdatabase; |
e8626caac353
* Made Artifact life cycle symmetric: setup/endOfLife.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
2 |
e8626caac353
* Made Artifact life cycle symmetric: setup/endOfLife.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
3 import javax.sql.DataSource; |
e8626caac353
* Made Artifact life cycle symmetric: setup/endOfLife.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
4 |
e8626caac353
* Made Artifact life cycle symmetric: setup/endOfLife.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
5 import java.sql.SQLException; |
e8626caac353
* Made Artifact life cycle symmetric: setup/endOfLife.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
6 |
e8626caac353
* Made Artifact life cycle symmetric: setup/endOfLife.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
7 import org.apache.commons.dbcp.BasicDataSource; |
e8626caac353
* Made Artifact life cycle symmetric: setup/endOfLife.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
8 |
19
1259d192e3c3
* New configuration based on config directory
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
12
diff
changeset
|
9 import java.io.File; |
1259d192e3c3
* New configuration based on config directory
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
12
diff
changeset
|
10 |
38
93edc04f3a10
Added postgresql support.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
19
diff
changeset
|
11 import org.apache.log4j.Logger; |
93edc04f3a10
Added postgresql support.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
19
diff
changeset
|
12 |
10
e8626caac353
* Made Artifact life cycle symmetric: setup/endOfLife.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
13 /** |
87
0f48188a6e02
Added some javadoc to the artifactdatabase module. Not done yet.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
38
diff
changeset
|
14 * This class encapsulate the creation and pooling of database connections used |
0f48188a6e02
Added some javadoc to the artifactdatabase module. Not done yet.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
38
diff
changeset
|
15 * by the artifact database. The credential to open the database connections |
0f48188a6e02
Added some javadoc to the artifactdatabase module. Not done yet.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
38
diff
changeset
|
16 * are taken from the global configuratiion. |
0f48188a6e02
Added some javadoc to the artifactdatabase module. Not done yet.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
38
diff
changeset
|
17 * @author <a href="mailto:sascha.teichmann@intevation.de">Sascha L. Teichmann</a> |
10
e8626caac353
* Made Artifact life cycle symmetric: setup/endOfLife.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
18 */ |
e8626caac353
* Made Artifact life cycle symmetric: setup/endOfLife.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
19 public class DBConnection |
e8626caac353
* Made Artifact life cycle symmetric: setup/endOfLife.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
20 { |
38
93edc04f3a10
Added postgresql support.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
19
diff
changeset
|
21 private static Logger logger = Logger.getLogger(DBConnection.class); |
93edc04f3a10
Added postgresql support.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
19
diff
changeset
|
22 |
87
0f48188a6e02
Added some javadoc to the artifactdatabase module. Not done yet.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
38
diff
changeset
|
23 /** |
0f48188a6e02
Added some javadoc to the artifactdatabase module. Not done yet.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
38
diff
changeset
|
24 * XPath to access the database driver within the global configuration. |
0f48188a6e02
Added some javadoc to the artifactdatabase module. Not done yet.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
38
diff
changeset
|
25 */ |
10
e8626caac353
* Made Artifact life cycle symmetric: setup/endOfLife.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
26 public static final String DB_DRIVER = |
38
93edc04f3a10
Added postgresql support.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
19
diff
changeset
|
27 "/artifact-database/database/driver/text()"; |
87
0f48188a6e02
Added some javadoc to the artifactdatabase module. Not done yet.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
38
diff
changeset
|
28 /** |
0f48188a6e02
Added some javadoc to the artifactdatabase module. Not done yet.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
38
diff
changeset
|
29 * XPath to access the database URL within the global configuration. |
0f48188a6e02
Added some javadoc to the artifactdatabase module. Not done yet.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
38
diff
changeset
|
30 */ |
10
e8626caac353
* Made Artifact life cycle symmetric: setup/endOfLife.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
31 public static final String DB_URL = |
38
93edc04f3a10
Added postgresql support.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
19
diff
changeset
|
32 "/artifact-database/database/url/text()"; |
87
0f48188a6e02
Added some javadoc to the artifactdatabase module. Not done yet.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
38
diff
changeset
|
33 /** |
0f48188a6e02
Added some javadoc to the artifactdatabase module. Not done yet.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
38
diff
changeset
|
34 * XPath to access the database use within the global configuration. |
0f48188a6e02
Added some javadoc to the artifactdatabase module. Not done yet.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
38
diff
changeset
|
35 */ |
10
e8626caac353
* Made Artifact life cycle symmetric: setup/endOfLife.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
36 public static final String DB_USER = |
38
93edc04f3a10
Added postgresql support.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
19
diff
changeset
|
37 "/artifact-database/database/user/text()"; |
87
0f48188a6e02
Added some javadoc to the artifactdatabase module. Not done yet.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
38
diff
changeset
|
38 /** |
0f48188a6e02
Added some javadoc to the artifactdatabase module. Not done yet.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
38
diff
changeset
|
39 * XPath to access the database password within the global configuration. |
0f48188a6e02
Added some javadoc to the artifactdatabase module. Not done yet.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
38
diff
changeset
|
40 */ |
10
e8626caac353
* Made Artifact life cycle symmetric: setup/endOfLife.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
41 public static final String DB_PASSWORD = |
38
93edc04f3a10
Added postgresql support.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
19
diff
changeset
|
42 "/artifact-database/database/password/text()"; |
10
e8626caac353
* Made Artifact life cycle symmetric: setup/endOfLife.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
43 |
87
0f48188a6e02
Added some javadoc to the artifactdatabase module. Not done yet.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
38
diff
changeset
|
44 /** |
0f48188a6e02
Added some javadoc to the artifactdatabase module. Not done yet.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
38
diff
changeset
|
45 * The default database driver: H2 |
0f48188a6e02
Added some javadoc to the artifactdatabase module. Not done yet.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
38
diff
changeset
|
46 */ |
10
e8626caac353
* Made Artifact life cycle symmetric: setup/endOfLife.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
47 public static final String DEFAULT_DRIVER = |
e8626caac353
* Made Artifact life cycle symmetric: setup/endOfLife.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
48 "org.h2.Driver"; |
e8626caac353
* Made Artifact life cycle symmetric: setup/endOfLife.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
49 |
87
0f48188a6e02
Added some javadoc to the artifactdatabase module. Not done yet.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
38
diff
changeset
|
50 /** |
0f48188a6e02
Added some javadoc to the artifactdatabase module. Not done yet.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
38
diff
changeset
|
51 * The default database name: artifacts.db |
0f48188a6e02
Added some javadoc to the artifactdatabase module. Not done yet.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
38
diff
changeset
|
52 */ |
19
1259d192e3c3
* New configuration based on config directory
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
12
diff
changeset
|
53 public static final String DEFAULT_DATABASE_FILE = |
1259d192e3c3
* New configuration based on config directory
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
12
diff
changeset
|
54 "artifacts.db"; |
1259d192e3c3
* New configuration based on config directory
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
12
diff
changeset
|
55 |
87
0f48188a6e02
Added some javadoc to the artifactdatabase module. Not done yet.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
38
diff
changeset
|
56 /** |
0f48188a6e02
Added some javadoc to the artifactdatabase module. Not done yet.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
38
diff
changeset
|
57 * The default database URL: This is created once by #getDefaultURL() |
0f48188a6e02
Added some javadoc to the artifactdatabase module. Not done yet.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
38
diff
changeset
|
58 */ |
19
1259d192e3c3
* New configuration based on config directory
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
12
diff
changeset
|
59 public static final String DEFAULT_URL = getDefaultURL(); |
10
e8626caac353
* Made Artifact life cycle symmetric: setup/endOfLife.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
60 |
87
0f48188a6e02
Added some javadoc to the artifactdatabase module. Not done yet.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
38
diff
changeset
|
61 /** |
0f48188a6e02
Added some javadoc to the artifactdatabase module. Not done yet.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
38
diff
changeset
|
62 * The default database user: "" |
0f48188a6e02
Added some javadoc to the artifactdatabase module. Not done yet.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
38
diff
changeset
|
63 */ |
10
e8626caac353
* Made Artifact life cycle symmetric: setup/endOfLife.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
64 public static final String DEFAULT_USER = ""; |
87
0f48188a6e02
Added some javadoc to the artifactdatabase module. Not done yet.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
38
diff
changeset
|
65 |
0f48188a6e02
Added some javadoc to the artifactdatabase module. Not done yet.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
38
diff
changeset
|
66 /** |
0f48188a6e02
Added some javadoc to the artifactdatabase module. Not done yet.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
38
diff
changeset
|
67 * The default database password: "" |
0f48188a6e02
Added some javadoc to the artifactdatabase module. Not done yet.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
38
diff
changeset
|
68 */ |
10
e8626caac353
* Made Artifact life cycle symmetric: setup/endOfLife.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
69 public static final String DEFAULT_PASSWORD = ""; |
e8626caac353
* Made Artifact life cycle symmetric: setup/endOfLife.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
70 |
e8626caac353
* Made Artifact life cycle symmetric: setup/endOfLife.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
71 private DBConnection() { |
e8626caac353
* Made Artifact life cycle symmetric: setup/endOfLife.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
72 } |
e8626caac353
* Made Artifact life cycle symmetric: setup/endOfLife.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
73 |
87
0f48188a6e02
Added some javadoc to the artifactdatabase module. Not done yet.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
38
diff
changeset
|
74 /** |
0f48188a6e02
Added some javadoc to the artifactdatabase module. Not done yet.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
38
diff
changeset
|
75 * Constructs the default databse URL. It concats the |
0f48188a6e02
Added some javadoc to the artifactdatabase module. Not done yet.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
38
diff
changeset
|
76 * config directory and the #DEFAULT_DATABASE_FILE |
0f48188a6e02
Added some javadoc to the artifactdatabase module. Not done yet.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
38
diff
changeset
|
77 * to the string with is needed to access H2 databases. |
89
d348fe1fd822
More javadoc (fixes small glitches, too).
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
87
diff
changeset
|
78 * @return The default URL. |
87
0f48188a6e02
Added some javadoc to the artifactdatabase module. Not done yet.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
38
diff
changeset
|
79 */ |
19
1259d192e3c3
* New configuration based on config directory
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
12
diff
changeset
|
80 public static final String getDefaultURL() { |
1259d192e3c3
* New configuration based on config directory
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
12
diff
changeset
|
81 File configDir = Config.getConfigDirectory(); |
1259d192e3c3
* New configuration based on config directory
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
12
diff
changeset
|
82 File databaseFile = new File(configDir, DEFAULT_DATABASE_FILE); |
1259d192e3c3
* New configuration based on config directory
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
12
diff
changeset
|
83 return "jdbc:h2:" + databaseFile; |
1259d192e3c3
* New configuration based on config directory
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
12
diff
changeset
|
84 } |
1259d192e3c3
* New configuration based on config directory
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
12
diff
changeset
|
85 |
10
e8626caac353
* Made Artifact life cycle symmetric: setup/endOfLife.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
86 private static BasicDataSource dataSource; |
e8626caac353
* Made Artifact life cycle symmetric: setup/endOfLife.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
87 |
e8626caac353
* Made Artifact life cycle symmetric: setup/endOfLife.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
88 private static final void addShutdownHook() { |
e8626caac353
* Made Artifact life cycle symmetric: setup/endOfLife.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
89 Runtime.getRuntime().addShutdownHook(new Thread() { |
87
0f48188a6e02
Added some javadoc to the artifactdatabase module. Not done yet.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
38
diff
changeset
|
90 @Override |
10
e8626caac353
* Made Artifact life cycle symmetric: setup/endOfLife.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
91 public void run() { |
e8626caac353
* Made Artifact life cycle symmetric: setup/endOfLife.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
92 if (dataSource != null) { |
e8626caac353
* Made Artifact life cycle symmetric: setup/endOfLife.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
93 try { |
e8626caac353
* Made Artifact life cycle symmetric: setup/endOfLife.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
94 dataSource.close(); |
e8626caac353
* Made Artifact life cycle symmetric: setup/endOfLife.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
95 } |
e8626caac353
* Made Artifact life cycle symmetric: setup/endOfLife.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
96 catch (SQLException sqle) { |
e8626caac353
* Made Artifact life cycle symmetric: setup/endOfLife.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
97 } |
e8626caac353
* Made Artifact life cycle symmetric: setup/endOfLife.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
98 dataSource = null; |
e8626caac353
* Made Artifact life cycle symmetric: setup/endOfLife.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
99 } |
e8626caac353
* Made Artifact life cycle symmetric: setup/endOfLife.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
100 } |
e8626caac353
* Made Artifact life cycle symmetric: setup/endOfLife.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
101 }); |
e8626caac353
* Made Artifact life cycle symmetric: setup/endOfLife.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
102 } |
e8626caac353
* Made Artifact life cycle symmetric: setup/endOfLife.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
103 |
87
0f48188a6e02
Added some javadoc to the artifactdatabase module. Not done yet.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
38
diff
changeset
|
104 /** |
0f48188a6e02
Added some javadoc to the artifactdatabase module. Not done yet.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
38
diff
changeset
|
105 * Static method to fetch a database connection. |
0f48188a6e02
Added some javadoc to the artifactdatabase module. Not done yet.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
38
diff
changeset
|
106 * @return a DataSource to access the database connection. |
0f48188a6e02
Added some javadoc to the artifactdatabase module. Not done yet.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
38
diff
changeset
|
107 */ |
10
e8626caac353
* Made Artifact life cycle symmetric: setup/endOfLife.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
108 public static synchronized DataSource getDataSource() { |
e8626caac353
* Made Artifact life cycle symmetric: setup/endOfLife.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
109 if (dataSource == null) { |
e8626caac353
* Made Artifact life cycle symmetric: setup/endOfLife.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
110 dataSource = new BasicDataSource(); |
e8626caac353
* Made Artifact life cycle symmetric: setup/endOfLife.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
111 |
e8626caac353
* Made Artifact life cycle symmetric: setup/endOfLife.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
112 String driver = Config.getStringXPath( |
e8626caac353
* Made Artifact life cycle symmetric: setup/endOfLife.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
113 DB_DRIVER, DEFAULT_DRIVER); |
e8626caac353
* Made Artifact life cycle symmetric: setup/endOfLife.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
114 |
e8626caac353
* Made Artifact life cycle symmetric: setup/endOfLife.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
115 String url = Config.getStringXPath( |
e8626caac353
* Made Artifact life cycle symmetric: setup/endOfLife.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
116 DB_URL, DEFAULT_URL); |
e8626caac353
* Made Artifact life cycle symmetric: setup/endOfLife.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
117 |
e8626caac353
* Made Artifact life cycle symmetric: setup/endOfLife.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
118 String user = Config.getStringXPath( |
e8626caac353
* Made Artifact life cycle symmetric: setup/endOfLife.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
119 DB_USER, DEFAULT_USER); |
e8626caac353
* Made Artifact life cycle symmetric: setup/endOfLife.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
120 |
e8626caac353
* Made Artifact life cycle symmetric: setup/endOfLife.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
121 String password = Config.getStringXPath( |
e8626caac353
* Made Artifact life cycle symmetric: setup/endOfLife.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
122 DB_PASSWORD, DEFAULT_PASSWORD); |
e8626caac353
* Made Artifact life cycle symmetric: setup/endOfLife.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
123 |
38
93edc04f3a10
Added postgresql support.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
19
diff
changeset
|
124 logger.info("database driver: " + driver); |
93edc04f3a10
Added postgresql support.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
19
diff
changeset
|
125 logger.info("database url: " + url); |
93edc04f3a10
Added postgresql support.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
19
diff
changeset
|
126 |
10
e8626caac353
* Made Artifact life cycle symmetric: setup/endOfLife.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
127 dataSource.setDriverClassName(driver); |
e8626caac353
* Made Artifact life cycle symmetric: setup/endOfLife.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
128 dataSource.setUsername(user); |
e8626caac353
* Made Artifact life cycle symmetric: setup/endOfLife.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
129 dataSource.setPassword(password); |
e8626caac353
* Made Artifact life cycle symmetric: setup/endOfLife.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
130 dataSource.setUrl(url); |
e8626caac353
* Made Artifact life cycle symmetric: setup/endOfLife.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
131 addShutdownHook(); |
e8626caac353
* Made Artifact life cycle symmetric: setup/endOfLife.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
132 } |
e8626caac353
* Made Artifact life cycle symmetric: setup/endOfLife.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
133 |
e8626caac353
* Made Artifact life cycle symmetric: setup/endOfLife.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
134 return dataSource; |
e8626caac353
* Made Artifact life cycle symmetric: setup/endOfLife.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
135 } |
e8626caac353
* Made Artifact life cycle symmetric: setup/endOfLife.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
136 } |
91
730ff077a58c
More javadoc, some code formatting.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
89
diff
changeset
|
137 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : |