use of org.bimserver.database.queries.om.Include.TypeDef in project BIMserver by opensourceBIM.
the class DatabaseReadingStackFrame method processPossibleInclude.
protected void processPossibleInclude(HashMapVirtualObject object, CanInclude previousInclude, Include include) throws QueryException, BimserverDatabaseException {
if (include.hasTypes()) {
for (TypeDef filterClass : include.getTypes()) {
if (!filterClass.geteClass().isSuperTypeOf(object.eClass())) {
// TODO too many times queries are spending time here
return;
}
}
}
if (include.hasDirectFields()) {
for (EReference eReference : include.getFieldsDirect()) {
Object ref = object.get(eReference.getName());
if (ref != null) {
if (ref instanceof List) {
for (Long r : (List<Long>) ref) {
HashMapVirtualObject byOid = getByOid(r, true);
object.addDirectListReference(eReference, byOid);
processPossibleIncludes(byOid, byOid.eClass(), include);
}
} else {
HashMapVirtualObject byOid = getByOid((Long) ref, true);
object.setDirectReference(eReference, byOid);
processPossibleIncludes(byOid, byOid.eClass(), include);
}
}
}
}
if (include.hasFields()) {
for (EStructuralFeature eStructuralFeature : include.getFields()) {
// TODO do we really have to iterate through the EAtrributes as well? You should not use fields for attributes anyways, so there should be none ...
object.addUseForSerialization(eStructuralFeature);
}
}
getQueryObjectProvider().push(new QueryIncludeStackFrame(getQueryObjectProvider(), getReusable(), previousInclude, include, object, queryPart));
}
use of org.bimserver.database.queries.om.Include.TypeDef in project BIMserver by opensourceBIM.
the class JsonQueryObjectModelConverter method toJson.
public ObjectNode toJson(Query query) {
ObjectNode queryNode = OBJECT_MAPPER.createObjectNode();
Map<String, Include> defines = query.getDefines();
ObjectNode definesNode = OBJECT_MAPPER.createObjectNode();
queryNode.set("defines", definesNode);
queryNode.put("doublebuffer", query.isDoubleBuffer());
for (String key : defines.keySet()) {
Include include = defines.get(key);
definesNode.set(key, dumpInclude(include));
}
ArrayNode queryPartsNode = OBJECT_MAPPER.createArrayNode();
queryNode.set("queries", queryPartsNode);
for (QueryPart queryPart : query.getQueryParts()) {
ObjectNode queryPartNode = OBJECT_MAPPER.createObjectNode();
if (queryPart.hasTypes()) {
ArrayNode typesNode = OBJECT_MAPPER.createArrayNode();
queryPartNode.set("types", typesNode);
for (TypeDef type : queryPart.getTypes()) {
if (type.isIncludeSubTypes()) {
ObjectNode typeDefNode = OBJECT_MAPPER.createObjectNode();
typeDefNode.put("name", type.geteClass().getName());
typeDefNode.put("includeAllSubTypes", type.isIncludeSubTypes());
typesNode.add(typeDefNode);
} else {
typesNode.add(type.geteClass().getName());
}
}
}
if (queryPart.hasOids()) {
ArrayNode oidsNode = OBJECT_MAPPER.createArrayNode();
queryPartNode.set("oids", oidsNode);
for (long oid : queryPart.getOids()) {
oidsNode.add(oid);
}
}
if (queryPart.hasInBoundingBox()) {
ObjectNode inBoundingBoxNode = OBJECT_MAPPER.createObjectNode();
inBoundingBoxNode.put("x", queryPart.getInBoundingBox().getX());
inBoundingBoxNode.put("y", queryPart.getInBoundingBox().getY());
inBoundingBoxNode.put("z", queryPart.getInBoundingBox().getZ());
inBoundingBoxNode.put("width", queryPart.getInBoundingBox().getWidth());
inBoundingBoxNode.put("height", queryPart.getInBoundingBox().getHeight());
inBoundingBoxNode.put("depth", queryPart.getInBoundingBox().getDepth());
inBoundingBoxNode.put("partial", queryPart.getInBoundingBox().isPartial());
queryPartNode.set("inBoundingBox", inBoundingBoxNode);
}
if (queryPart.hasIncludes() || queryPart.hasReferences()) {
ArrayNode includesNode = OBJECT_MAPPER.createArrayNode();
queryPartNode.set("includes", includesNode);
if (queryPart.hasIncludes()) {
for (Include include : queryPart.getIncludes()) {
ObjectNode includeNode = dumpInclude(include);
includesNode.add(includeNode);
}
}
if (queryPart.hasReferences()) {
for (Reference reference : queryPart.getReferences()) {
includesNode.add(reference.getName());
}
}
}
queryPartsNode.add(queryPartNode);
}
return queryNode;
}
use of org.bimserver.database.queries.om.Include.TypeDef in project BIMserver by opensourceBIM.
the class JsonQueryObjectModelConverter method dumpInclude.
private ObjectNode dumpInclude(Include include) {
ObjectNode includeNode = OBJECT_MAPPER.createObjectNode();
ArrayNode typesNode = OBJECT_MAPPER.createArrayNode();
for (TypeDef type : include.getTypes()) {
typesNode.add(type.geteClass().getName());
}
includeNode.set("types", typesNode);
ArrayNode fieldsNode = OBJECT_MAPPER.createArrayNode();
for (EReference eReference : include.getFields()) {
fieldsNode.add(eReference.getName());
}
includeNode.set("fields", fieldsNode);
if (include.hasIncludes() || include.hasReferences()) {
ArrayNode includes = OBJECT_MAPPER.createArrayNode();
includeNode.set("includes", includes);
if (include.hasIncludes()) {
for (Include nextInclude : include.getIncludes()) {
includes.add(dumpInclude(nextInclude));
}
}
if (include.hasReferences()) {
for (Reference reference : include.getReferences()) {
includes.add(reference.getName());
}
}
}
if (include.hasOutputTypes()) {
throw new RuntimeException("Not implemented");
}
return includeNode;
}
use of org.bimserver.database.queries.om.Include.TypeDef in project BIMserver by opensourceBIM.
the class QueryPart method dump.
public void dump(int indent, StringBuilder sb) {
if (indent > 10) {
// TODO this is also used for caching...
sb.append("..trimmed\n");
return;
}
if (hasTypes()) {
sb.append(indent(indent) + "types\n");
for (TypeDef type : getTypes()) {
sb.append(indent(indent + 1) + type.geteClass().getName() + ", " + type.isIncludeSubTypes() + "\n");
}
}
if (hasOids()) {
sb.append(indent(indent) + "oids\n");
for (long oid : getOids()) {
sb.append(indent(indent + 1) + oid + "\n");
}
}
if (hasGuids()) {
sb.append(indent(indent) + "guids\n");
for (String guid : getGuids()) {
sb.append(indent(indent + 1) + guid + "\n");
}
}
if (hasIncludes()) {
sb.append(indent(indent) + "includes\n");
for (Include include : getIncludes()) {
include.dump(indent + 1, sb);
}
}
if (hasInBoundingBox()) {
sb.append(indent(indent) + "inBoundingBox\n");
inBoundingBox.dump(indent + 1, sb);
}
if (hasProperties()) {
sb.append(indent(indent) + "properties\n");
for (String key : properties.keySet()) {
sb.append(indent(indent + 1) + key + ": " + properties.get(key));
}
}
}
Aggregations