diff options
author | Brian S. O'Neill <bronee@gmail.com> | 2009-02-10 19:54:31 +0000 |
---|---|---|
committer | Brian S. O'Neill <bronee@gmail.com> | 2009-02-10 19:54:31 +0000 |
commit | f9780b8b92778f5bd43cf1d21d83c1999060df56 (patch) | |
tree | 5c2bae220ab5ff535a972dc990cc1a6728b0ab1b | |
parent | b7e4a392f3fded6d025c8aba8ac8393538d7dff9 (diff) |
Fix for JDBC prepared statement values when query has an exists filter.
8 files changed, 36 insertions, 14 deletions
diff --git a/src/main/java/com/amazon/carbonado/filter/AndFilter.java b/src/main/java/com/amazon/carbonado/filter/AndFilter.java index 6da6896..3ab9c48 100644 --- a/src/main/java/com/amazon/carbonado/filter/AndFilter.java +++ b/src/main/java/com/amazon/carbonado/filter/AndFilter.java @@ -68,7 +68,7 @@ public class AndFilter<S extends Storable> extends BinaryOpFilter<S> { }
@Override
- <T extends Storable> Filter<T> asJoinedFromAny(ChainedProperty<T> joinProperty) {
+ public <T extends Storable> Filter<T> asJoinedFromAny(ChainedProperty<T> joinProperty) {
return mLeft.asJoinedFromAny(joinProperty).and(mRight.asJoinedFromAny(joinProperty));
}
@@ -117,7 +117,7 @@ public class AndFilter<S extends Storable> extends BinaryOpFilter<S> { }
@Override
- public int hashCode() {
+ int generateHashCode() {
return mLeft.hashCode() * 31 + mRight.hashCode();
}
diff --git a/src/main/java/com/amazon/carbonado/filter/ClosedFilter.java b/src/main/java/com/amazon/carbonado/filter/ClosedFilter.java index 4f4b51a..0ee1b5a 100644 --- a/src/main/java/com/amazon/carbonado/filter/ClosedFilter.java +++ b/src/main/java/com/amazon/carbonado/filter/ClosedFilter.java @@ -117,7 +117,7 @@ public class ClosedFilter<S extends Storable> extends Filter<S> { }
@Override
- <T extends Storable> ClosedFilter<T> asJoinedFromAny(ChainedProperty<T> joinProperty) {
+ public <T extends Storable> ClosedFilter<T> asJoinedFromAny(ChainedProperty<T> joinProperty) {
return getClosedFilter(joinProperty.getPrimeProperty().getEnclosingType());
}
@@ -155,7 +155,7 @@ public class ClosedFilter<S extends Storable> extends Filter<S> { }
@Override
- public int hashCode() {
+ int generateHashCode() {
return getStorableType().hashCode();
}
diff --git a/src/main/java/com/amazon/carbonado/filter/ExistsFilter.java b/src/main/java/com/amazon/carbonado/filter/ExistsFilter.java index 2a7af93..98ac530 100644 --- a/src/main/java/com/amazon/carbonado/filter/ExistsFilter.java +++ b/src/main/java/com/amazon/carbonado/filter/ExistsFilter.java @@ -197,7 +197,7 @@ public class ExistsFilter<S extends Storable> extends Filter<S> { }
@Override
- <T extends Storable> ExistsFilter<T> asJoinedFromAny(ChainedProperty<T> joinProperty) {
+ public <T extends Storable> ExistsFilter<T> asJoinedFromAny(ChainedProperty<T> joinProperty) {
ChainedProperty<T> newProperty = joinProperty.append(getChainedProperty());
return getCanonical(newProperty, mSubFilter, mNot);
}
@@ -255,7 +255,7 @@ public class ExistsFilter<S extends Storable> extends Filter<S> { }
@Override
- public int hashCode() {
+ int generateHashCode() {
int hash = mProperty.hashCode() * 31 + mSubFilter.hashCode();
return mNot ? ~hash : hash;
}
diff --git a/src/main/java/com/amazon/carbonado/filter/Filter.java b/src/main/java/com/amazon/carbonado/filter/Filter.java index bec0c6b..a51f796 100644 --- a/src/main/java/com/amazon/carbonado/filter/Filter.java +++ b/src/main/java/com/amazon/carbonado/filter/Filter.java @@ -153,6 +153,8 @@ public abstract class Filter<S extends Storable> implements Serializable, Append private final Class<S> mType;
+ private transient int mHashCode;
+
// Root FilterValues, built on demand, which is immutable.
private transient volatile FilterValues<S> mFilterValues;
@@ -643,7 +645,8 @@ public abstract class Filter<S extends Storable> implements Serializable, Append /**
* Allows join from any property type, including one-to-many joins.
*/
- abstract <T extends Storable> Filter<T> asJoinedFromAny(ChainedProperty<T> joinProperty);
+ public abstract <T extends Storable> Filter<T>
+ asJoinedFromAny(ChainedProperty<T> joinProperty);
/**
* Removes a join property prefix from all applicable properties of this
@@ -766,7 +769,15 @@ public abstract class Filter<S extends Storable> implements Serializable, Append abstract void markReduced();
@Override
- public abstract int hashCode();
+ public final int hashCode() {
+ int hashCode = mHashCode;
+ if (hashCode == 0) {
+ mHashCode = hashCode = generateHashCode();
+ }
+ return hashCode;
+ }
+
+ abstract int generateHashCode();
@Override
public abstract boolean equals(Object obj);
diff --git a/src/main/java/com/amazon/carbonado/filter/OpenFilter.java b/src/main/java/com/amazon/carbonado/filter/OpenFilter.java index da23e6c..7201e26 100644 --- a/src/main/java/com/amazon/carbonado/filter/OpenFilter.java +++ b/src/main/java/com/amazon/carbonado/filter/OpenFilter.java @@ -117,7 +117,7 @@ public class OpenFilter<S extends Storable> extends Filter<S> { }
@Override
- <T extends Storable> OpenFilter<T> asJoinedFromAny(ChainedProperty<T> joinProperty) {
+ public <T extends Storable> OpenFilter<T> asJoinedFromAny(ChainedProperty<T> joinProperty) {
return getOpenFilter(joinProperty.getPrimeProperty().getEnclosingType());
}
@@ -155,7 +155,7 @@ public class OpenFilter<S extends Storable> extends Filter<S> { }
@Override
- public int hashCode() {
+ int generateHashCode() {
return getStorableType().hashCode();
}
diff --git a/src/main/java/com/amazon/carbonado/filter/OrFilter.java b/src/main/java/com/amazon/carbonado/filter/OrFilter.java index 15019b6..0d9fa2a 100644 --- a/src/main/java/com/amazon/carbonado/filter/OrFilter.java +++ b/src/main/java/com/amazon/carbonado/filter/OrFilter.java @@ -68,7 +68,7 @@ public class OrFilter<S extends Storable> extends BinaryOpFilter<S> { }
@Override
- <T extends Storable> Filter<T> asJoinedFromAny(ChainedProperty<T> joinProperty) {
+ public <T extends Storable> Filter<T> asJoinedFromAny(ChainedProperty<T> joinProperty) {
return mLeft.asJoinedFromAny(joinProperty).or(mRight.asJoinedFromAny(joinProperty));
}
@@ -132,7 +132,7 @@ public class OrFilter<S extends Storable> extends BinaryOpFilter<S> { }
@Override
- public int hashCode() {
+ int generateHashCode() {
return mLeft.hashCode() * 31 + mRight.hashCode();
}
diff --git a/src/main/java/com/amazon/carbonado/filter/PropertyFilter.java b/src/main/java/com/amazon/carbonado/filter/PropertyFilter.java index 2cecca3..0183bbf 100644 --- a/src/main/java/com/amazon/carbonado/filter/PropertyFilter.java +++ b/src/main/java/com/amazon/carbonado/filter/PropertyFilter.java @@ -237,7 +237,7 @@ public class PropertyFilter<S extends Storable> extends Filter<S> { }
@Override
- <T extends Storable> PropertyFilter<T> asJoinedFromAny(ChainedProperty<T> joinProperty) {
+ public <T extends Storable> PropertyFilter<T> asJoinedFromAny(ChainedProperty<T> joinProperty){
ChainedProperty<T> newProperty = joinProperty.append(getChainedProperty());
if (isConstant()) {
@@ -406,7 +406,7 @@ public class PropertyFilter<S extends Storable> extends Filter<S> { }
@Override
- public int hashCode() {
+ int generateHashCode() {
return mProperty.hashCode() * 31 + mOp.hashCode() + mBindID;
}
diff --git a/src/main/java/com/amazon/carbonado/repo/jdbc/WhereBuilder.java b/src/main/java/com/amazon/carbonado/repo/jdbc/WhereBuilder.java index 80f895e..9023397 100644 --- a/src/main/java/com/amazon/carbonado/repo/jdbc/WhereBuilder.java +++ b/src/main/java/com/amazon/carbonado/repo/jdbc/WhereBuilder.java @@ -208,13 +208,24 @@ class WhereBuilder<S extends Storable> extends Visitor<S, FetchException, Object if (subFilter != null && !subFilter.isOpen()) {
mStatementBuilder.append(" AND (");
+
WhereBuilder wb = new WhereBuilder
(mStatementBuilder, oneToManyNode, mAliasGenerator);
+
FetchException e = (FetchException) subFilter.accept(wb, null);
if (e != null) {
return e;
}
+
mStatementBuilder.append(')');
+
+ // Transfer property filters from sub-builder as joined from exists filter.
+ int size = wb.mPropertyFilters.size();
+ for (int i=0; i<size; i++) {
+ PropertyFilter propFilter = (PropertyFilter) wb.mPropertyFilters.get(i);
+ mPropertyFilters.add(propFilter.asJoinedFromAny(chained));
+ }
+ mPropertyFilterNullable.addAll(wb.mPropertyFilterNullable);
}
mStatementBuilder.append(')');
|