diff options
author | Abyss777 <abyss@fox5.ru> | 2017-07-21 09:59:27 +0500 |
---|---|---|
committer | Abyss777 <abyss@fox5.ru> | 2017-07-21 09:59:27 +0500 |
commit | 839e741653c9b61e573fa1cdd0dad0641c79bcec (patch) | |
tree | 69ef63138122eb0d8cdebe38f678e1d0e2ff82df /src/org/traccar/database/QueryBuilder.java | |
parent | e00fbfa466b17e94f59e6ff8fefb83f08999b3ec (diff) | |
download | trackermap-server-839e741653c9b61e573fa1cdd0dad0641c79bcec.tar.gz trackermap-server-839e741653c9b61e573fa1cdd0dad0641c79bcec.tar.bz2 trackermap-server-839e741653c9b61e573fa1cdd0dad0641c79bcec.zip |
Abolish permissions classes and get permissions as Map from DB
Diffstat (limited to 'src/org/traccar/database/QueryBuilder.java')
-rw-r--r-- | src/org/traccar/database/QueryBuilder.java | 25 |
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; + } + } |