aboutsummaryrefslogtreecommitdiff
path: root/src/org/traccar/database/QueryBuilder.java
diff options
context:
space:
mode:
authorAnton Tananaev <anton.tananaev@gmail.com>2015-05-20 18:49:30 +1200
committerAnton Tananaev <anton.tananaev@gmail.com>2015-05-20 18:49:30 +1200
commit1f9a3c81b5ddd6218e2c6b62fe0478ba147ca6e0 (patch)
tree742f5528fb49020c0f38694fddfecb5427cef5ed /src/org/traccar/database/QueryBuilder.java
parent6dfee3947ef96e1092b668ecfc7c58037355ffb8 (diff)
downloadtrackermap-server-1f9a3c81b5ddd6218e2c6b62fe0478ba147ca6e0.tar.gz
trackermap-server-1f9a3c81b5ddd6218e2c6b62fe0478ba147ca6e0.tar.bz2
trackermap-server-1f9a3c81b5ddd6218e2c6b62fe0478ba147ca6e0.zip
Ignore field if no query column
Diffstat (limited to 'src/org/traccar/database/QueryBuilder.java')
-rw-r--r--src/org/traccar/database/QueryBuilder.java19
1 files changed, 17 insertions, 2 deletions
diff --git a/src/org/traccar/database/QueryBuilder.java b/src/org/traccar/database/QueryBuilder.java
index d05f48c09..a35b07fee 100644
--- a/src/org/traccar/database/QueryBuilder.java
+++ b/src/org/traccar/database/QueryBuilder.java
@@ -19,6 +19,7 @@ import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
+import java.sql.ResultSetMetaData;
import java.sql.SQLException;
import java.sql.Statement;
import java.sql.Timestamp;
@@ -203,6 +204,9 @@ public class QueryBuilder {
public <T extends Factory> Collection<T> executeQuery(T prototype) throws SQLException {
List<T> result = new LinkedList<T>();
+ ResultSet resultSet = statement.executeQuery();
+ ResultSetMetaData resultMetaData = resultSet.getMetaData();
+
List<ResultSetProcessor<T>> processors = new LinkedList<ResultSetProcessor<T>>();
Method[] methods = prototype.getClass().getMethods();
@@ -211,6 +215,19 @@ public class QueryBuilder {
if (method.getName().startsWith("set") && method.getParameterTypes().length == 1) {
final String name = method.getName().substring(3);
+
+ // Check if column exists
+ boolean column = false;
+ for (int i = 1; i <= resultMetaData.getColumnCount(); i++) {
+ if (name.equalsIgnoreCase(resultMetaData.getColumnName(i))) {
+ column = true;
+ break;
+ }
+ }
+ if (!column) {
+ continue;
+ }
+
Class<?> parameterType = method.getParameterTypes()[0];
if (parameterType.equals(boolean.class)) {
@@ -282,8 +299,6 @@ public class QueryBuilder {
}
}
}
-
- ResultSet resultSet = statement.executeQuery();
while (resultSet.next()) {
T object = (T) prototype.create();