From f9780b8b92778f5bd43cf1d21d83c1999060df56 Mon Sep 17 00:00:00 2001 From: "Brian S. O'Neill" Date: Tue, 10 Feb 2009 19:54:31 +0000 Subject: Fix for JDBC prepared statement values when query has an exists filter. --- src/main/java/com/amazon/carbonado/filter/AndFilter.java | 4 ++-- .../java/com/amazon/carbonado/filter/ClosedFilter.java | 4 ++-- .../java/com/amazon/carbonado/filter/ExistsFilter.java | 4 ++-- src/main/java/com/amazon/carbonado/filter/Filter.java | 15 +++++++++++++-- src/main/java/com/amazon/carbonado/filter/OpenFilter.java | 4 ++-- src/main/java/com/amazon/carbonado/filter/OrFilter.java | 4 ++-- .../java/com/amazon/carbonado/filter/PropertyFilter.java | 4 ++-- .../java/com/amazon/carbonado/repo/jdbc/WhereBuilder.java | 11 +++++++++++ 8 files changed, 36 insertions(+), 14 deletions(-) (limited to 'src') 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 extends BinaryOpFilter { } @Override - Filter asJoinedFromAny(ChainedProperty joinProperty) { + public Filter asJoinedFromAny(ChainedProperty joinProperty) { return mLeft.asJoinedFromAny(joinProperty).and(mRight.asJoinedFromAny(joinProperty)); } @@ -117,7 +117,7 @@ public class AndFilter extends BinaryOpFilter { } @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 extends Filter { } @Override - ClosedFilter asJoinedFromAny(ChainedProperty joinProperty) { + public ClosedFilter asJoinedFromAny(ChainedProperty joinProperty) { return getClosedFilter(joinProperty.getPrimeProperty().getEnclosingType()); } @@ -155,7 +155,7 @@ public class ClosedFilter extends Filter { } @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 extends Filter { } @Override - ExistsFilter asJoinedFromAny(ChainedProperty joinProperty) { + public ExistsFilter asJoinedFromAny(ChainedProperty joinProperty) { ChainedProperty newProperty = joinProperty.append(getChainedProperty()); return getCanonical(newProperty, mSubFilter, mNot); } @@ -255,7 +255,7 @@ public class ExistsFilter extends Filter { } @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 implements Serializable, Append private final Class mType; + private transient int mHashCode; + // Root FilterValues, built on demand, which is immutable. private transient volatile FilterValues mFilterValues; @@ -643,7 +645,8 @@ public abstract class Filter implements Serializable, Append /** * Allows join from any property type, including one-to-many joins. */ - abstract Filter asJoinedFromAny(ChainedProperty joinProperty); + public abstract Filter + asJoinedFromAny(ChainedProperty joinProperty); /** * Removes a join property prefix from all applicable properties of this @@ -766,7 +769,15 @@ public abstract class Filter 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 extends Filter { } @Override - OpenFilter asJoinedFromAny(ChainedProperty joinProperty) { + public OpenFilter asJoinedFromAny(ChainedProperty joinProperty) { return getOpenFilter(joinProperty.getPrimeProperty().getEnclosingType()); } @@ -155,7 +155,7 @@ public class OpenFilter extends Filter { } @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 extends BinaryOpFilter { } @Override - Filter asJoinedFromAny(ChainedProperty joinProperty) { + public Filter asJoinedFromAny(ChainedProperty joinProperty) { return mLeft.asJoinedFromAny(joinProperty).or(mRight.asJoinedFromAny(joinProperty)); } @@ -132,7 +132,7 @@ public class OrFilter extends BinaryOpFilter { } @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 extends Filter { } @Override - PropertyFilter asJoinedFromAny(ChainedProperty joinProperty) { + public PropertyFilter asJoinedFromAny(ChainedProperty joinProperty){ ChainedProperty newProperty = joinProperty.append(getChainedProperty()); if (isConstant()) { @@ -406,7 +406,7 @@ public class PropertyFilter extends Filter { } @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 extends Visitor