aboutsummaryrefslogtreecommitdiff
path: root/src/org/traccar/database/QueryBuilder.java
diff options
context:
space:
mode:
authorAnton Tananaev <anton.tananaev@gmail.com>2015-06-10 15:45:55 +1200
committerAnton Tananaev <anton.tananaev@gmail.com>2015-06-10 15:45:55 +1200
commitee087f587a96700d91e407d434e94d1616c18368 (patch)
treefc9642ed3159dd16ebd1c5448233b251b091921c /src/org/traccar/database/QueryBuilder.java
parentee4c07115d3bc3e58b92310f54bee7bd616ec669 (diff)
parent96a2d024658746f50628727f7255c4e19ecdb1b4 (diff)
downloadtrackermap-server-ee087f587a96700d91e407d434e94d1616c18368.tar.gz
trackermap-server-ee087f587a96700d91e407d434e94d1616c18368.tar.bz2
trackermap-server-ee087f587a96700d91e407d434e94d1616c18368.zip
Merge pull request #1240 from demianalonso/master
Move SQL queries to the config file
Diffstat (limited to 'src/org/traccar/database/QueryBuilder.java')
-rw-r--r--src/org/traccar/database/QueryBuilder.java22
1 files changed, 22 insertions, 0 deletions
diff --git a/src/org/traccar/database/QueryBuilder.java b/src/org/traccar/database/QueryBuilder.java
index ff26221de..05ec3e35c 100644
--- a/src/org/traccar/database/QueryBuilder.java
+++ b/src/org/traccar/database/QueryBuilder.java
@@ -15,6 +15,7 @@
*/
package org.traccar.database;
+import java.lang.reflect.Array;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.sql.Connection;
@@ -31,7 +32,9 @@ import java.util.HashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
+
import javax.sql.DataSource;
+
import org.traccar.model.Factory;
public class QueryBuilder {
@@ -211,6 +214,23 @@ public class QueryBuilder {
return this;
}
+ public QueryBuilder setBytes(String name, byte[] value) throws SQLException {
+ for (int i : indexes(name)) {
+ try {
+ if (value == null) {
+ statement.setNull(i, Types.VARCHAR);
+ } else {
+ statement.setBytes(i, value);
+ }
+ } catch (SQLException error) {
+ statement.close();
+ connection.close();
+ throw error;
+ }
+ }
+ return this;
+ }
+
public QueryBuilder setObject(Object object) throws SQLException {
Method[] methods = object.getClass().getMethods();
@@ -231,6 +251,8 @@ public class QueryBuilder {
setString(name, (String) method.invoke(object));
} else if (method.getReturnType().equals(Date.class)) {
setDate(name, (Date) method.invoke(object));
+ } else if (method.getReturnType().equals(byte[].class)) {
+ setBytes(name, (byte[]) method.invoke(object));
}
} catch (IllegalAccessException error) {
} catch (InvocationTargetException error) {