diff options
-rw-r--r-- | .checkstyle | 10 | ||||
-rw-r--r-- | pom.xml | 6 | ||||
-rw-r--r-- | src/org/traccar/BaseProtocol.java | 3 | ||||
-rw-r--r-- | src/org/traccar/database/DataManager.java | 64 | ||||
-rw-r--r-- | src/org/traccar/helper/PatternUtil.java | 18 | ||||
-rw-r--r-- | test/org/traccar/helper/PatternUtilTest.java | 2 |
6 files changed, 66 insertions, 37 deletions
diff --git a/.checkstyle b/.checkstyle new file mode 100644 index 000000000..96f43bf8f --- /dev/null +++ b/.checkstyle @@ -0,0 +1,10 @@ +<?xml version="1.0" encoding="UTF-8"?> + +<fileset-config file-format-version="1.2.0" simple-config="true" sync-formatter="false"> + <fileset name="all" enabled="true" check-config-name="Traccar Style" local="false"> + <file-match-pattern match-pattern="." include-pattern="true"/> + </fileset> + <filter name="FilesFromPackage" enabled="true"> + <filter-data value="test"/> + </filter> +</fileset-config> @@ -48,9 +48,9 @@ <version>9.4.1208.jre7</version> </dependency> <dependency> - <groupId>com.mchange</groupId> - <artifactId>c3p0</artifactId> - <version>0.9.5.2</version> + <groupId>com.zaxxer</groupId> + <artifactId>HikariCP</artifactId> + <version>2.4.5</version> </dependency> <dependency> <groupId>io.netty</groupId> diff --git a/src/org/traccar/BaseProtocol.java b/src/org/traccar/BaseProtocol.java index d1791d673..f968e81cc 100644 --- a/src/org/traccar/BaseProtocol.java +++ b/src/org/traccar/BaseProtocol.java @@ -61,7 +61,8 @@ public abstract class BaseProtocol implements Protocol { } } else { if (!supportedCommands.contains(command.getType())) { - throw new RuntimeException("Command " + command.getType() + " is not supported in protocol " + getName()); + throw new RuntimeException("Command " + + command.getType() + " is not supported in protocol " + getName()); } activeDevice.write(command); } diff --git a/src/org/traccar/database/DataManager.java b/src/org/traccar/database/DataManager.java index dffb8937c..839cf8cad 100644 --- a/src/org/traccar/database/DataManager.java +++ b/src/org/traccar/database/DataManager.java @@ -15,7 +15,25 @@ */ 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.Calendar; +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,35 +41,21 @@ 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; import org.traccar.model.Device; -import org.traccar.model.Event; import org.traccar.model.DevicePermission; +import org.traccar.model.Event; import org.traccar.model.Group; import org.traccar.model.GroupPermission; 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.Calendar; -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 { @@ -108,19 +112,21 @@ 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 hikariConfig = new HikariConfig(); + hikariConfig.setDriverClassName(config.getString("database.driver")); + hikariConfig.setJdbcUrl(config.getString("database.url")); + hikariConfig.setUsername(config.getString("database.user")); + hikariConfig.setPassword(config.getString("database.password")); + hikariConfig.setConnectionInitSql("SELECT 1 FROM DUAL"); + hikariConfig.setIdleTimeout(600000); + int maxPoolSize = config.getInteger("database.maxPoolSize"); + if (maxPoolSize != 0) { - ds.setMaxPoolSize(maxPoolSize); + hikariConfig.setMaximumPoolSize(maxPoolSize); } - dataSource = ds; + + dataSource = new HikariDataSource(hikariConfig); } } diff --git a/src/org/traccar/helper/PatternUtil.java b/src/org/traccar/helper/PatternUtil.java index 3d61cc698..88c3f053b 100644 --- a/src/org/traccar/helper/PatternUtil.java +++ b/src/org/traccar/helper/PatternUtil.java @@ -25,9 +25,21 @@ public final class PatternUtil { } public static class MatchResult { - public String pattern; - public String matched; - public String remaining; + private String pattern; + private String matched; + private String remaining; + + public String getPattern() { + return this.pattern; + } + + public String getMatched() { + return this.matched; + } + + public String getRemaining() { + return this.remaining; + } } public static MatchResult checkPattern(String pattern, String input) { diff --git a/test/org/traccar/helper/PatternUtilTest.java b/test/org/traccar/helper/PatternUtilTest.java index 9d8ed9bbd..bb1349363 100644 --- a/test/org/traccar/helper/PatternUtilTest.java +++ b/test/org/traccar/helper/PatternUtilTest.java @@ -9,7 +9,7 @@ public class PatternUtilTest { @Test public void testCheckPattern() { - assertEquals("ab", PatternUtil.checkPattern("abc", "abd").pattern); + assertEquals("ab", PatternUtil.checkPattern("abc", "abd").getPattern()); } |