aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAnton Tananaev <anton.tananaev@gmail.com>2015-06-01 14:57:26 +1200
committerAnton Tananaev <anton.tananaev@gmail.com>2015-06-01 14:57:26 +1200
commit0b575b94f469cdcdb24a6f86beee5e2c86285cb1 (patch)
tree2b95fcce85d9cd8354bb6dd759ac7e5d7452934c /src
parentd310875d1bf13baa13daba2ec73107dbeaa397f7 (diff)
downloadtrackermap-server-0b575b94f469cdcdb24a6f86beee5e2c86285cb1.tar.gz
trackermap-server-0b575b94f469cdcdb24a6f86beee5e2c86285cb1.tar.bz2
trackermap-server-0b575b94f469cdcdb24a6f86beee5e2c86285cb1.zip
Support JNDI data source (fix #1229)
Diffstat (limited to 'src')
-rw-r--r--src/org/traccar/database/DataManager.java52
1 files changed, 31 insertions, 21 deletions
diff --git a/src/org/traccar/database/DataManager.java b/src/org/traccar/database/DataManager.java
index 2b7d15b3d..2698dd378 100644
--- a/src/org/traccar/database/DataManager.java
+++ b/src/org/traccar/database/DataManager.java
@@ -34,6 +34,7 @@ import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.Properties;
+import javax.naming.InitialContext;
import javax.sql.DataSource;
import org.traccar.Context;
import org.traccar.helper.DriverDelegate;
@@ -76,31 +77,40 @@ public class DataManager {
private void initDatabase(Properties properties) throws Exception {
useNewDatabase = Boolean.valueOf(properties.getProperty("http.new"));
+
+ String jndiName = properties.getProperty("database.jndi");
- // Load driver
- String driver = properties.getProperty("database.driver");
- if (driver != null) {
- String driverFile = properties.getProperty("database.driverFile");
+ if (jndiName != null) {
- if (driverFile != null) {
- URL url = new URL("jar:file:" + new File(driverFile).getAbsolutePath() + "!/");
- URLClassLoader cl = new URLClassLoader(new URL[]{url});
- Driver d = (Driver) Class.forName(driver, true, cl).newInstance();
- DriverManager.registerDriver(new DriverDelegate(d));
- } else {
- Class.forName(driver);
+ dataSource = (DataSource) new InitialContext().lookup(jndiName);
+
+ } else {
+
+ // Load driver
+ String driver = properties.getProperty("database.driver");
+ if (driver != null) {
+ String driverFile = properties.getProperty("database.driverFile");
+
+ if (driverFile != null) {
+ URL url = new URL("jar:file:" + new File(driverFile).getAbsolutePath() + "!/");
+ URLClassLoader cl = new URLClassLoader(new URL[]{url});
+ Driver d = (Driver) Class.forName(driver, true, cl).newInstance();
+ DriverManager.registerDriver(new DriverDelegate(d));
+ } else {
+ Class.forName(driver);
+ }
}
+
+ // Initialize data source
+ ComboPooledDataSource ds = new ComboPooledDataSource();
+ ds.setDriverClass(properties.getProperty("database.driver"));
+ ds.setJdbcUrl(properties.getProperty("database.url"));
+ ds.setUser(properties.getProperty("database.user"));
+ ds.setPassword(properties.getProperty("database.password"));
+ ds.setIdleConnectionTestPeriod(600);
+ ds.setTestConnectionOnCheckin(true);
+ dataSource = ds;
}
-
- // Initialize data source
- ComboPooledDataSource ds = new ComboPooledDataSource();
- ds.setDriverClass(properties.getProperty("database.driver"));
- ds.setJdbcUrl(properties.getProperty("database.url"));
- ds.setUser(properties.getProperty("database.user"));
- ds.setPassword(properties.getProperty("database.password"));
- ds.setIdleConnectionTestPeriod(600);
- ds.setTestConnectionOnCheckin(true);
- dataSource = ds;
// Load statements from configuration
String query;