diff options
-rw-r--r-- | RELEASE-NOTES.txt | 4 | ||||
-rw-r--r-- | src/main/java/com/amazon/carbonado/repo/jdbc/JDBCStorage.java | 50 |
2 files changed, 47 insertions, 7 deletions
diff --git a/RELEASE-NOTES.txt b/RELEASE-NOTES.txt index da82d27..479eebf 100644 --- a/RELEASE-NOTES.txt +++ b/RELEASE-NOTES.txt @@ -1,6 +1,10 @@ Carbonado change history
------------------------
+1.1-BETA5 to 1.1-BETA6
+-------------------------------
+- Query filter constants appear as SQL constants.
+
1.1-BETA4 to 1.1-BETA5
-------------------------------
- More fixes in resync corruption repair logic.
diff --git a/src/main/java/com/amazon/carbonado/repo/jdbc/JDBCStorage.java b/src/main/java/com/amazon/carbonado/repo/jdbc/JDBCStorage.java index a1d4cd9..6f797b7 100644 --- a/src/main/java/com/amazon/carbonado/repo/jdbc/JDBCStorage.java +++ b/src/main/java/com/amazon/carbonado/repo/jdbc/JDBCStorage.java @@ -1121,25 +1121,61 @@ class JDBCStorage<S extends Storable> extends StandardQueryFactory<S> return e;
}
- mPropertyFilters.add(filter);
+ if (!filter.isConstant()) {
+ addBindParameter(filter);
+ } else {
+ RelOp op = filter.getOperator();
+
+ Object constant = filter.constant();
+ if (constant == null) {
+ if (op == RelOp.EQ) {
+ mStatementBuilder.append("IS NULL");
+ } else if (op == RelOp.NE) {
+ mStatementBuilder.append("IS NOT NULL");
+ } else {
+ mStatementBuilder.append(sqlOperatorFor(op));
+ mStatementBuilder.append("NULL");
+ }
+ } else if (filter.getType() == String.class) {
+ mStatementBuilder.append(sqlOperatorFor(op));
+ mStatementBuilder.append('\'');
+ mStatementBuilder.append(String.valueOf(constant).replace("'", "''"));
+ mStatementBuilder.append('\'');
+ } else if (Number.class.isAssignableFrom(filter.getBoxedType())) {
+ mStatementBuilder.append(sqlOperatorFor(op));
+ mStatementBuilder.append(String.valueOf(constant));
+ } else {
+ // Don't try to create literal for special type. Instead,
+ // fallback to bind parameter and let JDBC driver do the work.
+ addBindParameter(filter);
+ }
+ }
+
+ return null;
+ }
+ private void addBindParameter(PropertyFilter<S> filter) {
RelOp op = filter.getOperator();
StorableProperty<?> property = filter.getChainedProperty().getLastProperty();
+ mPropertyFilters.add(filter);
+
if (property.isNullable() && (op == RelOp.EQ || op == RelOp.NE)) {
mPropertyFilterNullable.add(true);
mStatementBuilder.append(new NullablePropertyStatement<S>(filter, op == RelOp.EQ));
} else {
mPropertyFilterNullable.add(false);
- if (op == RelOp.NE) {
- mStatementBuilder.append("<>");
- } else {
- mStatementBuilder.append(op.toString());
- }
+ mStatementBuilder.append(sqlOperatorFor(op));
mStatementBuilder.append('?');
}
+ }
- return null;
+ private String sqlOperatorFor(RelOp op) {
+ if (op == RelOp.NE) {
+ return "<>";
+ } else {
+ return op.toString();
+ }
}
}
}
|