From b22735e5dbc22539a6bf9d36cff042094c50d927 Mon Sep 17 00:00:00 2001 From: Abyss777 Date: Fri, 21 Jul 2017 10:12:27 +0500 Subject: Add helper function to generate request string name --- src/org/traccar/database/DataManager.java | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) (limited to 'src/org/traccar') diff --git a/src/org/traccar/database/DataManager.java b/src/org/traccar/database/DataManager.java index 39ffe6552..39a80ee72 100644 --- a/src/org/traccar/database/DataManager.java +++ b/src/org/traccar/database/DataManager.java @@ -268,10 +268,14 @@ public class DataManager { .executeUpdate()); } + private String makeName(String object) { + return object.substring(0, 1).toUpperCase() + object.replace("Id", "").substring(1); + } + public void linkObject(Map permission, boolean link) throws SQLException { String query = "database." + (!link ? "un" : "") + "link"; for (String key : permission.keySet()) { - query += key.substring(0, 1).toUpperCase() + key.replace("Id", "").substring(1); + query += makeName(key); } QueryBuilder queryBuilder = QueryBuilder.create(dataSource, getQuery(query)); for (String key : permission.keySet()) { @@ -286,10 +290,7 @@ public class DataManager { } public Collection> getPermissions(String owner, String property) throws SQLException { - String query = "database.select" - + owner.substring(0, 1).toUpperCase() + owner.substring(1) - + property.substring(0, 1).toUpperCase() + property.substring(1) - + "s"; + String query = "database.select" + makeName(owner) + makeName(property) + "s"; return QueryBuilder.create(dataSource, getQuery(query)).executeMapQuery(Long.class); } -- cgit v1.2.3