Skip to content
Permalink

Comparing changes

This is a direct comparison between two commits made in this repository or its related repositories. View the default comparison for this range or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: googleapis/google-cloud-java
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: 63fcd1df6732bd40dcdf3223d7b06d7d17839e60
Choose a base ref
..
head repository: googleapis/google-cloud-java
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: 41ca27feeb9e5c0b56159e2ab0c5ee782afd2a91
Choose a head ref
Showing with 61 additions and 256 deletions.
  1. +6 −2 gcloud-java-datastore/src/main/java/com/google/gcloud/datastore/BaseDatastoreBatchWriter.java
  2. +2 −12 gcloud-java-datastore/src/main/java/com/google/gcloud/datastore/BatchImpl.java
  3. +0 −58 gcloud-java-datastore/src/main/java/com/google/gcloud/datastore/BatchOption.java
  4. +3 −3 gcloud-java-datastore/src/main/java/com/google/gcloud/datastore/Datastore.java
  5. +2 −2 gcloud-java-datastore/src/main/java/com/google/gcloud/datastore/DatastoreHelper.java
  6. +8 −8 gcloud-java-datastore/src/main/java/com/google/gcloud/datastore/DatastoreImpl.java
  7. +4 −3 gcloud-java-datastore/src/main/java/com/google/gcloud/datastore/DatastoreOptions.java
  8. +9 −7 gcloud-java-datastore/src/main/java/com/google/gcloud/datastore/DateTime.java
  9. +3 −9 gcloud-java-datastore/src/main/java/com/google/gcloud/datastore/Query.java
  10. +2 −9 gcloud-java-datastore/src/main/java/com/google/gcloud/datastore/TransactionImpl.java
  11. +0 −114 gcloud-java-datastore/src/main/java/com/google/gcloud/datastore/TransactionOption.java
  12. +6 −15 gcloud-java-datastore/src/main/java/com/google/gcloud/spi/DefaultDatastoreRpc.java
  13. +2 −2 gcloud-java-datastore/src/test/java/com/google/gcloud/datastore/BaseDatastoreBatchWriterTest.java
  14. +1 −1 gcloud-java-datastore/src/test/java/com/google/gcloud/datastore/DatastoreOptionsTest.java
  15. +8 −9 gcloud-java-datastore/src/test/java/com/google/gcloud/datastore/DatastoreTest.java
  16. +5 −2 gcloud-java-datastore/src/test/java/com/google/gcloud/datastore/SerializationTest.java
Original file line number Diff line number Diff line change
@@ -37,7 +37,7 @@ public abstract class BaseDatastoreBatchWriter implements DatastoreBatchWriter {

private final String name;
private final Map<Key, FullEntity<Key>> toAdd = new LinkedHashMap<>();
final List<FullEntity<IncompleteKey>> toAddAutoId = new LinkedList<>();
private final List<FullEntity<IncompleteKey>> toAddAutoId = new LinkedList<>();
private final Map<Key, FullEntity<Key>> toUpdate = new LinkedHashMap<>();
private final Map<Key, FullEntity<Key>> toPut = new LinkedHashMap<>();
private final Set<Key> toDelete = new LinkedHashSet<>();
@@ -138,7 +138,7 @@ public final void put(Entity... entities) {
for (Entity entity : entities) {
Key key = entity.key();
toAdd.remove(key);
toUpdate.remove(key);
toUpdate.remove(key);
toDelete.remove(key);
toPut.put(key, entity);
}
@@ -183,6 +183,10 @@ protected Map<Key, FullEntity<Key>> toPut() {
protected Set<Key> toDelete() {
return toDelete;
}

protected int numAutoAllocatedIds() {
return toAddAutoId.size();
}

protected void deactivate() {
active = false;
Original file line number Diff line number Diff line change
@@ -16,18 +16,14 @@

package com.google.gcloud.datastore;

import com.google.gcloud.datastore.BatchOption.ForceWrites;

import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;


class BatchImpl extends BaseDatastoreBatchWriter implements Batch {

private final DatastoreImpl datastore;
private final boolean force;

static class ResponseImpl implements Batch.Response {

@@ -51,15 +47,9 @@ public List<Key> generatedKeys() {
}
}

BatchImpl(DatastoreImpl datastore, BatchOption... options) {
BatchImpl(DatastoreImpl datastore) {
super("batch");
this.datastore = datastore;
Map<Class<? extends BatchOption>, BatchOption> optionsMap = BatchOption.asImmutableMap(options);
if (optionsMap.containsKey(ForceWrites.class)) {
force = ((ForceWrites) optionsMap.get(ForceWrites.class)).force();
} else {
force = datastore.options().force();
}
}

@Override
@@ -72,7 +62,7 @@ public Batch.Response submit() {
requestPb.addAllMutations(mutationsPb);
com.google.datastore.v1beta3.CommitResponse responsePb = datastore.commit(requestPb.build());
deactivate();
return new ResponseImpl(responsePb, toAddAutoId.size());
return new ResponseImpl(responsePb, numAutoAllocatedIds());
}

@Override

This file was deleted.

Original file line number Diff line number Diff line change
@@ -30,7 +30,7 @@ public interface Datastore extends Service<DatastoreOptions>, DatastoreReaderWri
*
* @throws DatastoreException upon failure
*/
Transaction newTransaction(TransactionOption... options);
Transaction newTransaction();


/**
@@ -57,12 +57,12 @@ interface TransactionCallable<T> {
* @param options the options for the created transaction
* @throws DatastoreException upon failure
*/
<T> T runInTransaction(TransactionCallable<T> callable, TransactionOption... options);
<T> T runInTransaction(TransactionCallable<T> callable);

/**
* Returns a new Batch for processing multiple write operations in one request.
*/
Batch newBatch(BatchOption... options);
Batch newBatch();

/**
* Allocate a unique id for the given key.
Original file line number Diff line number Diff line change
@@ -70,8 +70,8 @@ static List<Entity> fetch(DatastoreReader reader, Key... keys) {
}

static <T> T runInTransaction(Datastore datastore,
Datastore.TransactionCallable<T> callable, TransactionOption... options) {
Transaction transaction = datastore.newTransaction(options);
Datastore.TransactionCallable<T> callable) {
Transaction transaction = datastore.newTransaction();
try {
T value = callable.run(transaction);
transaction.commit();
Original file line number Diff line number Diff line change
@@ -79,18 +79,18 @@ public RetryResult beforeEval(Exception exception) {
}

@Override
public Batch newBatch(BatchOption... options) {
return new BatchImpl(this, options);
public Batch newBatch() {
return new BatchImpl(this);
}

@Override
public Transaction newTransaction(TransactionOption... options) {
return new TransactionImpl(this, options);
public Transaction newTransaction() {
return new TransactionImpl(this);
}

@Override
public <T> T runInTransaction(TransactionCallable<T> callable, TransactionOption... options) {
return DatastoreHelper.runInTransaction(this, callable, options);
public <T> T runInTransaction(TransactionCallable<T> callable) {
return DatastoreHelper.runInTransaction(this, callable);
}

@Override
@@ -99,9 +99,9 @@ public <T> QueryResults<T> run(Query<T> query) {
}

<T> QueryResults<T> run(com.google.datastore.v1beta3.ReadOptions readOptionsPb, Query<T> query) {
// TODO(ajaykannan): uncomment this line when possible in datastore v1beta3 transition
// TODO(ajaykannan): fix me!
//return new QueryResultsImpl<>(this, readOptionsPb, query);
return null; // TODO(ajaykannan): remove this line when possible
return null; // TODO(ajaykannan): fix me!
}

com.google.datastore.v1beta3.RunQueryResponse runQuery(
Original file line number Diff line number Diff line change
@@ -18,6 +18,7 @@

import static com.google.gcloud.datastore.Validator.validateNamespace;

import com.google.common.base.MoreObjects;
import com.google.common.collect.ImmutableSet;
import com.google.common.collect.Iterables;
import com.google.gcloud.ServiceOptions;
@@ -148,10 +149,10 @@ private static String defaultNamespace() {
Class<?> clazz = Class.forName("com.google.appengine.api.NamespaceManager");
Method method = clazz.getMethod("get");
String namespace = (String) method.invoke(null);
return namespace == null || namespace.isEmpty() ? null : namespace;
return MoreObjects.firstNonNull(namespace, "");
} catch (Exception ignore) {
// return null (Datastore default namespace) if could not automatically determine
return null;
// return empty string (Datastore default namespace) if could not automatically determine
return "";
}
}

Original file line number Diff line number Diff line change
@@ -32,7 +32,7 @@
* @see <a href="https://cloud.google.com/datastore/docs/concepts/entities">Google Cloud Datastore
* Entities, Properties, and Keys</a>
*/
public final class DateTime extends Serializable<com.google.protobuf.Timestamp>
public final class DateTime extends Serializable<com.google.datastore.v1beta3.Value>
implements Comparable<DateTime> {

private static final long serialVersionUID = 7343324797621228378L;
@@ -96,22 +96,24 @@ public static DateTime copyFrom(Calendar calendar) {
}

@Override
protected com.google.protobuf.Timestamp toPb() {
return microsecondsToTimestampPb(timestampMicroseconds);
protected com.google.datastore.v1beta3.Value toPb() {
return com.google.datastore.v1beta3.Value.newBuilder()
.setTimestampValue(microsecondsToTimestampPb(timestampMicroseconds)).build();
}

@Override
protected Object fromPb(byte[] bytesPb) throws InvalidProtocolBufferException {
return new DateTime(timestampPbToMicroseconds(com.google.protobuf.Timestamp.parseFrom(bytesPb)));
return new DateTime(timestampPbToMicroseconds(com.google.datastore.v1beta3.Value
.parseFrom(bytesPb).getTimestampValue()));
}

protected static long timestampPbToMicroseconds(com.google.protobuf.Timestamp timestampPb) {
return timestampPb.getSeconds() * 1000000 + timestampPb.getNanos() / 1000;
return timestampPb.getSeconds() * 10^6 + timestampPb.getNanos() / 10^3;
}

protected static com.google.protobuf.Timestamp microsecondsToTimestampPb(long microseconds) {
long seconds = microseconds / 1000000;
int nanos = (int) (microseconds % 1000000) * 1000;
long seconds = microseconds / 10^6;
int nanos = (int) (microseconds % 10^6) * 10^3;
return com.google.protobuf.Timestamp.newBuilder().setSeconds(seconds).setNanos(nanos).build();
}
}
Original file line number Diff line number Diff line change
@@ -69,9 +69,7 @@ public abstract static class ResultType<V> implements java.io.Serializable {
//TODO(ajaykannan): uncomment when possible in datastore v1beta3 transition
//return Key.fromPb(entityPb.getKey());
}
// TODO(ajaykannan): uncomment when possible in datastore v1beta3 transition
//return ProjectionEntity.fromPb(entityPb);
return ProjectionEntity.fromPb((com.google.datastore.v1beta3.Entity) null); // remove this line when possible
return ProjectionEntity.fromPb(entityPb);
}
};

@@ -81,9 +79,7 @@ public abstract static class ResultType<V> implements java.io.Serializable {
private static final long serialVersionUID = 7712959777507168274L;

@Override protected Entity convert(DatastoreV1.Entity entityPb) {
// TODO(ajaykannan): uncomment when possible in datastore v1beta3 transition
//return Entity.fromPb(entityPb);
return Entity.fromPb((com.google.datastore.v1beta3.Entity) null); // remove this line when possible
return Entity.fromPb(entityPb);
}
};

@@ -106,9 +102,7 @@ public abstract static class ResultType<V> implements java.io.Serializable {
private static final long serialVersionUID = -7591409419690650246L;

@Override protected ProjectionEntity convert(DatastoreV1.Entity entityPb) {
// TODO(ajaykannan): uncomment when possible in datastore v1beta3 transition
//return ProjectionEntity.fromPb(entityPb);
return ProjectionEntity.fromPb((com.google.datastore.v1beta3.Entity) null); // remove this line when possible
return ProjectionEntity.fromPb(entityPb);
}
};

Original file line number Diff line number Diff line change
@@ -16,19 +16,16 @@

package com.google.gcloud.datastore;

import com.google.gcloud.datastore.TransactionOption.ForceWrites;
import com.google.protobuf.ByteString;

import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;

final class TransactionImpl extends BaseDatastoreBatchWriter implements Transaction {

private final DatastoreImpl datastore;
private final ByteString transaction;
private final boolean force;
private boolean rolledback;

static class ResponseImpl implements Transaction.Response {
@@ -53,15 +50,11 @@ public List<Key> generatedKeys() {
}
}

TransactionImpl(DatastoreImpl datastore, TransactionOption... options) {
TransactionImpl(DatastoreImpl datastore) {
super("transaction");
this.datastore = datastore;
com.google.datastore.v1beta3.BeginTransactionRequest.Builder requestPb =
com.google.datastore.v1beta3.BeginTransactionRequest.newBuilder();
Map<Class<? extends TransactionOption>, TransactionOption> optionsMap =
TransactionOption.asImmutableMap(options);
ForceWrites forceWrites = (ForceWrites) optionsMap.get(TransactionOption.ForceWrites.class);
force = forceWrites != null && forceWrites.force();
transaction = datastore.requestTransactionId(requestPb);
}

@@ -105,7 +98,7 @@ public Transaction.Response commit() {
requestPb.addAllMutations(mutationsPb);
com.google.datastore.v1beta3.CommitResponse responsePb = datastore.commit(requestPb.build());
deactivate();
return new ResponseImpl(responsePb, toAddAutoId.size());
return new ResponseImpl(responsePb, numAutoAllocatedIds());
}

@Override
Loading