diff options
Diffstat (limited to 'src/main/java/com/amazon/carbonado/qe')
-rw-r--r-- | src/main/java/com/amazon/carbonado/qe/EmptyQuery.java | 7 | ||||
-rw-r--r-- | src/main/java/com/amazon/carbonado/qe/StandardQuery.java | 9 |
2 files changed, 16 insertions, 0 deletions
diff --git a/src/main/java/com/amazon/carbonado/qe/EmptyQuery.java b/src/main/java/com/amazon/carbonado/qe/EmptyQuery.java index 31d9dd3..1a970e0 100644 --- a/src/main/java/com/amazon/carbonado/qe/EmptyQuery.java +++ b/src/main/java/com/amazon/carbonado/qe/EmptyQuery.java @@ -107,6 +107,13 @@ public final class EmptyQuery<S extends Storable> extends AbstractQuery<S> { }
/**
+ * Always returns false.
+ */
+ public boolean exists() {
+ return false;
+ }
+
+ /**
* Always throws an IllegalStateException.
*/
public Query<S> with(int value) {
diff --git a/src/main/java/com/amazon/carbonado/qe/StandardQuery.java b/src/main/java/com/amazon/carbonado/qe/StandardQuery.java index ec9bf4e..2d7995e 100644 --- a/src/main/java/com/amazon/carbonado/qe/StandardQuery.java +++ b/src/main/java/com/amazon/carbonado/qe/StandardQuery.java @@ -294,6 +294,15 @@ public abstract class StandardQuery<S extends Storable> extends AbstractQuery<S> }
}
+ public boolean exists() throws FetchException {
+ Cursor<S> cursor = fetch();
+ try {
+ return cursor.skipNext(1) > 0;
+ } finally {
+ cursor.close();
+ }
+ }
+
public boolean printNative(Appendable app, int indentLevel) throws IOException {
try {
return executor().printNative(app, indentLevel, mValues);
|