Search in sources :

Example 26 with Reference

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;
}
Also used : Path(com.google.storage.onestore.v3.OnestoreEntity.Path) Reference(com.google.storage.onestore.v3.OnestoreEntity.Reference) ByteString(com.google.protobuf.ByteString) GetResponse(com.google.apphosting.datastore.DatastoreV3Pb.GetResponse) EntityProto(com.google.storage.onestore.v3.OnestoreEntity.EntityProto)

Example 27 with Reference

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;
}
Also used : Path(com.google.storage.onestore.v3.OnestoreEntity.Path) Reference(com.google.storage.onestore.v3.OnestoreEntity.Reference) EntityProto(com.google.storage.onestore.v3.OnestoreEntity.EntityProto)

Example 28 with Reference

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();
}
Also used : Reference(com.google.storage.onestore.v3.OnestoreEntity.Reference) Test(org.junit.Test)

Example 29 with Reference

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");
}
Also used : Path(com.google.storage.onestore.v3.OnestoreEntity.Path) Reference(com.google.storage.onestore.v3.OnestoreEntity.Reference) Test(org.junit.Test)

Example 30 with Reference

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();
}
Also used : Reference(com.google.storage.onestore.v3.OnestoreEntity.Reference) Test(org.junit.Test)

Aggregations

Reference (com.google.storage.onestore.v3.OnestoreEntity.Reference)26 Path (com.google.storage.onestore.v3.OnestoreEntity.Path)16 Test (org.junit.Test)10 EntityProto (com.google.storage.onestore.v3.OnestoreEntity.EntityProto)9 ByteString (com.google.protobuf.ByteString)5 Element (com.google.storage.onestore.v3.OnestoreEntity.Path.Element)5 ArrayList (java.util.ArrayList)5 List (java.util.List)5 PropertyValue (com.google.storage.onestore.v3.OnestoreEntity.PropertyValue)4 Cost (com.google.apphosting.datastore.DatastoreV3Pb.Cost)3 Order (com.google.apphosting.datastore.DatastoreV3Pb.Query.Order)3 ImmutableList (com.google.common.collect.ImmutableList)3 LinkedHashMap (java.util.LinkedHashMap)3 LinkedList (java.util.LinkedList)3 Map (java.util.Map)3 AtomicLong (java.util.concurrent.atomic.AtomicLong)3 ReorderingMultiFuture (com.google.appengine.api.datastore.Batcher.ReorderingMultiFuture)2 MultiFuture (com.google.appengine.api.datastore.FutureHelper.MultiFuture)2 Utils.getLastElement (com.google.appengine.api.datastore.dev.Utils.getLastElement)2 GetResponse (com.google.apphosting.datastore.DatastoreV3Pb.GetResponse)2