aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authordrecchia <danilo@deltatecnologia.com>2016-05-30 22:57:21 -0300
committerdrecchia <danilo@deltatecnologia.com>2016-05-30 22:57:21 -0300
commite91153481a220235130a277d20f724b97fcfd325 (patch)
treeaeaa16ce2481c778011b2a018ade5911c899b901
parent4176894097bb9f3d06ff339e9e845c4969ca6874 (diff)
downloadtraccar-server-e91153481a220235130a277d20f724b97fcfd325.tar.gz
traccar-server-e91153481a220235130a277d20f724b97fcfd325.tar.bz2
traccar-server-e91153481a220235130a277d20f724b97fcfd325.zip
- Replaced connection poll from c3p0 to HikariCP.
-rw-r--r--pom.xml8
-rw-r--r--src/org/traccar/database/DataManager.java62
2 files changed, 39 insertions, 31 deletions
diff --git a/pom.xml b/pom.xml
index 0b0d7c19b..dd8c5e5fa 100644
--- a/pom.xml
+++ b/pom.xml
@@ -48,10 +48,10 @@
<version>9.4.1208.jre7</version>
</dependency>
<dependency>
- <groupId>com.mchange</groupId>
- <artifactId>c3p0</artifactId>
- <version>0.9.5.2</version>
- </dependency>
+ <groupId>com.zaxxer</groupId>
+ <artifactId>HikariCP</artifactId>
+ <version>2.4.5</version>
+ </dependency>
<dependency>
<groupId>io.netty</groupId>
<artifactId>netty</artifactId>
diff --git a/src/org/traccar/database/DataManager.java b/src/org/traccar/database/DataManager.java
index ac3be45ac..898669c21 100644
--- a/src/org/traccar/database/DataManager.java
+++ b/src/org/traccar/database/DataManager.java
@@ -15,7 +15,24 @@
*/
package org.traccar.database;
-import com.mchange.v2.c3p0.ComboPooledDataSource;
+import java.io.File;
+import java.lang.reflect.Method;
+import java.net.URL;
+import java.net.URLClassLoader;
+import java.sql.SQLException;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Date;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Map;
+import java.util.Set;
+import java.util.concurrent.locks.ReadWriteLock;
+import java.util.concurrent.locks.ReentrantReadWriteLock;
+
+import javax.naming.InitialContext;
+import javax.sql.DataSource;
+
import liquibase.Contexts;
import liquibase.Liquibase;
import liquibase.database.Database;
@@ -23,6 +40,7 @@ import liquibase.database.DatabaseFactory;
import liquibase.exception.LiquibaseException;
import liquibase.resource.FileSystemResourceAccessor;
import liquibase.resource.ResourceAccessor;
+
import org.traccar.Config;
import org.traccar.Context;
import org.traccar.helper.Log;
@@ -34,22 +52,8 @@ import org.traccar.model.Position;
import org.traccar.model.Server;
import org.traccar.model.User;
-import javax.naming.InitialContext;
-import javax.sql.DataSource;
-import java.io.File;
-import java.lang.reflect.Method;
-import java.net.URL;
-import java.net.URLClassLoader;
-import java.sql.SQLException;
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.Date;
-import java.util.HashMap;
-import java.util.HashSet;
-import java.util.Map;
-import java.util.Set;
-import java.util.concurrent.locks.ReadWriteLock;
-import java.util.concurrent.locks.ReentrantReadWriteLock;
+import com.zaxxer.hikari.HikariConfig;
+import com.zaxxer.hikari.HikariDataSource;
public class DataManager implements IdentityManager {
@@ -106,19 +110,23 @@ public class DataManager implements IdentityManager {
Class.forName(driver);
}
- ComboPooledDataSource ds = new ComboPooledDataSource();
- ds.setDriverClass(config.getString("database.driver"));
- ds.setJdbcUrl(config.getString("database.url"));
- ds.setUser(config.getString("database.user"));
- ds.setPassword(config.getString("database.password"));
- ds.setIdleConnectionTestPeriod(600);
- ds.setTestConnectionOnCheckin(true);
- ds.setMaxStatementsPerConnection(config.getInteger("database.maxStatements"));
+ HikariConfig hConfig = new HikariConfig();
+ hConfig.setDriverClassName( config.getString("database.driver") );
+ hConfig.setJdbcUrl( config.getString("database.url") );
+ hConfig.setUsername( config.getString("database.user") );
+ hConfig.setPassword( config.getString("database.password") );
+ hConfig.setConnectionInitSql( "SELECT 1 FROM DUAL" );
+ hConfig.setIdleTimeout( 600000 ); // milliseconds
+// ds.setIdleConnectionTestPeriod(600);
+// ds.setMaxStatementsPerConnection(config.getInteger("database.maxStatements"));
+
int maxPoolSize = config.getInteger("database.maxPoolSize");
+
if (maxPoolSize != 0) {
- ds.setMaxPoolSize(maxPoolSize);
+ hConfig.setMaximumPoolSize( maxPoolSize );
}
- dataSource = ds;
+
+ dataSource = new HikariDataSource(hConfig);
}
}