use of org.bimserver.database.DatabaseSession.GetResult in project BIMserver by opensourceBIM.
the class QueryClassificationsAndTypesStackFrame method process.
@Override
boolean process() throws BimserverDatabaseException, QueryException, JsonParseException, JsonMappingException, IOException {
if (typeRecordIterator == null) {
return true;
}
if (record == null) {
currentObject = null;
typeRecordIterator.close();
return true;
}
currentObject = null;
ByteBuffer nextKeyStart = ByteBuffer.allocate(12);
getQueryObjectProvider().incReads();
ByteBuffer keyBuffer = ByteBuffer.wrap(record.getKey());
int keyPid = keyBuffer.getInt();
long keyOid = keyBuffer.getLong();
int keyRid = -keyBuffer.getInt();
ByteBuffer valueBuffer = ByteBuffer.wrap(record.getValue());
GetResult map = getMap(eClass, eClass, valueBuffer, keyPid, keyOid, keyRid);
if (map == GetResult.CONTINUE_WITH_NEXT_OID) {
nextKeyStart.position(0);
nextKeyStart.putInt(getReusable().getPid());
nextKeyStart.putLong(keyOid + 1);
record = typeRecordIterator.next(nextKeyStart.array());
} else {
record = typeRecordIterator.next();
}
if (currentObject != null) {
if (!allowedOids.contains(currentObject.getOid())) {
currentObject = null;
}
}
processPossibleIncludes(currentObject, eClass, getQueryPart());
return false;
}
use of org.bimserver.database.DatabaseSession.GetResult in project BIMserver by opensourceBIM.
the class QueryOidsAndTypesStackFrame method process.
@Override
public boolean process() throws BimserverDatabaseException, QueryException {
if (typeRecordIterator == null) {
return true;
}
if (record == null) {
currentObject = null;
typeRecordIterator.close();
return true;
}
currentObject = null;
ByteBuffer nextKeyStart = ByteBuffer.allocate(12);
getQueryObjectProvider().incReads();
ByteBuffer keyBuffer = ByteBuffer.wrap(record.getKey());
int keyPid = keyBuffer.getInt();
long keyOid = keyBuffer.getLong();
int keyRid = -keyBuffer.getInt();
ByteBuffer valueBuffer = ByteBuffer.wrap(record.getValue());
GetResult map = getMap(eClass, eClass, valueBuffer, keyPid, keyOid, keyRid);
if (map == GetResult.CONTINUE_WITH_NEXT_OID) {
if (oidIterator.hasNext()) {
nextKeyStart.position(0);
nextKeyStart.putInt(getReusable().getPid());
nextKeyStart.putLong(oidIterator.next());
record = typeRecordIterator.next(nextKeyStart.array());
} else {
record = null;
}
} else {
record = typeRecordIterator.next();
}
processPossibleIncludes(currentObject, eClass, getQueryPart());
if (record == null) {
typeRecordIterator.close();
}
return record == null;
}
use of org.bimserver.database.DatabaseSession.GetResult in project BIMserver by opensourceBIM.
the class QueryPropertiesAndTypesStackFrame method process.
@SuppressWarnings("unchecked")
@Override
public boolean process() throws BimserverDatabaseException, QueryException {
if (typeRecordIterator == null) {
return true;
}
if (record == null) {
currentObject = null;
typeRecordIterator.close();
return true;
}
currentObject = null;
ByteBuffer nextKeyStart = ByteBuffer.allocate(12);
getQueryObjectProvider().incReads();
ByteBuffer keyBuffer = ByteBuffer.wrap(record.getKey());
int keyPid = keyBuffer.getInt();
long keyOid = keyBuffer.getLong();
int keyRid = -keyBuffer.getInt();
ByteBuffer valueBuffer = ByteBuffer.wrap(record.getValue());
GetResult map = getMap(eClass, eClass, valueBuffer, keyPid, keyOid, keyRid);
if (map == GetResult.CONTINUE_WITH_NEXT_OID) {
nextKeyStart.position(0);
nextKeyStart.putInt(getReusable().getPid());
nextKeyStart.putLong(keyOid + 1);
record = typeRecordIterator.next(nextKeyStart.array());
} else {
record = typeRecordIterator.next();
}
if (currentObject != null) {
DatabaseSession databaseSession = getQueryObjectProvider().getDatabaseSession();
List<Long> isDefinedByOids = (List<Long>) currentObject.get("IsDefinedBy");
int totalQueryProperties = 0;
for (String key : this.properties.keySet()) {
totalQueryProperties += this.properties.get(key).count();
}
if (isDefinedByOids != null) {
Set<String> propertyKeysMatched = new HashSet<>();
for (Long definedByOid : isDefinedByOids) {
EClass eClass = databaseSession.getEClassForOid(definedByOid);
if (getPackageMetaData().getEClass("IfcRelDefinesByProperties").isSuperTypeOf(eClass)) {
HashMapVirtualObject ifcRelDefinesByProperties = getByOid(definedByOid);
Long ifcPropertySetDefinition = (Long) ifcRelDefinesByProperties.get("RelatingPropertyDefinition");
processPropertySet(databaseSession, propertyKeysMatched, ifcPropertySetDefinition);
} else if (getPackageMetaData().getEClass("IfcRelDefinesByType").isSuperTypeOf(eClass)) {
HashMapVirtualObject ifcRelDefinesByType = getByOid(definedByOid);
Long relatingTypeId = (Long) ifcRelDefinesByType.get("RelatingType");
EClass eClassForOid = databaseSession.getEClassForOid(relatingTypeId);
if (getPackageMetaData().getEClass("IfcTypeObject").isSuperTypeOf(eClassForOid)) {
HashMapVirtualObject ifcTypeObject = getByOid(relatingTypeId);
List<Long> propertySets = (List<Long>) ifcTypeObject.get("HasPropertySets");
if (propertySets != null) {
for (Long propertySetId : propertySets) {
processPropertySet(databaseSession, propertyKeysMatched, propertySetId);
}
}
}
} else {
LOGGER.info(eClass.getName());
}
}
if (propertyKeysMatched.size() != totalQueryProperties) {
// All properties should have matched, atm all properties provided in the query are evaluated as AND
currentObject = null;
}
}
}
processPossibleIncludes(currentObject, eClass, getQueryPart());
return false;
}
use of org.bimserver.database.DatabaseSession.GetResult in project BIMserver by opensourceBIM.
the class QueryTypeStackFrame method process.
@Override
public boolean process() throws BimserverDatabaseException, QueryException {
if (typeRecordIterator == null) {
return true;
}
if (record == null) {
currentObject = null;
typeRecordIterator.close();
return true;
}
currentObject = null;
ByteBuffer nextKeyStart = ByteBuffer.allocate(12);
getQueryObjectProvider().incReads();
ByteBuffer keyBuffer = ByteBuffer.wrap(record.getKey());
int keyPid = keyBuffer.getInt();
long keyOid = keyBuffer.getLong();
int keyRid = -keyBuffer.getInt();
ByteBuffer valueBuffer = ByteBuffer.wrap(record.getValue());
GetResult map = getMap(eClass, eClass, valueBuffer, keyPid, keyOid, keyRid);
if (map == GetResult.CONTINUE_WITH_NEXT_OID) {
nextKeyStart.position(0);
nextKeyStart.putInt(getReusable().getPid());
nextKeyStart.putLong(keyOid + 1);
record = typeRecordIterator.next(nextKeyStart.array());
} else {
record = typeRecordIterator.next();
}
if (currentObject != null) {
if (getQueryPart() != null && getQueryPart().getMinimumReuseThreshold() != -1) {
if (GeometryPackage.eINSTANCE.getGeometryData() == currentObject.eClass()) {
int saveableTriangles = (int) currentObject.get("saveableTriangles");
if (getQueryPart().getMinimumReuseThreshold() > saveableTriangles) {
currentObject = null;
return false;
}
}
}
}
processPossibleIncludes(currentObject, eClass, getQueryPart());
return false;
}
use of org.bimserver.database.DatabaseSession.GetResult in project BIMserver by opensourceBIM.
the class QueryBoundingBoxStackFrame method process.
@Override
public boolean process() throws BimserverDatabaseException, QueryException {
if (typeRecordIterator == null) {
return true;
}
if (record == null) {
currentObject = null;
typeRecordIterator.close();
return true;
}
currentObject = null;
ByteBuffer nextKeyStart = ByteBuffer.allocate(12);
getQueryObjectProvider().incReads();
ByteBuffer keyBuffer = ByteBuffer.wrap(record.getKey());
int keyPid = keyBuffer.getInt();
long keyOid = keyBuffer.getLong();
int keyRid = -keyBuffer.getInt();
ByteBuffer valueBuffer = ByteBuffer.wrap(record.getValue());
GetResult map = getMap(eClass, eClass, valueBuffer, keyPid, keyOid, keyRid);
if (map == GetResult.CONTINUE_WITH_NEXT_OID) {
nextKeyStart.position(0);
nextKeyStart.putInt(getReusable().getPid());
nextKeyStart.putLong(keyOid + 1);
record = typeRecordIterator.next(nextKeyStart.array());
} else {
record = typeRecordIterator.next();
}
if (currentObject != null) {
if (currentObject.has("geometry")) {
long geometryInfoId = (Long) currentObject.get("geometry");
HashMapVirtualObject geometryInfo = getByOid(geometryInfoId);
// TODO the querying party should be able to force the units used
// TODO use some spatial indexing, this is getting slow now that it's actually used
boolean hasAny = !Double.isNaN(inBoundingBox.getX()) || !Double.isNaN(inBoundingBox.getY()) || !Double.isNaN(inBoundingBox.getZ()) || !Double.isNaN(inBoundingBox.getWidth()) || !Double.isNaN(inBoundingBox.getHeight()) || !Double.isNaN(inBoundingBox.getDepth());
if (inBoundingBox.getDensityLowerThreshold() != null) {
float density = (float) geometryInfo.get("density");
if (density > inBoundingBox.getDensityLowerThreshold()) {
currentObject = null;
return false;
}
}
if (inBoundingBox.getDensityUpperThreshold() != null) {
float density = (float) geometryInfo.get("density");
if (density <= inBoundingBox.getDensityUpperThreshold()) {
currentObject = null;
return false;
}
}
if (hasAny) {
HashMapWrappedVirtualObject bounds = (HashMapWrappedVirtualObject) geometryInfo.get("boundsMm");
HashMapWrappedVirtualObject minBounds = (HashMapWrappedVirtualObject) bounds.eGet("min");
HashMapWrappedVirtualObject maxBounds = (HashMapWrappedVirtualObject) bounds.eGet("max");
double minX = (double) minBounds.eGet("x");
double minY = (double) minBounds.eGet("y");
double minZ = (double) minBounds.eGet("z");
double maxX = (double) maxBounds.eGet("x");
double maxY = (double) maxBounds.eGet("y");
double maxZ = (double) maxBounds.eGet("z");
if (inBoundingBox.isPartial()) {
// }
if (minX >= inBoundingBox.getX() && minY >= inBoundingBox.getY() && minZ >= inBoundingBox.getZ() && maxX <= inBoundingBox.getX() + inBoundingBox.getWidth() && maxY <= inBoundingBox.getY() + inBoundingBox.getHeight() && maxZ <= inBoundingBox.getZ() + inBoundingBox.getDepth()) {
// OK
} else if (minX <= inBoundingBox.getX() && minY <= inBoundingBox.getY() && minZ <= inBoundingBox.getZ() && maxX >= inBoundingBox.getX() + inBoundingBox.getWidth() && maxY >= inBoundingBox.getY() + inBoundingBox.getHeight() && maxZ >= inBoundingBox.getZ() + inBoundingBox.getDepth()) {
// OK
} else {
if ((minX <= inBoundingBox.getX() + inBoundingBox.getWidth() && maxX >= inBoundingBox.getX()) && (minY <= inBoundingBox.getY() + inBoundingBox.getHeight() && maxY >= inBoundingBox.getY()) && (minZ <= inBoundingBox.getZ() + inBoundingBox.getDepth() && maxZ >= inBoundingBox.getZ())) {
// OK
} else {
currentObject = null;
}
}
} else if (inBoundingBox.isUseCenterPoint()) {
double centerX = (minX + maxX) / 2f;
double centerY = (minY + maxY) / 2f;
double centerZ = (minZ + maxZ) / 2f;
if (centerX > inBoundingBox.getX() && centerY > inBoundingBox.getY() && centerZ > inBoundingBox.getZ() && centerX <= inBoundingBox.getX() + inBoundingBox.getWidth() && centerY <= inBoundingBox.getY() + inBoundingBox.getHeight() && centerZ <= inBoundingBox.getZ() + inBoundingBox.getDepth()) {
} else {
currentObject = null;
}
} else {
if (minX > inBoundingBox.getX() && minY > inBoundingBox.getY() && minZ > inBoundingBox.getZ() && maxX <= inBoundingBox.getX() + inBoundingBox.getWidth() && maxY <= inBoundingBox.getY() + inBoundingBox.getHeight() && maxZ <= inBoundingBox.getZ() + inBoundingBox.getDepth()) {
if (inBoundingBox.isExcludeOctants()) {
for (int x = 0; x < 2; x++) {
for (int y = 0; y < 2; y++) {
for (int z = 0; z < 2; z++) {
if (minX > inBoundingBox.getX() + (x * inBoundingBox.getWidth() / 2) && minY > inBoundingBox.getY() + (y * inBoundingBox.getHeight() / 2) && minZ > inBoundingBox.getZ() + (z * inBoundingBox.getDepth() / 2) && maxX < inBoundingBox.getX() + ((x == 0 ? 0.5f : 1f) * inBoundingBox.getWidth()) && maxY < inBoundingBox.getY() + ((y == 0 ? 0.5f : 1f) * inBoundingBox.getHeight()) && maxZ < inBoundingBox.getZ() + ((z == 0 ? 0.5f : 1f) * inBoundingBox.getDepth())) {
currentObject = null;
break;
}
}
}
}
} else {
// OK
}
} else {
currentObject = null;
}
}
}
} else {
currentObject = null;
}
}
processPossibleIncludes(currentObject, eClass, getQueryPart());
return false;
}
Aggregations