Search in sources :

Example 31 with Reference

use of com.google.storage.onestore.v3.OnestoreEntity.Reference in project appengine-java-standard by GoogleCloudPlatform.

the class KeyTranslatorTest method testConvertToPbTwoLevelsPut.

@Test
public void testConvertToPbTwoLevelsPut() throws Exception {
    Key key1 = new Key("foo");
    key1.simulatePutForTesting(12345L);
    Key key2 = new Key("bar", key1);
    key2.simulatePutForTesting(12346L);
    assertThat(key2.isComplete()).isTrue();
    assertThat(key2.getId()).isEqualTo(12346L);
    Reference ref2 = KeyTranslator.convertToPb(key2);
    assertThat(ref2.getPath().elementSize()).isEqualTo(2);
    assertThat(ref2.getPath().elements().get(0).getType()).isEqualTo("foo");
    assertThat(ref2.getPath().elements().get(0).hasId()).isTrue();
    assertThat(ref2.getPath().elements().get(0).getId()).isEqualTo(12345L);
    assertThat(ref2.getPath().elements().get(0).hasName()).isFalse();
    assertThat(ref2.getPath().elements().get(1).getType()).isEqualTo("bar");
    assertThat(ref2.getPath().elements().get(1).hasId()).isTrue();
    assertThat(ref2.getPath().elements().get(1).getId()).isEqualTo(12346L);
    assertThat(ref2.getPath().elements().get(1).hasName()).isFalse();
}
Also used : Reference(com.google.storage.onestore.v3.OnestoreEntity.Reference) Test(org.junit.Test)

Example 32 with Reference

use of com.google.storage.onestore.v3.OnestoreEntity.Reference in project appengine-java-standard by GoogleCloudPlatform.

the class KeyTranslatorTest method testConvertToPbTwoLevelsNotPut.

@Test
public void testConvertToPbTwoLevelsNotPut() throws Exception {
    Key key1 = new Key("foo");
    key1.simulatePutForTesting(12345L);
    Key key2 = new Key("bar", key1);
    assertThat(key2.isComplete()).isFalse();
    Reference ref2 = KeyTranslator.convertToPb(key2);
    assertThat(ref2.getPath().elementSize()).isEqualTo(2);
    assertThat(ref2.getPath().elements().get(0).getType()).isEqualTo("foo");
    assertThat(ref2.getPath().elements().get(0).hasId()).isTrue();
    assertThat(ref2.getPath().elements().get(0).getId()).isEqualTo(12345L);
    assertThat(ref2.getPath().elements().get(0).hasName()).isFalse();
    assertThat(ref2.getPath().elements().get(1).getType()).isEqualTo("bar");
    assertThat(ref2.getPath().elements().get(1).hasId()).isFalse();
    assertThat(ref2.getPath().elements().get(1).hasName()).isFalse();
}
Also used : Reference(com.google.storage.onestore.v3.OnestoreEntity.Reference) Test(org.junit.Test)

Example 33 with Reference

use of com.google.storage.onestore.v3.OnestoreEntity.Reference in project appengine-java-standard by GoogleCloudPlatform.

the class ReferenceValues method toReferenceProperty.

/**
 * Converts a {@link Reference} to a {@link PropertyValue}
 *
 * <p>with the same {@link PropertyValue.ReferenceValue}.
 *
 * <p>Doesn't do any validation!
 *
 * @return the corresponding {@link PropertyValue}
 */
public static PropertyValue toReferenceProperty(Reference key) {
    PropertyValue prop = new PropertyValue();
    PropertyValue.ReferenceValue ref = prop.getMutableReferenceValue();
    if (key.hasApp()) {
        ref.setAppAsBytes(key.getAppAsBytes());
    }
    if (key.hasDatabaseId()) {
        ref.setDatabaseIdAsBytes(key.getDatabaseIdAsBytes());
    }
    if (key.hasNameSpace()) {
        ref.setNameSpaceAsBytes(key.getNameSpaceAsBytes());
    }
    for (Path.Element keyElem : key.getPath().elements()) {
        PropertyValue.ReferenceValuePathElement refElem = ref.addPathElement();
        if (keyElem.hasType()) {
            refElem.setTypeAsBytes(keyElem.getTypeAsBytes());
        }
        if (keyElem.hasId()) {
            refElem.setId(keyElem.getId());
        }
        if (keyElem.hasName()) {
            refElem.setNameAsBytes(keyElem.getNameAsBytes());
        }
    }
    return prop;
}
Also used : Path(com.google.storage.onestore.v3.OnestoreEntity.Path) PropertyValue(com.google.storage.onestore.v3.OnestoreEntity.PropertyValue)

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