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);
}
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;
}
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;
}
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);
}
}
}
}
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());
}
Aggregations