diff options
author | Abyss777 <abyss@fox5.ru> | 2016-12-14 17:34:34 +0500 |
---|---|---|
committer | Abyss777 <abyss@fox5.ru> | 2016-12-14 18:02:17 +0500 |
commit | fff8f0c792606daff151624479d9ae9dc54187d5 (patch) | |
tree | 97e0ab38de08aba1a7b7adf90283df82d850a3ad /src/org/traccar/database/QueryBuilder.java | |
parent | 4557cf912fada1dc249333aa05215b0116b8ebab (diff) | |
download | trackermap-server-fff8f0c792606daff151624479d9ae9dc54187d5.tar.gz trackermap-server-fff8f0c792606daff151624479d9ae9dc54187d5.tar.bz2 trackermap-server-fff8f0c792606daff151624479d9ae9dc54187d5.zip |
Calendars implementation
Diffstat (limited to 'src/org/traccar/database/QueryBuilder.java')
-rw-r--r-- | src/org/traccar/database/QueryBuilder.java | 30 |
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); + } + } + }); } } |