Search in sources :

Example 1 with IdEObject

use of org.bimserver.emf.IdEObject in project BIMserver by opensourceBIM.

the class DatabaseSession method writeWrappedValue.

private void writeWrappedValue(int pid, int rid, Object value, ByteBuffer buffer, PackageMetaData packageMetaData) throws BimserverDatabaseException {
    IdEObject wrappedValue = (IdEObject) value;
    EStructuralFeature eStructuralFeature = wrappedValue.eClass().getEStructuralFeature("wrappedValue");
    Short cid = database.getCidOfEClass(wrappedValue.eClass());
    buffer.order(ByteOrder.LITTLE_ENDIAN);
    buffer.putShort((short) -cid);
    buffer.order(ByteOrder.BIG_ENDIAN);
    writePrimitiveValue(eStructuralFeature, wrappedValue.eGet(eStructuralFeature), buffer);
    if (eStructuralFeature.getEType() == EcorePackage.eINSTANCE.getEDouble() || eStructuralFeature.getEType() == EcorePackage.eINSTANCE.getEDoubleObject()) {
        EStructuralFeature fe = wrappedValue.eClass().getEStructuralFeature("wrappedValueAsString");
        writePrimitiveValue(fe, wrappedValue.eGet(fe), buffer);
    }
    if (wrappedValue.eClass().getName().equals("IfcGloballyUniqueId")) {
        EClass eClass = packageMetaData.getEClass("IfcGloballyUniqueId");
        if (wrappedValue.getOid() == -1) {
            ((IdEObjectImpl) wrappedValue).setOid(newOid(eClass));
        }
        ByteBuffer valueBuffer = convertObjectToByteArray(wrappedValue, ByteBuffer.allocate(getExactSize(wrappedValue, packageMetaData, true)), packageMetaData);
        ByteBuffer keyBuffer = createKeyBuffer(pid, wrappedValue.getOid(), rid);
        try {
            database.getKeyValueStore().storeNoOverwrite(eClass.getEPackage().getName() + "_" + eClass.getName(), keyBuffer.array(), valueBuffer.array(), this);
            database.incrementCommittedWrites(1);
        } catch (BimserverLockConflictException e) {
            LOGGER.error("", e);
        }
    }
}
Also used : IdEObjectImpl(org.bimserver.emf.IdEObjectImpl) EClass(org.eclipse.emf.ecore.EClass) IdEObject(org.bimserver.emf.IdEObject) EStructuralFeature(org.eclipse.emf.ecore.EStructuralFeature) ByteBuffer(java.nio.ByteBuffer)

Example 2 with IdEObject

use of org.bimserver.emf.IdEObject in project BIMserver by opensourceBIM.

the class DatabaseSession method getExactSize.

private int getExactSize(IdEObject idEObject, PackageMetaData packageMetaData, boolean useUnsetBits) {
    int size = 0;
    int bits = 0;
    for (EStructuralFeature eStructuralFeature : idEObject.eClass().getEAllStructuralFeatures()) {
        if (packageMetaData.useForDatabaseStorage(idEObject.eClass(), eStructuralFeature)) {
            bits++;
            if (!useUnsetBits || !useUnsetBit(eStructuralFeature, idEObject)) {
                Object val = idEObject.eGet(eStructuralFeature);
                if (eStructuralFeature instanceof EAttribute) {
                    EAttribute eAttribute = (EAttribute) eStructuralFeature;
                    if (eAttribute.isMany()) {
                        size += 4;
                        for (Object v : ((List<?>) val)) {
                            size += getPrimitiveSize(eAttribute.getEAttributeType(), v);
                        }
                    } else {
                        size += getPrimitiveSize(eAttribute.getEAttributeType(), val);
                    }
                } else if (eStructuralFeature instanceof EReference) {
                    EReference eReference = (EReference) eStructuralFeature;
                    if (eReference.isMany()) {
                        size += 4;
                        for (Object v : ((List<?>) val)) {
                            size += getWrappedValueSize(v, eReference, packageMetaData);
                        }
                    } else {
                        size += getWrappedValueSize(val, eReference, packageMetaData);
                    }
                }
            }
        }
    }
    if (useUnsetBits) {
        size += (int) Math.ceil(bits / 8.0);
    }
    return size;
}
Also used : EAttribute(org.eclipse.emf.ecore.EAttribute) EStructuralFeature(org.eclipse.emf.ecore.EStructuralFeature) VirtualObject(org.bimserver.shared.VirtualObject) HashMapVirtualObject(org.bimserver.shared.HashMapVirtualObject) EObject(org.eclipse.emf.ecore.EObject) IdEObject(org.bimserver.emf.IdEObject) List(java.util.List) BasicEList(org.eclipse.emf.common.util.BasicEList) ArrayList(java.util.ArrayList) EList(org.eclipse.emf.common.util.EList) AbstractEList(org.eclipse.emf.common.util.AbstractEList) EReference(org.eclipse.emf.ecore.EReference)

Example 3 with IdEObject

use of org.bimserver.emf.IdEObject in project BIMserver by opensourceBIM.

the class DatabaseSession method processTodoList.

private void processTodoList(IfcModelInterface model, TodoList todoList, QueryInterface query) throws BimserverDatabaseException {
    IdEObject idEObject = todoList.poll();
    while (idEObject != null) {
        IdEObject result = get(idEObject, idEObject.getOid(), model, query, todoList);
        if (result == null) {
            throw new BimserverDatabaseException("Object not found: " + query.getPid() + " " + query.getRid() + " " + idEObject.getOid() + " " + idEObject.eClass().getName());
        }
        if (!model.contains(result.getOid())) {
            try {
                model.addAllowMultiModel(result.getOid(), result);
            } catch (IfcModelInterfaceException e) {
                throw new BimserverDatabaseException(e);
            }
        }
        idEObject = todoList.poll();
    }
}
Also used : BimserverDatabaseException(org.bimserver.BimserverDatabaseException) IfcModelInterfaceException(org.bimserver.emf.IfcModelInterfaceException) IdEObject(org.bimserver.emf.IdEObject)

Example 4 with IdEObject

use of org.bimserver.emf.IdEObject in project BIMserver by opensourceBIM.

the class DatabaseSession method create.

@SuppressWarnings("unchecked")
public <T> T create(EClass eClass, int pid, int rid) throws BimserverDatabaseException {
    checkOpen();
    IdEObject idEObject = createInternal(eClass, null);
    store(idEObject, pid, rid);
    return (T) idEObject;
}
Also used : IdEObject(org.bimserver.emf.IdEObject)

Example 5 with IdEObject

use of org.bimserver.emf.IdEObject in project BIMserver by opensourceBIM.

the class DatabaseSession method readEmbeddedValue.

private IdEObject readEmbeddedValue(EStructuralFeature feature, ByteBuffer buffer, EClass eClass, QueryInterface query) {
    IdEObject eObject = createInternal(eClass, query);
    for (EStructuralFeature eStructuralFeature : eClass.getEAllStructuralFeatures()) {
        if (eStructuralFeature.isMany()) {
        // Not implemented
        } else {
            Object primitiveValue = readPrimitiveValue(eStructuralFeature.getEType(), buffer, query);
            ((IdEObjectImpl) eObject).setLoaded();
            eObject.eSet(eStructuralFeature, primitiveValue);
        }
    }
    return eObject;
}
Also used : IdEObjectImpl(org.bimserver.emf.IdEObjectImpl) IdEObject(org.bimserver.emf.IdEObject) EStructuralFeature(org.eclipse.emf.ecore.EStructuralFeature) VirtualObject(org.bimserver.shared.VirtualObject) HashMapVirtualObject(org.bimserver.shared.HashMapVirtualObject) EObject(org.eclipse.emf.ecore.EObject) IdEObject(org.bimserver.emf.IdEObject)

Aggregations

IdEObject (org.bimserver.emf.IdEObject)68 List (java.util.List)25 EStructuralFeature (org.eclipse.emf.ecore.EStructuralFeature)25 EClass (org.eclipse.emf.ecore.EClass)20 EReference (org.eclipse.emf.ecore.EReference)18 IdEObjectImpl (org.bimserver.emf.IdEObjectImpl)15 UserException (org.bimserver.shared.exceptions.UserException)15 BimserverDatabaseException (org.bimserver.BimserverDatabaseException)14 EList (org.eclipse.emf.common.util.EList)14 EObject (org.eclipse.emf.ecore.EObject)14 ArrayList (java.util.ArrayList)12 AbstractEList (org.eclipse.emf.common.util.AbstractEList)12 HashSet (java.util.HashSet)10 IfcModelInterface (org.bimserver.emf.IfcModelInterface)10 HashMapVirtualObject (org.bimserver.shared.HashMapVirtualObject)10 OldQuery (org.bimserver.database.OldQuery)9 IfcModelInterfaceException (org.bimserver.emf.IfcModelInterfaceException)9 VirtualObject (org.bimserver.shared.VirtualObject)9 EAttribute (org.eclipse.emf.ecore.EAttribute)9 Project (org.bimserver.models.store.Project)8