use of com.google.appengine.api.datastore.dev.LocalDatastoreService.Extent 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.appengine.api.datastore.dev.LocalDatastoreService.Extent 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;
}
use of com.google.appengine.api.datastore.dev.LocalDatastoreService.Extent in project appengine-java-standard by GoogleCloudPlatform.
the class KindPseudoKind method runQuery.
// Based on LocalDatastoreService.getSchema (now removed)
@Override
List<EntityProto> runQuery(Query query, Key startKey, boolean startInclusive, Key endKey, boolean endInclusive) {
/* Ancestor has no meaning in schema queries. This also has the desirable side effect that
* schema queries cannot live in transactions. */
checkRequest(!query.hasAncestor(), "ancestor queries on " + KIND_METADATA_KIND + " not allowed");
String app = query.getApp();
String namespace = query.getNameSpace();
String startKind = kindKeyToString(startKey);
String endKind = kindKeyToString(endKey);
Profile profile = getDatastore().getOrCreateProfile(app);
Map<String, Extent> extents = profile.getExtents();
List<EntityProto> kinds = Lists.newArrayList();
synchronized (extents) {
// We create one EntityProto per kind with a key containing the kind name
for (Map.Entry<String, Extent> entry : extents.entrySet()) {
String kind = entry.getKey();
// Apply filters.
if (startKind != null) {
int kindsCompared = kind.compareTo(startKind);
if ((startInclusive && kindsCompared < 0) || (!startInclusive && kindsCompared <= 0)) {
continue;
}
}
if (endKind != null) {
int kindsCompared = kind.compareTo(endKind);
if ((endInclusive && kindsCompared > 0) || (!endInclusive && kindsCompared >= 0)) {
continue;
}
}
if (entry.getValue().getAllEntityProtos().isEmpty()) {
// no entities of this kind
continue;
}
// Add an entry only if entities exist in the requested namespace.
if (isKindPresentInNamespace(entry.getValue(), namespace)) {
kinds.add(makeKindEntity(kind, app, namespace));
}
}
}
return kinds;
}
Aggregations