use of com.google.storage.onestore.v3.OnestoreEntity.Reference in project appengine-java-standard by GoogleCloudPlatform.
the class LocalDatastoreService method get.
public GetResponse get(@SuppressWarnings("unused") Status status, GetRequest request) {
GetResponse response = new GetResponse();
LiveTxn liveTxn = null;
for (Reference key : request.keys()) {
validatePathComplete(key);
String app = key.getApp();
Path groupPath = getGroup(key);
GetResponse.Entity responseEntity = response.addEntity();
Profile profile = getOrCreateProfile(app);
synchronized (profile) {
Profile.EntityGroup eg = profile.getGroup(groupPath);
if (request.hasTransaction()) {
if (liveTxn == null) {
liveTxn = profile.getTxn(request.getTransaction().getHandle());
}
// this will throw an exception if we attempt to read from
// the wrong entity group
eg.addTransaction(liveTxn);
}
boolean eventualConsistency = request.hasFailoverMs() && liveTxn == null;
EntityProto entity = pseudoKinds.get(liveTxn, eg, key, eventualConsistency);
if (entity == PseudoKinds.NOT_A_PSEUDO_KIND) {
VersionedEntity versionedEntity = eg.get(liveTxn, key, eventualConsistency);
if (versionedEntity == null) {
entity = null;
if (!eventualConsistency) {
responseEntity.setVersion(profile.getReadTimestamp());
}
} else {
entity = versionedEntity.entityProto();
responseEntity.setVersion(versionedEntity.version());
}
}
if (entity != null) {
responseEntity.getMutableEntity().copyFrom(entity);
postprocessEntity(responseEntity.getMutableEntity());
} else {
responseEntity.getMutableKey().copyFrom(key);
}
// Give all entity groups with unapplied jobs the opportunity to catch
// up. Note that this will not impact the result we're about to return.
profile.groom();
}
}
return response;
}
use of com.google.storage.onestore.v3.OnestoreEntity.Reference in project appengine-java-standard by GoogleCloudPlatform.
the class KindPseudoKind method makeKindEntity.
/**
* Creates a __kind__ entity
*/
private static EntityProto makeKindEntity(String kind, String app, String namespace) {
EntityProto kindEntity = new EntityProto();
Path path = new Path();
path.addElement().setType(KIND_METADATA_KIND).setName(kind);
Reference key = new Reference().setApp(app).setPath(path);
if (namespace.length() > 0) {
key.setNameSpace(namespace);
}
kindEntity.setKey(key);
// EntityProto.entity_group is a required PB field.
kindEntity.getMutableEntityGroup().addElement(path.getElement(0));
return kindEntity;
}
use of com.google.storage.onestore.v3.OnestoreEntity.Reference in project appengine-java-standard by GoogleCloudPlatform.
the class KeyTranslatorTest method testConvertToPbOneLevelNotPut.
@Test
public void testConvertToPbOneLevelNotPut() throws Exception {
Key key1 = new Key("foo");
assertThat(key1.isComplete()).isFalse();
Reference ref1 = KeyTranslator.convertToPb(key1);
assertThat(ref1.getPath().elementSize()).isEqualTo(1);
assertThat(ref1.getPath().elements().get(0).getType()).isEqualTo("foo");
assertThat(ref1.getPath().elements().get(0).hasId()).isFalse();
assertThat(ref1.getPath().elements().get(0).hasName()).isFalse();
}
use of com.google.storage.onestore.v3.OnestoreEntity.Reference in project appengine-java-standard by GoogleCloudPlatform.
the class KeyTranslatorTest method testUpdateKey_Name.
@Test
public void testUpdateKey_Name() {
Key key = new Key("yam", "harold");
AppIdNamespace appIdNamespace = key.getAppIdNamespace();
Reference ref = new Reference();
ref.setApp("my app");
Path path = new Path();
ref.setPath(path);
KeyTranslator.updateKey(ref, key);
assertThat(key.getAppIdNamespace()).isEqualTo(appIdNamespace);
assertThat(key.getId()).isEqualTo(Key.NOT_ASSIGNED);
assertThat(key.getName()).isEqualTo("harold");
}
use of com.google.storage.onestore.v3.OnestoreEntity.Reference in project appengine-java-standard by GoogleCloudPlatform.
the class KeyTranslatorTest method testConvertToPbOneLevelPut.
@Test
public void testConvertToPbOneLevelPut() throws Exception {
Key key1 = new Key("foo");
key1.simulatePutForTesting(12345L);
assertThat(key1.isComplete()).isTrue();
assertThat(key1.getId()).isEqualTo(12345L);
Reference ref1 = KeyTranslator.convertToPb(key1);
assertThat(ref1.getPath().elementSize()).isEqualTo(1);
assertThat(ref1.getPath().elements().get(0).getType()).isEqualTo("foo");
assertThat(ref1.getPath().elements().get(0).hasId()).isTrue();
assertThat(ref1.getPath().elements().get(0).getId()).isEqualTo(12345L);
assertThat(ref1.getPath().elements().get(0).hasName()).isFalse();
}
Aggregations