aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAbyss777 <abyss@fox5.ru>2017-07-31 17:31:42 +0500
committerAbyss777 <abyss@fox5.ru>2017-07-31 17:31:42 +0500
commit01de09dcdf4a746bac66e1f700f8c6eb2c96c6ae (patch)
treeba5b3f3b1c476b47921a1bc7d8cb0595988766bf /src
parentae76cbf971bfc9e47ef21e87606dacc7c0e3ddc6 (diff)
downloadtraccar-server-01de09dcdf4a746bac66e1f700f8c6eb2c96c6ae.tar.gz
traccar-server-01de09dcdf4a746bac66e1f700f8c6eb2c96c6ae.tar.bz2
traccar-server-01de09dcdf4a746bac66e1f700f8c6eb2c96c6ae.zip
- Rename QueryAdditional to QueryExtended
- Use Introspector.decapitalize - Replace new lines with spaces - Fixed indentation - Fixed extended query name
Diffstat (limited to 'src')
-rw-r--r--src/org/traccar/database/DataManager.java45
-rw-r--r--src/org/traccar/database/QueryExtended.java (renamed from src/org/traccar/database/QueryAdditional.java)2
-rw-r--r--src/org/traccar/model/Device.java4
-rw-r--r--src/org/traccar/model/User.java6
4 files changed, 29 insertions, 28 deletions
diff --git a/src/org/traccar/database/DataManager.java b/src/org/traccar/database/DataManager.java
index a753c311b..3d89cc3d1 100644
--- a/src/org/traccar/database/DataManager.java
+++ b/src/org/traccar/database/DataManager.java
@@ -15,6 +15,7 @@
*/
package org.traccar.database;
+import java.beans.Introspector;
import java.io.File;
import java.lang.reflect.Method;
import java.net.URL;
@@ -124,7 +125,7 @@ public class DataManager {
}
}
- public static String constructObjectQuery(String action, Class<?> clazz, boolean additional) {
+ public static String constructObjectQuery(String action, Class<?> clazz, boolean extended) {
switch (action) {
case ACTION_INSERT:
case ACTION_UPDATE:
@@ -136,17 +137,20 @@ public class DataManager {
methods.removeAll(Arrays.asList(Object.class.getMethods()));
methods.removeAll(Arrays.asList(BaseModel.class.getMethods()));
for (Method method : methods) {
- if (method.getName().startsWith("get") && method.getParameterTypes().length == 0
- && (additional ? method.isAnnotationPresent(QueryAdditional.class)
- : !method.isAnnotationPresent(QueryIgnore.class)
- && !method.isAnnotationPresent(QueryAdditional.class))) {
- String name = method.getName().substring(3, 4).toLowerCase()
- + method.getName().substring(4);
+ boolean skip;
+ if (extended) {
+ skip = !method.isAnnotationPresent(QueryExtended.class);
+ } else {
+ skip = method.isAnnotationPresent(QueryIgnore.class)
+ || method.isAnnotationPresent(QueryExtended.class);
+ }
+ if (!skip && method.getName().startsWith("get") && method.getParameterTypes().length == 0) {
+ String name = Introspector.decapitalize(method.getName().substring(3));
if (action.equals(ACTION_INSERT)) {
fields.append(name).append(", ");
values.append(":").append(name).append(", ");
} else {
- fields.append(name).append(" = :").append(name).append(",\n");
+ fields.append(name).append(" = :").append(name).append(", ");
}
}
}
@@ -154,12 +158,12 @@ public class DataManager {
if (action.equals(ACTION_INSERT)) {
values.setLength(values.length() - 2);
result.append("INSERT INTO ").append(getObjectsTableName(clazz)).append(" (");
- result.append(fields).append(")\n");
+ result.append(fields).append(") ");
result.append("VALUES (").append(values).append(")");
} else {
- result.append("UPDATE ").append(getObjectsTableName(clazz)).append(" SET\n");
+ result.append("UPDATE ").append(getObjectsTableName(clazz)).append(" SET ");
result.append(fields);
- result.append("\nWHERE id = :id");
+ result.append(" WHERE id = :id");
}
return result.toString();
case ACTION_SELECT_ALL:
@@ -170,7 +174,7 @@ public class DataManager {
return "DELETE FROM " + getObjectsTableName(clazz) + " WHERE id = :id";
default:
throw new IllegalArgumentException("Unknown action");
- }
+ }
}
public static String constructPermissionQuery(String action, Class<?> owner, Class<?> property) {
@@ -188,7 +192,7 @@ public class DataManager {
+ " AND " + makeNameId(property) + " = :" + makeNameId(property);
default:
throw new IllegalArgumentException("Unknown action");
- }
+ }
}
private String getQuery(String key) {
@@ -203,16 +207,16 @@ public class DataManager {
return getQuery(action, clazz, false);
}
- public String getQuery(String action, Class<?> clazz, boolean additional) {
+ public String getQuery(String action, Class<?> clazz, boolean extended) {
String queryName;
if (action.equals(ACTION_SELECT_ALL)) {
queryName = "database.select" + clazz.getSimpleName() + "s";
} else {
- queryName = "database." + action.toLowerCase() + clazz.getSimpleName();
+ queryName = "database." + action.toLowerCase() + clazz.getSimpleName() + (extended ? "Extended" : "");
}
String query = config.getString(queryName);
if (query == null) {
- query = constructObjectQuery(action, clazz, additional);
+ query = constructObjectQuery(action, clazz, extended);
config.setString(queryName, query);
}
@@ -238,18 +242,15 @@ public class DataManager {
}
private static String getPermissionsTableName(Class<?> owner, Class<?> property) {
- String ownerName = owner.getSimpleName();
String propertyName = property.getSimpleName();
if (propertyName.equals("ManagedUser")) {
propertyName = "User";
}
- return ownerName.substring(0, 1).toLowerCase() + ownerName.substring(1) + "_"
- + propertyName.substring(0, 1).toLowerCase() + propertyName.substring(1);
+ return Introspector.decapitalize(owner.getSimpleName()) + "_" + Introspector.decapitalize(propertyName);
}
private static String getObjectsTableName(Class<?> clazz) {
- String name = clazz.getSimpleName();
- return name.substring(0, 1).toLowerCase() + name.substring(1) + "s";
+ return Introspector.decapitalize(clazz.getSimpleName()) + "s";
}
private void initDatabaseSchema() throws SQLException, LiquibaseException {
@@ -399,7 +400,7 @@ public class DataManager {
public static String makeNameId(Class<?> clazz) {
String name = clazz.getSimpleName();
- return name.substring(0, 1).toLowerCase() + name.substring(1) + (name.indexOf("Id") == -1 ? "Id" : "");
+ return Introspector.decapitalize(name) + (name.indexOf("Id") == -1 ? "Id" : "");
}
public Collection<Permission> getPermissions(Class<? extends BaseModel> owner, Class<? extends BaseModel> property)
diff --git a/src/org/traccar/database/QueryAdditional.java b/src/org/traccar/database/QueryExtended.java
index 7a42c1875..07bc2c211 100644
--- a/src/org/traccar/database/QueryAdditional.java
+++ b/src/org/traccar/database/QueryExtended.java
@@ -23,5 +23,5 @@ import java.lang.annotation.Target;
@Target(ElementType.METHOD)
@Retention(RetentionPolicy.RUNTIME)
-public @interface QueryAdditional {
+public @interface QueryExtended {
}
diff --git a/src/org/traccar/model/Device.java b/src/org/traccar/model/Device.java
index cd5dd12c4..c8a28404c 100644
--- a/src/org/traccar/model/Device.java
+++ b/src/org/traccar/model/Device.java
@@ -18,7 +18,7 @@ package org.traccar.model;
import java.util.Date;
import java.util.List;
-import org.traccar.database.QueryAdditional;
+import org.traccar.database.QueryExtended;
import org.traccar.database.QueryIgnore;
public class Device extends ExtendedModel {
@@ -60,7 +60,7 @@ public class Device extends ExtendedModel {
private Date lastUpdate;
- @QueryAdditional
+ @QueryExtended
public Date getLastUpdate() {
if (lastUpdate != null) {
return new Date(lastUpdate.getTime());
diff --git a/src/org/traccar/model/User.java b/src/org/traccar/model/User.java
index 72b53ee5d..b71666f87 100644
--- a/src/org/traccar/model/User.java
+++ b/src/org/traccar/model/User.java
@@ -17,7 +17,7 @@ package org.traccar.model;
import com.fasterxml.jackson.annotation.JsonIgnore;
-import org.traccar.database.QueryAdditional;
+import org.traccar.database.QueryExtended;
import org.traccar.database.QueryIgnore;
import org.traccar.helper.Hashing;
@@ -247,7 +247,7 @@ public class User extends ExtendedModel {
private String hashedPassword;
@JsonIgnore
- @QueryAdditional
+ @QueryExtended
public String getHashedPassword() {
return hashedPassword;
}
@@ -259,7 +259,7 @@ public class User extends ExtendedModel {
private String salt;
@JsonIgnore
- @QueryAdditional
+ @QueryExtended
public String getSalt() {
return salt;
}