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;
}
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();
}
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;
}
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;
}
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();
}
Aggregations