aboutsummaryrefslogtreecommitdiff
path: root/src/org/traccar/database/QueryBuilder.java
diff options
context:
space:
mode:
authorAnton Tananaev <anton.tananaev@gmail.com>2016-12-16 00:28:26 +1300
committerGitHub <noreply@github.com>2016-12-16 00:28:26 +1300
commit835853422ce9f1c1fde15a6464c6f0f7eda4fed7 (patch)
tree049fa09050caec98242a0f642d478a533cee5898 /src/org/traccar/database/QueryBuilder.java
parentf76c78a68f249ddb45a2bbae11dd95dd6db743b6 (diff)
parentef9148eea8dd404aba5707898f244a4b7bc26feb (diff)
downloadtrackermap-server-835853422ce9f1c1fde15a6464c6f0f7eda4fed7.tar.gz
trackermap-server-835853422ce9f1c1fde15a6464c6f0f7eda4fed7.tar.bz2
trackermap-server-835853422ce9f1c1fde15a6464c6f0f7eda4fed7.zip
Merge pull request #2686 from Abyss777/calendars
Calendars implementation
Diffstat (limited to 'src/org/traccar/database/QueryBuilder.java')
-rw-r--r--src/org/traccar/database/QueryBuilder.java30
1 files changed, 30 insertions, 0 deletions
diff --git a/src/org/traccar/database/QueryBuilder.java b/src/org/traccar/database/QueryBuilder.java
index 50d689a2a..201240f2f 100644
--- a/src/org/traccar/database/QueryBuilder.java
+++ b/src/org/traccar/database/QueryBuilder.java
@@ -240,6 +240,23 @@ public final class QueryBuilder {
return this;
}
+ public QueryBuilder setBlob(String name, byte[] value) throws SQLException {
+ for (int i : indexes(name)) {
+ try {
+ if (value == null) {
+ statement.setNull(i, Types.BLOB);
+ } 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();
@@ -260,6 +277,8 @@ public final 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)) {
+ setBlob(name, (byte[]) method.invoke(object));
} else if (method.getReturnType().equals(Map.class)) {
if (Context.getConfig().getBoolean("database.xml")) {
setString(name, MiscFormatter.toXmlString((Map) method.invoke(object)));
@@ -375,6 +394,17 @@ public final class QueryBuilder {
}
}
});
+ } else if (parameterType.equals(byte[].class)) {
+ processors.add(new ResultSetProcessor<T>() {
+ @Override
+ public void process(T object, ResultSet resultSet) throws SQLException {
+ try {
+ method.invoke(object, resultSet.getBytes(name));
+ } catch (IllegalAccessException | InvocationTargetException error) {
+ Log.warning(error);
+ }
+ }
+ });
}
}