Search in sources :

Example 16 with IdEObjectImpl

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

the class GetDataObjectByOidDatabaseAction method execute.

@Override
public DataObject execute() throws UserException, BimserverLockConflictException, BimserverDatabaseException {
    Revision virtualRevision = getRevisionByRoid(roid);
    EObject eObject = null;
    IfcModelSet ifcModelSet = new IfcModelSet();
    PackageMetaData lastPackageMetaData = null;
    Map<Integer, Long> pidRoidMap = new HashMap<>();
    pidRoidMap.put(virtualRevision.getProject().getId(), virtualRevision.getOid());
    for (ConcreteRevision concreteRevision : virtualRevision.getConcreteRevisions()) {
        PackageMetaData packageMetaData = getBimServer().getMetaDataManager().getPackageMetaData(concreteRevision.getProject().getSchema());
        lastPackageMetaData = packageMetaData;
        IfcModel subModel = new BasicIfcModel(packageMetaData, pidRoidMap);
        int highestStopId = findHighestStopRid(concreteRevision.getProject(), concreteRevision);
        OldQuery query = new OldQuery(packageMetaData, concreteRevision.getProject().getId(), concreteRevision.getId(), virtualRevision.getOid(), null, Deep.NO, highestStopId);
        eObject = getDatabaseSession().get(null, oid, subModel, query);
        subModel.getModelMetaData().setDate(concreteRevision.getDate());
        ifcModelSet.add(subModel);
        if (eObject != null) {
            break;
        }
    }
    IfcModelInterface ifcModel = new BasicIfcModel(lastPackageMetaData, pidRoidMap);
    if (ifcModelSet.size() > 1) {
        try {
            ifcModel = getBimServer().getMergerFactory().createMerger(getDatabaseSession(), getAuthorization().getUoid()).merge(virtualRevision.getProject(), ifcModelSet, new ModelHelper(getBimServer().getMetaDataManager(), ifcModel));
        } catch (MergeException e) {
            throw new UserException(e);
        }
    } else {
        ifcModel = ifcModelSet.iterator().next();
    }
    if (eObject == null) {
        throw new UserException("Object not found in this project/revision");
    }
    DataObject dataObject = null;
    if (eObject instanceof IfcRoot) {
        IfcRoot ifcRoot = (IfcRoot) eObject;
        String guid = ifcRoot.getGlobalId() != null ? ifcRoot.getGlobalId() : "";
        String name = ifcRoot.getName() != null ? ifcRoot.getName() : "";
        dataObject = StoreFactory.eINSTANCE.createDataObject();
        dataObject.setType(eObject.eClass().getName());
        ((IdEObjectImpl) dataObject).setOid(oid);
        dataObject.setGuid(guid);
        dataObject.setName(name);
    } else {
        dataObject = StoreFactory.eINSTANCE.createDataObject();
        dataObject.setType(eObject.eClass().getName());
        ((IdEObjectImpl) dataObject).setOid(oid);
        dataObject.setName("");
        dataObject.setGuid("");
    }
    fillDataObject(ifcModel.getObjects(), eObject, dataObject);
    return dataObject;
}
Also used : IdEObjectImpl(org.bimserver.emf.IdEObjectImpl) ModelHelper(org.bimserver.plugins.ModelHelper) HashMap(java.util.HashMap) PackageMetaData(org.bimserver.emf.PackageMetaData) IfcModelInterface(org.bimserver.emf.IfcModelInterface) IfcRoot(org.bimserver.models.ifc2x3tc1.IfcRoot) BasicIfcModel(org.bimserver.ifc.BasicIfcModel) OldQuery(org.bimserver.database.OldQuery) BasicIfcModel(org.bimserver.ifc.BasicIfcModel) IfcModel(org.bimserver.ifc.IfcModel) DataObject(org.bimserver.models.store.DataObject) Revision(org.bimserver.models.store.Revision) ConcreteRevision(org.bimserver.models.store.ConcreteRevision) ConcreteRevision(org.bimserver.models.store.ConcreteRevision) MergeException(org.bimserver.plugins.modelmerger.MergeException) IdEObject(org.bimserver.emf.IdEObject) EObject(org.eclipse.emf.ecore.EObject) IfcModelSet(org.bimserver.plugins.IfcModelSet) UserException(org.bimserver.shared.exceptions.UserException)

Example 17 with IdEObjectImpl

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

the class GetDataObjectsByTypeDatabaseAction method execute.

@Override
public List<DataObject> execute() throws UserException, BimserverLockConflictException, BimserverDatabaseException {
    EClass eClass = getDatabaseSession().getEClassForName(packageName, className);
    Revision virtualRevision = getRevisionByRoid(roid);
    if (virtualRevision == null) {
        throw new UserException("No revision with roid " + roid + " found");
    }
    Map<Integer, Long> pidRoidMap = new HashMap<>();
    IfcModelSet ifcModelSet = new IfcModelSet();
    pidRoidMap.put(virtualRevision.getProject().getId(), virtualRevision.getOid());
    PackageMetaData lastPackageMetaData = null;
    Project project = virtualRevision.getProject();
    for (ConcreteRevision concreteRevision : virtualRevision.getConcreteRevisions()) {
        PackageMetaData packageMetaData = getBimServer().getMetaDataManager().getPackageMetaData(concreteRevision.getProject().getSchema());
        int highestStopId = findHighestStopRid(project, concreteRevision);
        OldQuery query = new OldQuery(packageMetaData, concreteRevision.getProject().getId(), concreteRevision.getId(), -1, null, Deep.NO, highestStopId);
        lastPackageMetaData = packageMetaData;
        IfcModelInterface subModel = getDatabaseSession().getAllOfType(packageMetaData.getEPackage().getName(), className, query);
        subModel.getModelMetaData().setDate(concreteRevision.getDate());
        ifcModelSet.add(subModel);
    }
    IfcModelInterface ifcModel = new ServerIfcModel(lastPackageMetaData, pidRoidMap, getDatabaseSession());
    if (ifcModelSet.size() > 1) {
        try {
            ifcModel = getBimServer().getMergerFactory().createMerger(getDatabaseSession(), getAuthorization().getUoid()).merge(project, ifcModelSet, new ModelHelper(getBimServer().getMetaDataManager(), ifcModel));
        } catch (MergeException e) {
            throw new UserException(e);
        }
    } else {
        ifcModel = ifcModelSet.iterator().next();
    }
    List<DataObject> dataObjects = new ArrayList<DataObject>();
    for (Long oid : new HashSet<>(ifcModel.keySet())) {
        EObject eObject = ifcModel.get(oid);
        if (eClass.isInstance(eObject)) {
            DataObject dataObject = StoreFactory.eINSTANCE.createDataObject();
            if (eObject instanceof IfcRoot) {
                IfcRoot ifcRoot = (IfcRoot) eObject;
                String guid = ifcRoot.getGlobalId() != null ? ifcRoot.getGlobalId() : "";
                String name = ifcRoot.getName() != null ? ifcRoot.getName() : "";
                dataObject = StoreFactory.eINSTANCE.createDataObject();
                dataObject.setType(eObject.eClass().getName());
                ((IdEObjectImpl) dataObject).setOid(oid);
                dataObject.setGuid(guid);
                dataObject.setName(name);
            } else {
                dataObject = StoreFactory.eINSTANCE.createDataObject();
                dataObject.setType(eObject.eClass().getName());
                ((IdEObjectImpl) dataObject).setOid(oid);
                dataObject.setGuid("");
                dataObject.setName("");
            }
            if (!flat) {
                GetDataObjectByOidDatabaseAction.fillDataObject(ifcModel.getObjects(), eObject, dataObject);
            }
            dataObjects.add(dataObject);
        }
    }
    return dataObjects;
}
Also used : IdEObjectImpl(org.bimserver.emf.IdEObjectImpl) ServerIfcModel(org.bimserver.ServerIfcModel) HashMap(java.util.HashMap) IfcModelInterface(org.bimserver.emf.IfcModelInterface) IfcRoot(org.bimserver.models.ifc2x3tc1.IfcRoot) ArrayList(java.util.ArrayList) EClass(org.eclipse.emf.ecore.EClass) ConcreteRevision(org.bimserver.models.store.ConcreteRevision) MergeException(org.bimserver.plugins.modelmerger.MergeException) EObject(org.eclipse.emf.ecore.EObject) UserException(org.bimserver.shared.exceptions.UserException) HashSet(java.util.HashSet) ModelHelper(org.bimserver.plugins.ModelHelper) PackageMetaData(org.bimserver.emf.PackageMetaData) OldQuery(org.bimserver.database.OldQuery) Project(org.bimserver.models.store.Project) DataObject(org.bimserver.models.store.DataObject) Revision(org.bimserver.models.store.Revision) ConcreteRevision(org.bimserver.models.store.ConcreteRevision) IfcModelSet(org.bimserver.plugins.IfcModelSet)

Example 18 with IdEObjectImpl

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

the class GetDataObjectsDatabaseAction method execute.

@Override
public List<DataObject> execute() throws UserException, BimserverLockConflictException, BimserverDatabaseException {
    Revision virtualRevision = getRevisionByRoid(roid);
    IfcModelSet ifcModelSet = new IfcModelSet();
    PackageMetaData lastPackageMetaData = null;
    Map<Integer, Long> pidRoidMap = new HashMap<>();
    pidRoidMap.put(virtualRevision.getProject().getId(), virtualRevision.getOid());
    for (ConcreteRevision concreteRevision : virtualRevision.getConcreteRevisions()) {
        int highestStopId = findHighestStopRid(concreteRevision.getProject(), concreteRevision);
        PackageMetaData packageMetaData = getBimServer().getMetaDataManager().getPackageMetaData(concreteRevision.getProject().getSchema());
        lastPackageMetaData = packageMetaData;
        IfcModel subModel = new ServerIfcModel(packageMetaData, pidRoidMap, getDatabaseSession());
        OldQuery query = new OldQuery(packageMetaData, concreteRevision.getProject().getId(), concreteRevision.getId(), virtualRevision.getOid(), null, Deep.YES, highestStopId);
        getDatabaseSession().getMap(subModel, query);
        subModel.getModelMetaData().setDate(concreteRevision.getDate());
        ifcModelSet.add(subModel);
    }
    IfcModelInterface ifcModel = new ServerIfcModel(lastPackageMetaData, pidRoidMap, getDatabaseSession());
    try {
        ifcModel = getBimServer().getMergerFactory().createMerger(getDatabaseSession(), getAuthorization().getUoid()).merge(virtualRevision.getProject(), ifcModelSet, new ModelHelper(getBimServer().getMetaDataManager(), ifcModel));
    } catch (MergeException e) {
        throw new UserException(e);
    }
    List<DataObject> dataObjects = new ArrayList<DataObject>();
    for (Long oid : ifcModel.keySet()) {
        EObject eObject = ifcModel.get(oid);
        if (eObject.eClass().getEAnnotation("hidden") == null) {
            DataObject dataObject = null;
            if (eObject instanceof IfcRoot) {
                IfcRoot ifcRoot = (IfcRoot) eObject;
                String guid = ifcRoot.getGlobalId() != null ? ifcRoot.getGlobalId() : "";
                String name = ifcRoot.getName() != null ? ifcRoot.getName() : "";
                dataObject = StoreFactory.eINSTANCE.createDataObject();
                dataObject.setType(eObject.eClass().getName());
                ((IdEObjectImpl) dataObject).setOid(oid);
                dataObject.setGuid(guid);
                dataObject.setName(name);
            } else {
                dataObject = StoreFactory.eINSTANCE.createDataObject();
                dataObject.setType(eObject.eClass().getName());
                ((IdEObjectImpl) dataObject).setOid(oid);
                dataObject.setGuid("");
                dataObject.setName("");
            }
            GetDataObjectByOidDatabaseAction.fillDataObject(ifcModel.getObjects(), eObject, dataObject);
            dataObjects.add(dataObject);
        }
    }
    return dataObjects;
}
Also used : IdEObjectImpl(org.bimserver.emf.IdEObjectImpl) ServerIfcModel(org.bimserver.ServerIfcModel) ModelHelper(org.bimserver.plugins.ModelHelper) HashMap(java.util.HashMap) PackageMetaData(org.bimserver.emf.PackageMetaData) IfcModelInterface(org.bimserver.emf.IfcModelInterface) IfcRoot(org.bimserver.models.ifc2x3tc1.IfcRoot) ArrayList(java.util.ArrayList) OldQuery(org.bimserver.database.OldQuery) ServerIfcModel(org.bimserver.ServerIfcModel) IfcModel(org.bimserver.ifc.IfcModel) DataObject(org.bimserver.models.store.DataObject) Revision(org.bimserver.models.store.Revision) ConcreteRevision(org.bimserver.models.store.ConcreteRevision) ConcreteRevision(org.bimserver.models.store.ConcreteRevision) MergeException(org.bimserver.plugins.modelmerger.MergeException) EObject(org.eclipse.emf.ecore.EObject) IfcModelSet(org.bimserver.plugins.IfcModelSet) UserException(org.bimserver.shared.exceptions.UserException)

Example 19 with IdEObjectImpl

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

the class DatabaseSession method lazyLoad.

@SuppressWarnings("unused")
public IdEObject lazyLoad(IdEObject idEObject) throws BimserverDatabaseException {
    if (DEVELOPER_DEBUG) {
        LOGGER.info("Lazy loading " + idEObject.eClass().getName() + " " + idEObject.getOid());
    }
    IfcModelInterface model = ((IdEObjectImpl) idEObject).getModel();
    if (model == null) {
        Map<Integer, Long> pidToRoid = new HashMap<Integer, Long>();
        model = createModel(getMetaDataManager().getPackageMetaData(idEObject.eClass().getEPackage().getName()), pidToRoid);
    }
    idEObject = get(idEObject, idEObject.getOid(), model, ((IdEObjectImpl) idEObject).getQueryInterface(), new TodoList());
    if (idEObject != null) {
        if (DEVELOPER_DEBUG && idEObject.getRid() > 100000 || idEObject.getRid() < -100000) {
            LOGGER.debug("Improbable rid " + idEObject.getRid() + " - " + idEObject);
        }
    }
    return idEObject;
}
Also used : IdEObjectImpl(org.bimserver.emf.IdEObjectImpl) HashMap(java.util.HashMap) IfcModelInterface(org.bimserver.emf.IfcModelInterface)

Example 20 with IdEObjectImpl

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

the class DatabaseSession method readReference.

private IdEObject readReference(EClass originalQueryClass, ByteBuffer buffer, IfcModelInterface model, IdEObject object, EStructuralFeature feature, EClass eClass, QueryInterface query, TodoList todoList) throws BimserverDatabaseException {
    // TODO next bit seems to make no sense, why detect a deleted record when reading a reference??
    if (buffer.capacity() == 1 && buffer.get(0) == -1) {
        buffer.position(buffer.position() + 1);
        return null;
    }
    buffer.order(ByteOrder.LITTLE_ENDIAN);
    long oid = buffer.getLong();
    buffer.order(ByteOrder.BIG_ENDIAN);
    IdEObject foundInCache = objectCache.get(oid);
    if (foundInCache != null) {
        return foundInCache;
    }
    if (model.contains(oid)) {
        return model.get(oid);
    }
    IdEObjectImpl newObject = createInternal(eClass, query);
    newObject.setOid(oid);
    if (perRecordVersioning(newObject)) {
        newObject.setPid(Database.STORE_PROJECT_ID);
    } else {
        newObject.setPid(query.getPid());
    }
    newObject.setRid(query.getRid());
    try {
        newObject.setModel(model);
    } catch (IfcModelInterfaceException e) {
        LOGGER.error("", e);
    }
    objectCache.put(oid, newObject);
    if (query.isDeep() && object.eClass().getEAnnotation("wrapped") == null) {
        if (feature.getEAnnotation("nolazyload") == null) {
            todoList.add(newObject);
        }
    } else {
        if (object.eClass().getEAnnotation("wrapped") == null) {
            try {
                model.addAllowMultiModel(oid, newObject);
            } catch (IfcModelInterfaceException e) {
                throw new BimserverDatabaseException(e);
            }
        }
    }
    return newObject;
}
Also used : IdEObjectImpl(org.bimserver.emf.IdEObjectImpl) IfcModelInterfaceException(org.bimserver.emf.IfcModelInterfaceException) BimserverDatabaseException(org.bimserver.BimserverDatabaseException) IdEObject(org.bimserver.emf.IdEObject)

Aggregations

IdEObjectImpl (org.bimserver.emf.IdEObjectImpl)23 IdEObject (org.bimserver.emf.IdEObject)16 EObject (org.eclipse.emf.ecore.EObject)10 EClass (org.eclipse.emf.ecore.EClass)8 UserException (org.bimserver.shared.exceptions.UserException)7 EStructuralFeature (org.eclipse.emf.ecore.EStructuralFeature)7 HashMap (java.util.HashMap)6 IfcModelInterfaceException (org.bimserver.emf.IfcModelInterfaceException)6 EAttribute (org.eclipse.emf.ecore.EAttribute)6 EReference (org.eclipse.emf.ecore.EReference)6 IfcModelInterface (org.bimserver.emf.IfcModelInterface)5 IfcRoot (org.bimserver.models.ifc2x3tc1.IfcRoot)5 HashMapVirtualObject (org.bimserver.shared.HashMapVirtualObject)5 AbstractEList (org.eclipse.emf.common.util.AbstractEList)5 ArrayList (java.util.ArrayList)4 List (java.util.List)4 BimserverDatabaseException (org.bimserver.BimserverDatabaseException)4 OldQuery (org.bimserver.database.OldQuery)4 QueryException (org.bimserver.database.queries.om.QueryException)4 PackageMetaData (org.bimserver.emf.PackageMetaData)4