Skip to content

Commit

Permalink
Clean up test code and javadoc formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
Ajay Kannan committed Mar 1, 2016
1 parent c95e5e7 commit 76e3b3e
Show file tree
Hide file tree
Showing 6 changed files with 190 additions and 330 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -114,28 +114,27 @@ interface TransactionCallable<T> {
Entity get(Key key, ReadOption... options);

/**
* Returns an {@link Entity} for each given {@link Key} that exists in the Datastore.
* The order of the result is unspecified.
* Results are loaded lazily, so it is possible to get a {@code DatastoreException}
* from the returned {@code Iterator}'s {@link Iterator#hasNext hasNext} or
* {@link Iterator#next next} methods. {@link ReadOption}s can be specified if desired.
* Returns an {@link Entity} for each given {@link Key} that exists in the Datastore. The order of
* the result is unspecified. Results are loaded lazily, so it is possible to get a
* {@code DatastoreException} from the returned {@code Iterator}'s
* {@link Iterator#hasNext hasNext} or {@link Iterator#next next} methods. {@link ReadOption}s can
* be specified if desired.
*
* @throws DatastoreException upon failure
* @see #get(Key)
*/
Iterator<Entity> get(Iterable<Key> keys, ReadOption... options);

/**
* Returns a list with a value for each given key (ordered by input).
* {@code null} values are returned for nonexistent keys.
* When possible prefer using {@link #get(Key...)} to avoid eagerly loading the results.
* {@link ReadOption}s can be specified if desired.
* Returns a list with a value for each given key (ordered by input). {@code null} values are
* returned for nonexistent keys. When possible prefer using {@link #get(Key...)} to avoid eagerly
* loading the results. {@link ReadOption}s can be specified if desired.
*/
List<Entity> fetch(Iterable<Key> keys, ReadOption... options);

/**
* Submits a {@link Query} and returns its result.
* {@link ReadOption}s can be specified if desired.
* Submits a {@link Query} and returns its result. {@link ReadOption}s can be specified if
* desired.
*
* @throws DatastoreException upon failure
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,22 +56,19 @@ static KeyFactory newKeyFactory(DatastoreOptions options) {
}

/**
* Returns a list with a value for each given key (ordered by input).
* {@code null} values are returned for nonexistent keys.
* Returns a list with a value for each given key (ordered by input). {@code null} values are
* returned for nonexistent keys.
*/
static List<Entity> fetch(Transaction reader, Key... keys) {
Iterator<Entity> entities = reader.get(keys);
return compileEntities(keys, entities);
return compileEntities(keys, reader.get(keys));
}

/**
* Returns a list with a value for each given key (ordered by input).
* {@code null} values are returned for nonexistent keys.
* Returns a list with a value for each given key (ordered by input). {@code null} values are
* returned for nonexistent keys.
*/
static List<Entity> fetch(Datastore reader, Key[] keys, ReadOption... options) {
Iterator<Entity> entities;
entities = reader.get(Arrays.asList(keys), options);
return compileEntities(keys, entities);
return compileEntities(keys, reader.get(Arrays.asList(keys), options));
}

private static List<Entity> compileEntities(Key[] keys, Iterator<Entity> entities) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -210,16 +210,11 @@ public Iterator<Entity> get(Iterable<Key> keys, ReadOption... options) {

private static com.google.datastore.v1beta3.ReadOptions toReadOptionsPb(ReadOption... options) {
com.google.datastore.v1beta3.ReadOptions readOptionsPb = null;
if (options != null) {
Map<Class<? extends ReadOption>, ReadOption> optionsMap = ReadOption.asImmutableMap(options);
EventualConsistency eventualConsistency =
(EventualConsistency) optionsMap.get(EventualConsistency.class);
if (eventualConsistency != null) {
readOptionsPb =
com.google.datastore.v1beta3.ReadOptions.newBuilder()
.setReadConsistency(ReadConsistency.EVENTUAL)
.build();
}
if (options != null
&& ReadOption.asImmutableMap(options).containsKey(EventualConsistency.class)) {
readOptionsPb = com.google.datastore.v1beta3.ReadOptions.newBuilder()
.setReadConsistency(ReadConsistency.EVENTUAL)
.build();
}
return readOptionsPb;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,21 +32,20 @@ public interface DatastoreReader {
Entity get(Key key);

/**
* Returns an {@link Entity} for each given {@link Key} that exists in the Datastore.
* The order of the result is unspecified.
* Results are loaded lazily, so it is possible to get a {@code DatastoreException}
* from the returned {@code Iterator}'s {@link Iterator#hasNext hasNext} or
* {@link Iterator#next next} methods.
* Returns an {@link Entity} for each given {@link Key} that exists in the Datastore. The order of
* the result is unspecified. Results are loaded lazily, so it is possible to get a
* {@code DatastoreException} from the returned {@code Iterator}'s
* {@link Iterator#hasNext hasNext} or {@link Iterator#next next} methods.
*
* @throws DatastoreException upon failure
* @see #get(Key)
*/
Iterator<Entity> get(Key... key);

/**
* Returns a list with a value for each given key (ordered by input).
* {@code null} values are returned for nonexistent keys.
* When possible prefer using {@link #get(Key...)} to avoid eagerly loading the results.
* Returns a list with a value for each given key (ordered by input). {@code null} values are
* returned for nonexistent keys. When possible prefer using {@link #get(Key...)} to avoid eagerly
* loading the results.
*/
List<Entity> fetch(Key... keys);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public boolean isEventual() {
}
}

ReadOption() {}
private ReadOption() {}

/**
* Returns a {@code ReadOption} that specifies eventual consistency.
Expand Down
Loading

0 comments on commit 76e3b3e

Please sign in to comment.