aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
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;