use of com.google.storage.onestore.v3.OnestoreEntity.EntityProto 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.EntityProto 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.EntityProto in project appengine-java-standard by GoogleCloudPlatform.
the class NamespacePseudoKind method runQuery.
@Override
List<EntityProto> runQuery(Query query, Key startKey, boolean startInclusive, Key endKey, boolean endInclusive) {
/* Ancestor has no meaning in namespace queries. This also has the desirable side effect that
* schema queries cannot live in transactions. */
checkRequest(!query.hasAncestor(), "ancestor queries on " + NAMESPACE_METADATA_KIND + " not allowed");
String app = query.getApp();
String startNamespace = namespaceKeyToString(startKey);
String endNamespace = namespaceKeyToString(endKey);
Profile profile = getDatastore().getOrCreateProfile(app);
Map<String, Extent> extents = profile.getExtents();
Set<String> namespaceSet = new HashSet<String>();
synchronized (extents) {
// Just collect all namespaces that are in the selected range
for (Map.Entry<String, Extent> entry : extents.entrySet()) {
for (EntityProto entity : entry.getValue().getAllEntityProtos()) {
String namespace = entity.getKey().getNameSpace();
// Apply filters.
if (startNamespace != null) {
int namespacesCompared = namespace.compareTo(startNamespace);
if ((startInclusive && namespacesCompared < 0) || (!startInclusive && namespacesCompared <= 0)) {
continue;
}
}
if (endNamespace != null) {
int namespacesCompared = namespace.compareTo(endNamespace);
if ((endInclusive && namespacesCompared > 0) || (!endInclusive && namespacesCompared >= 0)) {
continue;
}
}
namespaceSet.add(namespace);
}
}
}
return makeNamespaceEntities(namespaceSet, app, query.getNameSpace());
}
use of com.google.storage.onestore.v3.OnestoreEntity.EntityProto 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.EntityProto in project appengine-java-standard by GoogleCloudPlatform.
the class PropertyPseudoKind method getProperties.
/**
* Get the results of a __property__ query over the specified range.
*/
private List<EntityProto> getProperties(String app, String namespace, boolean keysOnly, KindProperty start, boolean startInclusive, KindProperty end, boolean endInclusive) {
Profile profile = getDatastore().getOrCreateProfile(app);
Map<String, Extent> extents = profile.getExtents();
List<EntityProto> schema = Lists.newArrayList();
synchronized (extents) {
// that kind.
for (Map.Entry<String, Extent> entry : extents.entrySet()) {
String kind = entry.getKey();
boolean startKindEqual = false;
boolean endKindEqual = false;
// Apply kind filter (inclusive is only meaningful at the property level).
if (start.kind != null) {
int kindsCompared = kind.compareTo(start.kind);
startKindEqual = kindsCompared == 0;
if (kindsCompared < 0) {
continue;
}
}
if (end.kind != null) {
int kindsCompared = kind.compareTo(end.kind);
endKindEqual = kindsCompared == 0;
if (kindsCompared > 0) {
continue;
}
}
List<EntityProto> entities = getEntitiesForNamespace(entry.getValue(), namespace);
// Skip kinds with no entities in the specified namespace
if (entities.isEmpty()) {
continue;
}
// Collect and add the indexed properties. (schema queries don't
// report unindexed properties; details in http://b/1004244)
SortedSetMultimap<String, String> allProps = TreeMultimap.create();
for (EntityProto entity : entities) {
for (Property prop : entity.propertys()) {
String name = prop.getName();
PropertyType type = PropertyType.getType(prop.getValue());
// Apply start property filter if kind equal to start.kind
if (startKindEqual) {
int propertysCompared = name.compareTo(start.property);
if ((startInclusive && propertysCompared < 0) || (!startInclusive && propertysCompared <= 0)) {
continue;
}
}
// Apply end property filter if kind equal to end.kind
if (endKindEqual) {
int propertysCompared = name.compareTo(end.property);
if ((endInclusive && propertysCompared > 0) || (!endInclusive && propertysCompared >= 0)) {
continue;
}
}
// Skip invisible special properties.
if (getDatastore().getSpecialPropertyMap().containsKey(name) && !getDatastore().getSpecialPropertyMap().get(name).isVisible()) {
continue;
}
allProps.put(name, type.name());
}
}
addPropertyEntitiesToSchema(schema, kind, allProps, app, namespace, keysOnly);
}
}
return schema;
}
Aggregations