aboutsummaryrefslogtreecommitdiff
path: root/src/org/traccar/database/QueryBuilder.java
diff options
context:
space:
mode:
authorAnton Tananaev <anton.tananaev@gmail.com>2017-07-23 18:29:36 +1200
committerGitHub <noreply@github.com>2017-07-23 18:29:36 +1200
commit4b2372336d0496c85befe099914434e5b68f05b3 (patch)
tree798de625a07c18287e829b3a037cacee179ebcff /src/org/traccar/database/QueryBuilder.java
parentba82047a492be54545961716814584d8880d28ae (diff)
parent5a65c0d6be8ffc2db0ffdb0c35ecedfb2b3750c7 (diff)
downloadtrackermap-server-4b2372336d0496c85befe099914434e5b68f05b3.tar.gz
trackermap-server-4b2372336d0496c85befe099914434e5b68f05b3.tar.bz2
trackermap-server-4b2372336d0496c85befe099914434e5b68f05b3.zip
Merge pull request #3373 from Abyss777/refactor_managers
Refactor managers, permissions etc
Diffstat (limited to 'src/org/traccar/database/QueryBuilder.java')
-rw-r--r--src/org/traccar/database/QueryBuilder.java25
1 files changed, 25 insertions, 0 deletions
diff --git a/src/org/traccar/database/QueryBuilder.java b/src/org/traccar/database/QueryBuilder.java
index a24e6f0bf..440690a76 100644
--- a/src/org/traccar/database/QueryBuilder.java
+++ b/src/org/traccar/database/QueryBuilder.java
@@ -35,6 +35,7 @@ import java.sql.Types;
import java.util.Collection;
import java.util.Date;
import java.util.HashMap;
+import java.util.LinkedHashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
@@ -487,4 +488,28 @@ public final class QueryBuilder {
return 0;
}
+ public <T> Collection<Map<String, T>> executeMapQuery(Class<T> clazz) throws SQLException {
+ List<Map<String, T>> result = new LinkedList<>();
+ if (query != null) {
+ try {
+ try (ResultSet resultSet = statement.executeQuery()) {
+ ResultSetMetaData resultMetaData = resultSet.getMetaData();
+ while (resultSet.next()) {
+ LinkedHashMap<String, T> map = new LinkedHashMap<>();
+ for (int i = 1; i <= resultMetaData.getColumnCount(); i++) {
+ String label = resultMetaData.getColumnLabel(i);
+ map.put(label, resultSet.getObject(label, clazz));
+ }
+ result.add(map);
+ }
+ }
+ } finally {
+ statement.close();
+ connection.close();
+ }
+ }
+
+ return result;
+ }
+
}