diff options
Diffstat (limited to 'src')
4 files changed, 56 insertions, 77 deletions
| diff --git a/src/main/java/com/amazon/carbonado/Query.java b/src/main/java/com/amazon/carbonado/Query.java index d1cebca..36a8117 100644 --- a/src/main/java/com/amazon/carbonado/Query.java +++ b/src/main/java/com/amazon/carbonado/Query.java @@ -255,6 +255,25 @@ public interface Query<S extends Storable> {      Query<S> orderBy(String... properties) throws FetchException;
      /**
 +     * Returns a query which fetches results for this query after a given
 +     * starting point, which is useful for re-opening a cursor. This is only
 +     * effective when query has been given an explicit {@link #orderBy
 +     * ordering}. If not a total ordering, then query may start at an earlier
 +     * position.
 +     *
 +     * <p>Note: The returned query can be very expensive to fetch from
 +     * repeatedly, if the query needs to perform a sort operation. Ideally, the
 +     * query ordering should match the natural ordering of an index or key.
 +     *
 +     * @param start storable to attempt to start after; if null, this query is
 +     * returned
 +     * @throws IllegalStateException if any blank parameters in this query
 +     * @throws FetchException if storage layer throws an exception
 +     * @since 1.2
 +     */
 +    Query<S> after(S start) throws FetchException;
 +
 +    /**
       * Fetches results for this query. If any updates or deletes might be
       * performed on the results, consider enclosing the fetch in a
       * transaction. This allows the isolation level and "for update" mode to be
 @@ -288,7 +307,7 @@ public interface Query<S extends Storable> {       * Fetches results for this query after a given starting point, which is
       * useful for re-opening a cursor. This is only effective when query has
       * been given an explicit {@link #orderBy ordering}. If not a total
 -     * ordering, then returned cursor may start at an earlier position.
 +     * ordering, then cursor may start at an earlier position.
       *
       * <p>Note: This method can be very expensive to call repeatedly, if the
       * query needs to perform a sort operation. Ideally, the query ordering
 @@ -299,35 +318,11 @@ public interface Query<S extends Storable> {       * @throws IllegalStateException if any blank parameters in this query
       * @throws FetchException if storage layer throws an exception
       * @see Repository#enterTransaction(IsolationLevel)
 +     * @see #after
       */
      Cursor<S> fetchAfter(S start) throws FetchException;
      /**
 -     * Fetches a slice of results for this query after a given starting point,
 -     * which is useful for re-opening a cursor. This is only effective when
 -     * query has been given an explicit {@link #orderBy ordering}. If not a
 -     * total ordering, then returned cursor may start at an earlier position.
 -     * It is strongly recommended that the query be given a total ordering in
 -     * order for the slice results to be deterministic.
 -     *
 -     * <p>Note: This method can be very expensive to call repeatedly, if the
 -     * query needs to perform a sort operation. Ideally, the query ordering
 -     * should match the natural ordering of an index or key.
 -     *
 -     * @param start storable to attempt to start after; if null, fetch all results
 -     * @param from zero-based {@code from} record number, inclusive
 -     * @param to optional zero-based {@code to} record number, exclusive
 -     * @return fetch results
 -     * @throws IllegalStateException if any blank parameters in this query
 -     * @throws IllegalArgumentException if {@code from} is negative or if
 -     * {@code from} is more than {@code to}
 -     * @throws FetchException if storage layer throws an exception
 -     * @see Repository#enterTransaction(IsolationLevel)
 -     * @since 1.2
 -     */
 -    Cursor<S> fetchAfter(S start, long from, Long to) throws FetchException;
 -
 -    /**
       * Attempts to load exactly one matching object. If the number of matching
       * records is zero or exceeds one, then an exception is thrown instead.
       *
 diff --git a/src/main/java/com/amazon/carbonado/qe/EmptyQuery.java b/src/main/java/com/amazon/carbonado/qe/EmptyQuery.java index 9754019..83c09a6 100644 --- a/src/main/java/com/amazon/carbonado/qe/EmptyQuery.java +++ b/src/main/java/com/amazon/carbonado/qe/EmptyQuery.java @@ -205,6 +205,10 @@ public final class EmptyQuery<S extends Storable> extends AbstractQuery<S> {          return new EmptyQuery<S>(mFactory, properties);
      }
 +    public Query<S> after(S start) {
 +        return this;
 +    }
 +
      /**
       * Always returns an {@link EmptyCursor}.
       */
 @@ -228,14 +232,6 @@ public final class EmptyQuery<S extends Storable> extends AbstractQuery<S> {      }
      /**
 -     * Always returns an {@link EmptyCursor}.
 -     */
 -    public Cursor<S> fetchAfter(S start, long from, Long to) {
 -        checkSliceArguments(from, to);
 -        return EmptyCursor.the();
 -    }
 -
 -    /**
       * Always throws {@link PersistNoneException}.
       */
      public void deleteOne() throws PersistNoneException {
 diff --git a/src/main/java/com/amazon/carbonado/qe/StandardQuery.java b/src/main/java/com/amazon/carbonado/qe/StandardQuery.java index 1ee3acb..f8db1df 100644 --- a/src/main/java/com/amazon/carbonado/qe/StandardQuery.java +++ b/src/main/java/com/amazon/carbonado/qe/StandardQuery.java @@ -209,43 +209,12 @@ public abstract class StandardQuery<S extends Storable> extends AbstractQuery<S>                             OrderingList.get(getStorableType(), properties), mHints);
      }
 -    public Cursor<S> fetch() throws FetchException {
 -        try {
 -            return executor().fetch(mValues);
 -        } catch (RepositoryException e) {
 -            throw e.toFetchException();
 -        }
 -    }
 -
 -    public Cursor<S> fetch(long from, Long to) throws FetchException {
 -        if (!checkSliceArguments(from, to)) {
 -            return fetch();
 -        }
 -        try {
 -            QueryHints hints = QueryHints.emptyHints().with(QueryHint.CONSUME_SLICE);
 -            return executorFactory().executor(mFilter, mOrdering, hints).fetch(mValues, from, to);
 -        } catch (RepositoryException e) {
 -            throw e.toFetchException();
 -        }
 -    }
 -
 -    public Cursor<S> fetchAfter(S start) throws FetchException {
 +    public Query<S> after(S start) throws FetchException {
          OrderingList<S> orderings;
          if (start == null || (orderings = mOrdering).size() == 0) {
 -            return fetch();
 -        }
 -        return buildAfter(start, orderings).fetch();
 -    }
 -
 -    public Cursor<S> fetchAfter(S start, long from, Long to) throws FetchException {
 -        if (!checkSliceArguments(from, to)) {
 -            return fetchAfter(start);
 -        }
 -        OrderingList<S> orderings;
 -        if (start == null || (orderings = mOrdering).size() == 0) {
 -            return fetch(from, to);
 +            return this;
          }
 -        return buildAfter(start, orderings).fetch(from, to);
 +        return buildAfter(start, orderings);
      }
      private Query<S> buildAfter(S start, OrderingList<S> orderings) throws FetchException {
 @@ -271,6 +240,30 @@ public abstract class StandardQuery<S extends Storable> extends AbstractQuery<S>          return and(orderFilter);
      }
 +    public Cursor<S> fetch() throws FetchException {
 +        try {
 +            return executor().fetch(mValues);
 +        } catch (RepositoryException e) {
 +            throw e.toFetchException();
 +        }
 +    }
 +
 +    public Cursor<S> fetch(long from, Long to) throws FetchException {
 +        if (!checkSliceArguments(from, to)) {
 +            return fetch();
 +        }
 +        try {
 +            QueryHints hints = QueryHints.emptyHints().with(QueryHint.CONSUME_SLICE);
 +            return executorFactory().executor(mFilter, mOrdering, hints).fetch(mValues, from, to);
 +        } catch (RepositoryException e) {
 +            throw e.toFetchException();
 +        }
 +    }
 +
 +    public Cursor<S> fetchAfter(S start) throws FetchException {
 +        return after(start).fetch();
 +    }
 +
      public boolean tryDeleteOne() throws PersistException {
          Transaction txn = enterTransaction(IsolationLevel.READ_COMMITTED);
          try {
 diff --git a/src/main/java/com/amazon/carbonado/repo/logging/LoggingQuery.java b/src/main/java/com/amazon/carbonado/repo/logging/LoggingQuery.java index 56e4e33..e737288 100644 --- a/src/main/java/com/amazon/carbonado/repo/logging/LoggingQuery.java +++ b/src/main/java/com/amazon/carbonado/repo/logging/LoggingQuery.java @@ -129,6 +129,10 @@ class LoggingQuery<S extends Storable> implements Query<S> {          return newInstance(mQuery.orderBy(strings));
      }
 +    public Query<S> after(S start) throws FetchException {
 +        return newInstance(mQuery.after(start));
 +    }
 +
      public Cursor<S> fetch() throws FetchException {
          Log log = mStorage.mLog;
          if (log.isEnabled()) {
 @@ -154,15 +158,6 @@ class LoggingQuery<S extends Storable> implements Query<S> {          return mQuery.fetchAfter(start);
      }
 -    public Cursor<S> fetchAfter(S start, long from, Long to) throws FetchException {
 -        Log log = mStorage.mLog;
 -        if (log.isEnabled()) {
 -            log.write("Query.fetchAfter(start, from, to) on " + this + ", start: " + start +
 -                      ", from: " + from + ", to: " + to);
 -        }
 -        return mQuery.fetchAfter(start);
 -    }
 -
      public S loadOne() throws FetchException {
          Log log = mStorage.mLog;
          if (log.isEnabled()) {
 | 
