use of org.bimserver.shared.HashMapVirtualObject in project BIMserver by opensourceBIM.
the class QueryObjectProvider method next.
@Override
public HashMapVirtualObject next() throws BimserverDatabaseException {
if (start == -1) {
start = System.nanoTime();
}
try {
while (!stack.isEmpty()) {
if (stack.size() > MAX_STACK_SIZE) {
dumpEndQuery();
throw new BimserverDatabaseException("Query stack size > " + MAX_STACK_SIZE + ", probably a bug, please report");
}
stackFrame = stack.peek();
if (stackFrame.isDone()) {
stack.pop();
continue;
}
stackFramesProcessed++;
if (stackFramesProcessed > MAX_STACK_FRAMES_PROCESSED) {
dumpEndQuery();
throw new BimserverDatabaseException("Too many stack frames processed ( > " + MAX_STACK_FRAMES_PROCESSED + "), probably a bug, or possibly a very large model, please report");
}
boolean done = stackFrame.process();
stackFrame.setDone(done);
if (stackFrame instanceof ObjectProvidingStackFrame) {
HashMapVirtualObject currentObject = ((ObjectProvidingStackFrame) stackFrame).getCurrentObject();
if (currentObject != null) {
if (!oidsRead.contains(currentObject.getOid())) {
oidsRead.add(currentObject.getOid());
return currentObject;
}
}
}
}
} catch (Exception e) {
if (e instanceof BimserverDatabaseException) {
throw (BimserverDatabaseException) e;
}
throw new BimserverDatabaseException(e);
}
return null;
}
use of org.bimserver.shared.HashMapVirtualObject 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()) {
// TODO also exclude the possibly excluded types here
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);
int index = object.addDirectListReference(eReference, byOid);
object.addUseForSerialization(eReference, index);
processPossibleIncludes(byOid, byOid.eClass(), include);
}
} else {
if (ref instanceof Long) {
HashMapVirtualObject byOid = getByOid((Long) ref, true);
if (byOid == null) {
throw new BimserverDatabaseException("Object with oid " + ref + " not found (" + queryObjectProvider.getDatabaseSession().getEClassForOid((Long) ref).getName() + ")");
}
object.setDirectReference(eReference, byOid);
object.addUseForSerialization(eReference);
processPossibleIncludes(byOid, byOid.eClass(), include);
} else {
object.setDirectReference(eReference, (HashMapWrappedVirtualObject) ref);
}
}
}
}
}
if (include.hasFields() && !include.isExclude()) {
for (EStructuralFeature eStructuralFeature : include.getFields()) {
object.addUseForSerialization(eStructuralFeature);
}
}
getQueryObjectProvider().push(new QueryIncludeStackFrame(getQueryObjectProvider(), getReusable(), previousInclude, include, object, queryPart));
}
use of org.bimserver.shared.HashMapVirtualObject in project BIMserver by opensourceBIM.
the class DatabaseReadingStackFrame method readList.
private Object readList(HashMapVirtualObject idEObject, ByteBuffer buffer, EStructuralFeature feature) throws BimserverDatabaseException {
if (feature.getEType() instanceof EEnum) {
} else if (feature.getEType() instanceof EClass) {
if (buffer.capacity() == 1 && buffer.get(0) == -1) {
buffer.position(buffer.position() + 1);
} else {
int listSize = buffer.getInt();
for (int i = 0; i < listSize; i++) {
if (feature.getEAnnotation("twodimensionalarray") != null) {
HashMapVirtualObject newObject = new HashMapVirtualObject(reusable, (EClass) feature.getEType());
EClass eClass = (EClass) feature.getEType();
EStructuralFeature eStructuralFeature = eClass.getEStructuralFeature("List");
buffer.order(ByteOrder.LITTLE_ENDIAN);
short cid = buffer.getShort();
buffer.order(ByteOrder.BIG_ENDIAN);
EClass referenceClass = queryObjectProvider.getDatabaseSession().getEClass((short) (-cid));
if (referenceClass == null) {
throw new BimserverDatabaseException("No class found for cid " + (-cid));
}
Object result = readList(newObject, buffer, eStructuralFeature);
if (eStructuralFeature.getEType() == EcorePackage.eINSTANCE.getEDouble() || eStructuralFeature.getEType() == EcorePackage.eINSTANCE.getEDoubleObject()) {
result = readList(newObject, buffer, eClass.getEStructuralFeature("ListAsString"));
}
idEObject.setListItem(feature, i, newObject);
} else {
buffer.order(ByteOrder.LITTLE_ENDIAN);
short cid = buffer.getShort();
buffer.order(ByteOrder.BIG_ENDIAN);
if (cid == -1) {
// null, do nothing
} else if (cid < 0) {
// negative cid means value is
// embedded
// in record
EClass referenceClass = queryObjectProvider.getDatabaseSession().getEClass((short) (-cid));
if (referenceClass == null) {
throw new BimserverDatabaseException("No class found for cid " + (-cid));
}
EStructuralFeature wv = referenceClass.getEStructuralFeature("wrappedValue");
if (wv != null && wv.isMany()) {
HashMapVirtualObject eObject = new HashMapVirtualObject(reusable, referenceClass);
readList(eObject, buffer, wv);
idEObject.setListItem(feature, i, eObject);
} else {
idEObject.setListItem(feature, i, readWrappedValue(feature, buffer, referenceClass));
}
idEObject.addUseForSerialization(feature, i);
} else if (cid > 0) {
// positive cid means value is a
// reference
// to another record
EClass referenceClass = queryObjectProvider.getDatabaseSession().getEClass(cid);
if (referenceClass == null) {
throw new BimserverDatabaseException("Cannot find class with cid " + cid);
}
buffer.position(buffer.position() - 2);
long rf = readReference(buffer, feature, referenceClass);
idEObject.setListItemReference(feature, i, referenceClass, rf, -1);
if (rf != -1) {
if (queryObjectProvider.hasReadOrIsGoingToRead((rf)) || queryObjectProvider.hasReadOrIsGoingToRead(referenceClass)) {
idEObject.addUseForSerialization(feature, i);
}
}
// } else if (cid == 0) {
// throw new BimserverDatabaseException("Cid cannot be 0");
}
}
}
}
} else if (feature.getEType() instanceof EDataType) {
int listSize = buffer.getInt();
if (listSize < 0) {
throw new BimserverDatabaseException("Negative array size for " + feature.getEContainingClass().getName() + "." + feature.getName());
}
for (int i = 0; i < listSize; i++) {
Object reference = readPrimitiveValue(feature.getEType(), buffer);
if (reference != null) {
idEObject.setListItem(feature, i, reference);
}
}
}
return null;
}
use of org.bimserver.shared.HashMapVirtualObject in project BIMserver by opensourceBIM.
the class StreamingGeometryGenerator method placementToMatrix.
private double[] placementToMatrix(HashMapVirtualObject placement) {
HashMapVirtualObject placementRelTo = placement.getDirectFeature(packageMetaData.getEReference("IfcLocalPlacement", "PlacementRelTo"));
double[] matrix = Matrix.identity();
if (placement.eClass().getName().equals("IfcLocalPlacement")) {
HashMapVirtualObject relativePlacement = placement.getDirectFeature(packageMetaData.getEReference("IfcLocalPlacement", "RelativePlacement"));
if (relativePlacement != null && relativePlacement.eClass().getName().equals("IfcAxis2Placement3D")) {
matrix = placement3DToMatrix(relativePlacement);
}
}
if (placementRelTo != null) {
double[] baseMatrix = placementToMatrix(placementRelTo);
double[] rhs = matrix;
matrix = Matrix.identity();
Matrix.multiplyMM(matrix, 0, baseMatrix, 0, rhs, 0);
}
return matrix;
}
use of org.bimserver.shared.HashMapVirtualObject in project BIMserver by opensourceBIM.
the class DatabaseReadingStackFrame method convertByteArrayToObject.
protected HashMapVirtualObject convertByteArrayToObject(EClass eClass, long oid, ByteBuffer buffer, int rid) throws BimserverDatabaseException {
try {
int unsettedLength = getPackageMetaData().getUnsettedLength(eClass);
byte[] unsetted = new byte[unsettedLength];
buffer.get(unsetted);
int fieldCounter = 0;
HashMapVirtualObject idEObject = new HashMapVirtualObject(reusable, eClass, oid, new UUID(buffer.getLong(), buffer.getLong()));
for (EStructuralFeature feature : eClass.getEAllStructuralFeatures()) {
try {
if (getPackageMetaData().useForDatabaseStorage(eClass, feature)) {
boolean isUnsetted = (unsetted[fieldCounter / 8] & (1 << (fieldCounter % 8))) != 0;
if (isUnsetted) {
if (feature.isUnsettable()) {
idEObject.eUnset(feature);
} else if (feature.isMany()) {
// do nothing
} else if (feature.getDefaultValue() != null) {
idEObject.setAttribute((EAttribute) feature, feature.getDefaultValue());
}
} else {
Object newValue = null;
if (feature.isMany()) {
newValue = readList(idEObject, buffer, feature);
} else {
if (feature.getEType() instanceof EEnum) {
int enumOrdinal = buffer.getInt();
if (enumOrdinal == -1) {
newValue = null;
} else {
EClassifier eType = feature.getEType();
EEnumLiteral enumLiteral = ((EEnumImpl) eType).getEEnumLiteral(enumOrdinal);
if (enumLiteral != null) {
newValue = enumLiteral.getInstance();
}
}
} else if (feature.getEType() instanceof EClass) {
// EReference eReference = (EReference) feature;
buffer.order(ByteOrder.LITTLE_ENDIAN);
short cid = buffer.getShort();
buffer.order(ByteOrder.BIG_ENDIAN);
if (cid == -1) {
// null, do nothing
} else if (cid < 0) {
// negative cid means value is embedded in
// record
EClass referenceClass = queryObjectProvider.getDatabaseSession().getEClass((short) (-cid));
if (feature.getEAnnotation("dbembed") != null) {
newValue = readEmbeddedValue(feature, buffer, referenceClass);
} else {
newValue = readWrappedValue(feature, buffer, referenceClass);
}
} else if (cid > 0) {
// positive cid means value is reference to
// other record
EClass referenceClass = queryObjectProvider.getDatabaseSession().getEClass(cid);
if (referenceClass == null) {
throw new BimserverDatabaseException("No eClass found for cid " + cid);
}
buffer.position(buffer.position() - 2);
newValue = readReference(buffer, feature, referenceClass);
if ((Long) newValue != -1) {
if (queryObjectProvider.hasReadOrIsGoingToRead(((Long) newValue)) || queryObjectProvider.hasReadOrIsGoingToRead(referenceClass)) {
idEObject.addUseForSerialization(feature);
}
}
// if (eReference.getEOpposite() != null &&
// ((IdEObjectImpl)
// newValue).isLoadedOrLoading()) {
// newValue = null;
// }
}
} else if (feature.getEType() instanceof EDataType) {
newValue = readPrimitiveValue(feature.getEType(), buffer);
}
if (newValue != null) {
if (feature instanceof EAttribute) {
idEObject.setAttribute((EAttribute) feature, newValue);
} else {
if (newValue instanceof Long) {
idEObject.setReference((EReference) feature, (Long) newValue);
} else {
idEObject.setReference((EReference) feature, (WrappedVirtualObject) newValue);
}
}
}
}
}
fieldCounter++;
}
} catch (StringIndexOutOfBoundsException e) {
throw new BimserverDatabaseException("Reading " + eClass.getName() + "." + feature.getName(), e);
} catch (BufferUnderflowException e) {
throw new BimserverDatabaseException("Reading " + eClass.getName() + "." + feature.getName() + " " + buffer.capacity(), e);
} catch (BufferOverflowException e) {
throw new BimserverDatabaseException("Reading " + eClass.getName() + "." + feature.getName(), e);
}
}
return idEObject;
} catch (BufferUnderflowException e) {
throw new BimserverDatabaseException("Reading " + eClass.getName(), e);
} catch (BufferOverflowException e) {
throw new BimserverDatabaseException("Reading " + eClass.getName(), e);
}
}
Aggregations