summaryrefslogtreecommitdiff
path: root/src/main/java/com/amazon/carbonado/repo
diff options
context:
space:
mode:
authorBrian S. O'Neill <bronee@gmail.com>2006-11-23 00:35:18 +0000
committerBrian S. O'Neill <bronee@gmail.com>2006-11-23 00:35:18 +0000
commit0ece63c797c344a51705fce885b48a84c4a94441 (patch)
tree123db3a69e05e2bfec62aa43f91dd4efb11111b0 /src/main/java/com/amazon/carbonado/repo
parent017b1aee4eb9a460a484aa58f9f17200d43cec15 (diff)
Query filter constants appear as SQL constants.
Diffstat (limited to 'src/main/java/com/amazon/carbonado/repo')
-rw-r--r--src/main/java/com/amazon/carbonado/repo/jdbc/JDBCStorage.java50
1 files changed, 43 insertions, 7 deletions
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();
+ }
}
}
}