Search in sources :

Example 16 with HashMapVirtualObject

use of org.bimserver.shared.HashMapVirtualObject in project BIMserver by opensourceBIM.

the class CloneToNewProjectDatabaseAction method execute.

@Override
public ConcreteRevision execute() throws UserException, BimserverLockConflictException, BimserverDatabaseException {
    Revision oldRevision = getDatabaseSession().get(StorePackage.eINSTANCE.getRevision(), roid, OldQuery.getDefault());
    Project oldProject = oldRevision.getProject();
    final User user = getDatabaseSession().get(StorePackage.eINSTANCE.getUser(), authorization.getUoid(), OldQuery.getDefault());
    if (!authorization.hasRightsOnProjectOrSuperProjectsOrSubProjects(user, oldProject)) {
        throw new UserException("User has insufficient rights to download revisions from this project");
    }
    if (oldRevision.getConcreteRevisions().size() != 1) {
        throw new UserException("This method can only be used on Revisions that contain just one ConcreteRevision");
    }
    PackageMetaData packageMetaData = getBimServer().getMetaDataManager().getPackageMetaData(oldProject.getSchema());
    newProject = new AddProjectDatabaseAction(getBimServer(), getDatabaseSession(), getAccessMethod(), projectName, packageMetaData.getSchema().getEPackageName(), authorization).execute();
    ConcreteRevision oldConcreteRevision = oldRevision.getConcreteRevisions().get(0);
    SummaryMap summaryMap = new SummaryMap(packageMetaData, oldConcreteRevision.getSummary());
    Query query = new Query(packageMetaData);
    query.setSpecialQueryType(SpecialQueryType.ALL);
    CreateRevisionResult result = createNewConcreteRevision(getDatabaseSession(), oldRevision.getSize(), newProject, user, comment.trim());
    ConcreteRevision newConcreteRevision = result.getConcreteRevision();
    QueryContext newQueryContext = new QueryContext(getDatabaseSession(), packageMetaData, newProject.getId(), result.getRevisions().get(0).getId(), roid, newConcreteRevision.getOid(), -1);
    newConcreteRevision.setSummary(summaryMap.toRevisionSummary(getDatabaseSession()));
    newConcreteRevision.setOidCounters(new OidCounters(getDatabaseSession(), oldConcreteRevision.getOidCounters()).getBytes());
    newConcreteRevision.setIfcHeader(oldConcreteRevision.getIfcHeader());
    newConcreteRevision.setMultiplierToMm(oldConcreteRevision.getMultiplierToMm());
    newConcreteRevision.setBounds(oldConcreteRevision.getBounds());
    newConcreteRevision.setBoundsUntransformed(oldConcreteRevision.getBoundsUntransformed());
    try {
        QueryObjectProvider queryObjectProvider = new QueryObjectProvider(getDatabaseSession(), getBimServer(), query, Collections.singleton(roid), packageMetaData);
        HashMapVirtualObject next = queryObjectProvider.next();
        // Phase 1, copy all objects
        Map<Long, Long> oldOidToNew = new HashMap<>();
        while (next != null) {
            long oldOid = next.getOid();
            next.prepareForCopy(newQueryContext);
            Long newOid = getOrCreateOid(oldOidToNew, next.getReusable(), oldOid);
            next.setOid(newOid);
            for (EReference eReference : next.eClass().getEAllReferences()) {
                if (eReference.isMany()) {
                    List<Object> list = (List<Object>) next.get(eReference.getName());
                    if (list != null) {
                        for (int i = 0; i < list.size(); i++) {
                            Object object = list.get(i);
                            if (object instanceof Long) {
                                long refOid = (long) object;
                                Long newRefOid = getOrCreateOid(oldOidToNew, next.getReusable(), refOid);
                                list.set(i, newRefOid);
                            }
                        }
                    }
                } else {
                    Object object = next.eGet(eReference);
                    if (object != null) {
                        if (object instanceof Long) {
                            long refOid = (long) object;
                            long newRefOid = getOrCreateOid(oldOidToNew, next.getReusable(), refOid);
                            next.set(eReference.getName(), newRefOid);
                        }
                    }
                }
            }
            next.save();
            next = queryObjectProvider.next();
        }
    } catch (IOException e) {
        e.printStackTrace();
    } catch (QueryException e) {
        e.printStackTrace();
    }
    return null;
}
Also used : User(org.bimserver.models.store.User) Query(org.bimserver.database.queries.om.Query) OldQuery(org.bimserver.database.OldQuery) HashMap(java.util.HashMap) ConcreteRevision(org.bimserver.models.store.ConcreteRevision) QueryObjectProvider(org.bimserver.database.queries.QueryObjectProvider) OidCounters(org.bimserver.database.OidCounters) List(java.util.List) UserException(org.bimserver.shared.exceptions.UserException) EReference(org.eclipse.emf.ecore.EReference) PackageMetaData(org.bimserver.emf.PackageMetaData) QueryContext(org.bimserver.shared.QueryContext) IOException(java.io.IOException) Project(org.bimserver.models.store.Project) QueryException(org.bimserver.database.queries.om.QueryException) Revision(org.bimserver.models.store.Revision) ConcreteRevision(org.bimserver.models.store.ConcreteRevision) SummaryMap(org.bimserver.SummaryMap) HashMapVirtualObject(org.bimserver.shared.HashMapVirtualObject) HashMapVirtualObject(org.bimserver.shared.HashMapVirtualObject)

Example 17 with HashMapVirtualObject

use of org.bimserver.shared.HashMapVirtualObject in project BIMserver by opensourceBIM.

the class GeometryRunner method createBuffer.

private long createBuffer(QueryContext queryContext, ByteBuffer data) throws BimserverDatabaseException {
    HashMapVirtualObject buffer = new HashMapVirtualObject(queryContext, GeometryPackage.eINSTANCE.getBuffer());
    buffer.set("data", data.array());
    buffer.save();
    return buffer.getOid();
}
Also used : HashMapVirtualObject(org.bimserver.shared.HashMapVirtualObject)

Example 18 with HashMapVirtualObject

use of org.bimserver.shared.HashMapVirtualObject in project BIMserver by opensourceBIM.

the class GeometryAccellerator method generateReuseSet.

private ReuseSet generateReuseSet(ReuseKey key) {
    long start = System.nanoTime();
    ReuseSet reuseSet = new ReuseSet();
    try (DatabaseSession databaseSession = bimServer.getDatabase().createSession(OperationType.READ_ONLY)) {
        // Assuming all given roids are of projects that all have the same schema
        Revision revision = databaseSession.get(key.getRoids().iterator().next(), OldQuery.getDefault());
        PackageMetaData packageMetaData = bimServer.getMetaDataManager().getPackageMetaData(revision.getProject().getSchema());
        Query query = new Query(packageMetaData);
        Set<EClass> excluded = new HashSet<>();
        for (String exclude : key.getExcludedClasses()) {
            excluded.add(packageMetaData.getEClass(exclude));
        }
        QueryPart queryPart = query.createQueryPart();
        queryPart.addType(packageMetaData.getEClass("IfcProduct"), true, excluded);
        Include product = queryPart.createInclude();
        product.addType(packageMetaData.getEClass("IfcProduct"), true);
        product.addFieldDirect("geometry");
        Include geometryInfo = product.createInclude();
        geometryInfo.addType(GeometryPackage.eINSTANCE.getGeometryInfo(), false);
        Map<Long, ReuseObject> map = new HashMap<>();
        QueryObjectProvider queryObjectProvider = new QueryObjectProvider(databaseSession, bimServer, query, key.getRoids(), packageMetaData);
        HashMapVirtualObject next = queryObjectProvider.next();
        while (next != null) {
            AbstractHashMapVirtualObject geometry = next.getDirectFeature(packageMetaData.getEReference("IfcProduct", "geometry"));
            if (geometry != null) {
                Long dataId = (Long) geometry.get("data");
                ReuseObject reuseObject = map.get(dataId);
                if (reuseObject == null) {
                    reuseObject = new ReuseObject(dataId, 1, (int) geometry.get("primitiveCount"));
                    map.put(dataId, reuseObject);
                } else {
                    reuseObject.inc();
                }
            }
            next = queryObjectProvider.next();
        }
        for (long dataId : map.keySet()) {
            reuseSet.add(map.get(dataId));
        }
        long end = System.nanoTime();
        LOGGER.info("ReuseSets generated in " + ((end - start) / 1000000) + " ms");
    } catch (BimserverDatabaseException e) {
        LOGGER.error("", e);
    } catch (QueryException e) {
        LOGGER.error("", e);
    } catch (IOException e) {
        LOGGER.error("", e);
    }
    return reuseSet;
}
Also used : Query(org.bimserver.database.queries.om.Query) OldQuery(org.bimserver.database.OldQuery) DatabaseSession(org.bimserver.database.DatabaseSession) HashMap(java.util.HashMap) PackageMetaData(org.bimserver.emf.PackageMetaData) QueryPart(org.bimserver.database.queries.om.QueryPart) Include(org.bimserver.database.queries.om.Include) IOException(java.io.IOException) BimserverDatabaseException(org.bimserver.BimserverDatabaseException) EClass(org.eclipse.emf.ecore.EClass) QueryException(org.bimserver.database.queries.om.QueryException) Revision(org.bimserver.models.store.Revision) HashMapVirtualObject(org.bimserver.shared.HashMapVirtualObject) AbstractHashMapVirtualObject(org.bimserver.shared.AbstractHashMapVirtualObject) AbstractHashMapVirtualObject(org.bimserver.shared.AbstractHashMapVirtualObject) QueryObjectProvider(org.bimserver.database.queries.QueryObjectProvider) AtomicLong(java.util.concurrent.atomic.AtomicLong) HashSet(java.util.HashSet)

Example 19 with HashMapVirtualObject

use of org.bimserver.shared.HashMapVirtualObject in project BIMserver by opensourceBIM.

the class StreamingGeometryGenerator method processUnits.

private float processUnits(DatabaseSession databaseSession, QueryContext queryContext) throws QueryException, IOException, BimserverDatabaseException {
    Query query = new Query("Unit query", packageMetaData);
    QueryPart unitQueryPart = query.createQueryPart();
    unitQueryPart.addType(packageMetaData.getEClass("IfcProject"), false);
    Include unitsInContextInclude = unitQueryPart.createInclude();
    unitsInContextInclude.addType(packageMetaData.getEClass("IfcProject"), false);
    unitsInContextInclude.addField("UnitsInContext");
    Include units = unitsInContextInclude.createInclude();
    units.addType(packageMetaData.getEClass("IfcUnitAssignment"), false);
    units.addField("Units");
    Include unit = units.createInclude();
    unit.addType(packageMetaData.getEClass("IfcSIUnit"), false);
    QueryObjectProvider queryObjectProvider = new QueryObjectProvider(databaseSession, bimServer, query, Collections.singleton(queryContext.getRoid()), packageMetaData);
    HashMapVirtualObject next = queryObjectProvider.next();
    while (next != null) {
        if (packageMetaData.getEClass("IfcSIUnit").isSuperTypeOf(next.eClass())) {
            if (next.get("UnitType") == packageMetaData.getEEnumLiteral("IfcUnitEnum", "LENGTHUNIT").getInstance()) {
                Object prefix = next.get("Prefix");
                if (prefix == null) {
                    // Meters, we need to multiply by 1000 to go to mm
                    return 1000f;
                }
                return IfcUtils.getLengthUnitPrefixMm(((Enumerator) prefix).getName()) * 1000f;
            }
        }
        next = queryObjectProvider.next();
    }
    // Assume meters, we need to multiply by 1000
    return 1000f;
}
Also used : OldQuery(org.bimserver.database.OldQuery) Query(org.bimserver.database.queries.om.Query) HashMapVirtualObject(org.bimserver.shared.HashMapVirtualObject) AbstractHashMapVirtualObject(org.bimserver.shared.AbstractHashMapVirtualObject) Enumerator(org.eclipse.emf.common.util.Enumerator) QueryPart(org.bimserver.database.queries.om.QueryPart) QueryObjectProvider(org.bimserver.database.queries.QueryObjectProvider) Include(org.bimserver.database.queries.om.Include) HashMapWrappedVirtualObject(org.bimserver.shared.HashMapWrappedVirtualObject) VirtualObject(org.bimserver.shared.VirtualObject) HashMapVirtualObject(org.bimserver.shared.HashMapVirtualObject) AbstractHashMapVirtualObject(org.bimserver.shared.AbstractHashMapVirtualObject)

Example 20 with HashMapVirtualObject

use of org.bimserver.shared.HashMapVirtualObject in project BIMserver by opensourceBIM.

the class QueryIncludeStackFrame method process.

@SuppressWarnings("unchecked")
@Override
public boolean process() throws BimserverDatabaseException, QueryException {
    if (!featureIterator.hasNext()) {
        return true;
    }
    feature = featureIterator.next();
    Object value = currentObject.eGet(feature);
    if (value != null) {
        if (feature.isMany()) {
            List<Long> list = (List<Long>) value;
            for (Object r : list) {
                if (r instanceof Long) {
                    if (directFeatureSet != null && directFeatureSet.contains(feature)) {
                        HashMapVirtualObject byOid = getByOid((long) r, true);
                        getQueryObjectProvider().addRead(byOid.getOid());
                        currentObject.addDirectListReference(feature, byOid);
                        processPossibleIncludes(byOid, byOid.eClass(), include);
                    } else {
                        processReference((Long) r);
                    }
                } else {
                // ??
                }
            }
        } else {
            if (value instanceof Long) {
                long refOid = (Long) value;
                if (directFeatureSet != null && directFeatureSet.contains(feature)) {
                    HashMapVirtualObject byOid = getByOid((Long) refOid, true);
                    getQueryObjectProvider().addRead(byOid.getOid());
                    currentObject.setDirectReference(feature, byOid);
                    processPossibleIncludes(byOid, byOid.eClass(), include);
                } else {
                    processReference(refOid);
                }
            } else if (value instanceof WrappedVirtualObject) {
            // ??
            }
        }
    }
    return !featureIterator.hasNext();
}
Also used : HashMapVirtualObject(org.bimserver.shared.HashMapVirtualObject) HashMapVirtualObject(org.bimserver.shared.HashMapVirtualObject) WrappedVirtualObject(org.bimserver.shared.WrappedVirtualObject) List(java.util.List) WrappedVirtualObject(org.bimserver.shared.WrappedVirtualObject)

Aggregations

HashMapVirtualObject (org.bimserver.shared.HashMapVirtualObject)44 QueryObjectProvider (org.bimserver.database.queries.QueryObjectProvider)23 Query (org.bimserver.database.queries.om.Query)23 QueryPart (org.bimserver.database.queries.om.QueryPart)22 List (java.util.List)20 EClass (org.eclipse.emf.ecore.EClass)20 PackageMetaData (org.bimserver.emf.PackageMetaData)18 UserException (org.bimserver.shared.exceptions.UserException)17 EReference (org.eclipse.emf.ecore.EReference)15 BimserverDatabaseException (org.bimserver.BimserverDatabaseException)13 HashMapWrappedVirtualObject (org.bimserver.shared.HashMapWrappedVirtualObject)12 OldQuery (org.bimserver.database.OldQuery)11 IOException (java.io.IOException)9 HashMap (java.util.HashMap)8 HashSet (java.util.HashSet)8 Include (org.bimserver.database.queries.om.Include)8 QueryException (org.bimserver.database.queries.om.QueryException)7 ByteBuffer (java.nio.ByteBuffer)6 Revision (org.bimserver.models.store.Revision)6 EAttribute (org.eclipse.emf.ecore.EAttribute)6