Search in sources :

Example 6 with Reference

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

the class EntityGroupPseudoKind method get.

@Override
@Nullable
public EntityProto get(@Nullable LiveTxn txn, EntityGroup eg, Reference key, boolean eventualConsistency) {
    // We plan to add support to query the set of entity groups by querying this pseudo-kind.  Such
    // queries would return pseudo-entities as direct children of the entity-group root with
    // numeric key ID. Thus to make sure we can get() and queries are consistent, we require that
    // key match that format.
    Path path = key.getPath();
    if (path.elementSize() != 2 || path.getElement(1).getId() != ENTITY_GROUP_METADATA_ID) {
        return null;
    }
    long version;
    if (txn == null) {
        // Can just grab the entity-group version as its incremented eagerly rather than on job-apply.
        version = eg.getVersion();
    } else {
        version = txn.trackEntityGroup(eg).getEntityGroupVersion();
    }
    // return a version even when the entity group is empty(new or not).
    return makeEntityGroupEntity(key, version + baseVersion);
}
Also used : Path(com.google.storage.onestore.v3.OnestoreEntity.Path) Nullable(org.checkerframework.checker.nullness.qual.Nullable)

Example 7 with Reference

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

the class EntityGroupPseudoKind method makeEntityGroupEntity.

/**
 * Creates an __entity_group__ entity
 */
private static EntityProto makeEntityGroupEntity(Reference key, long version) {
    EntityProto egEntity = new EntityProto().setKey(key);
    // EntityProto.entity_group is a required PB field.
    egEntity.getMutableEntityGroup().addElement(key.getPath().getElement(0));
    PropertyValue value = new PropertyValue().setInt64Value(version);
    egEntity.addProperty().setMultiple(false).setName(VERSION_RESERVED_PROPERTY).setValue(value);
    return egEntity;
}
Also used : PropertyValue(com.google.storage.onestore.v3.OnestoreEntity.PropertyValue) EntityProto(com.google.storage.onestore.v3.OnestoreEntity.EntityProto)

Example 8 with Reference

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

the class NamespacePseudoKind method makeNamespaceEntities.

private List<EntityProto> makeNamespaceEntities(Set<String> namespaceSet, String app, String executionNamespace) {
    List<EntityProto> namespaces = Lists.newArrayListWithCapacity(namespaceSet.size());
    for (String namespace : namespaceSet) {
        // Create namespace entity and set its key based on the namespace
        EntityProto namespaceEntity = new EntityProto();
        namespaces.add(namespaceEntity);
        Path path = new Path();
        // Empty namespaces use an EMPTY_NAMESPACE_ID key
        if (namespace.isEmpty()) {
            path.addElement().setType(NAMESPACE_METADATA_KIND).setId(EMPTY_NAMESPACE_ID);
        } else {
            path.addElement().setType(NAMESPACE_METADATA_KIND).setName(namespace);
        }
        Reference key = new Reference().setApp(app).setPath(path);
        if (executionNamespace.length() > 0) {
            key.setNameSpace(executionNamespace);
        }
        namespaceEntity.setKey(key);
        // EntityProto.entity_group is a required PB field.
        namespaceEntity.getMutableEntityGroup().addElement(path.getElement(0));
    }
    return namespaces;
}
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 9 with Reference

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

the class PropertyPseudoKind method addPropertyEntitiesToSchema.

/**
 * Build __property__ entities from results of scanning entities, and add them to the schema
 */
private static void addPropertyEntitiesToSchema(List<EntityProto> schema, String kind, SortedSetMultimap<String, String> allProps, String app, String namespace, boolean keysOnly) {
    // {@link SortedSet}s so the results will be ordered.
    for (String prop : allProps.keySet()) {
        // Create schema entity and set its key based on the kind
        EntityProto propEntity = new EntityProto();
        schema.add(propEntity);
        Path path = new Path();
        path.addElement().setType(KIND_METADATA_KIND).setName(kind);
        path.addElement().setType(PROPERTY_METADATA_KIND).setName(prop);
        Reference key = new Reference().setApp(app).setPath(path);
        if (namespace.length() > 0) {
            key.setNameSpace(namespace);
        }
        propEntity.setKey(key);
        // EntityProto.entity_group is a required PB field.
        propEntity.getMutableEntityGroup().addElement(path.getElement(0));
        if (!keysOnly) {
            for (String rep : allProps.get(prop)) {
                PropertyValue repValue = new PropertyValue().setStringValue(rep);
                propEntity.addProperty().setName("property_representation").setValue(repValue).setMultiple(true);
            }
        }
    }
}
Also used : Path(com.google.storage.onestore.v3.OnestoreEntity.Path) Reference(com.google.storage.onestore.v3.OnestoreEntity.Reference) PropertyValue(com.google.storage.onestore.v3.OnestoreEntity.PropertyValue) EntityProto(com.google.storage.onestore.v3.OnestoreEntity.EntityProto)

Example 10 with Reference

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

the class CursorTest method testReverseCursorPostfix.

@SuppressWarnings("deprecation")
@Test
public void testReverseCursorPostfix() {
    IndexPostfix postfixPosition = new IndexPostfix().setKey(new Reference()).setBefore(true);
    Cursor pfCursor = toCursor(new CompiledCursor().setPostfixPosition(postfixPosition));
    // reverse() is a no-op.
    Cursor pfReverse = pfCursor.reverse();
    assertThat(pfReverse).isEqualTo(pfCursor);
    assertThat(pfCursor).isEqualTo(pfReverse.reverse());
}
Also used : IndexPostfix(com.google.storage.onestore.v3.OnestoreEntity.IndexPostfix) Reference(com.google.storage.onestore.v3.OnestoreEntity.Reference) CompiledCursor(com.google.apphosting.datastore.DatastoreV3Pb.CompiledCursor) CompiledCursor(com.google.apphosting.datastore.DatastoreV3Pb.CompiledCursor) 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