use of org.bimserver.database.queries.om.QueryPart in project BIMserver by opensourceBIM.
the class GetNrPrimitivesDatabaseAction method execute.
@Override
public Long execute() throws UserException, BimserverLockConflictException, BimserverDatabaseException, ServerException {
Revision revision = getDatabaseSession().get(roid, OldQuery.getDefault());
PackageMetaData packageMetaData = bimServer.getMetaDataManager().getPackageMetaData(revision.getProject().getSchema());
if (packageMetaData == null) {
throw new UserException("Schema not fond");
}
try {
Query query = new Query("test", packageMetaData);
QueryPart queryPart = query.createQueryPart();
queryPart.addType(packageMetaData.getEClassIncludingDependencies("GeometryInfo"), true);
QueryObjectProvider queryObjectProvider = new QueryObjectProvider(getDatabaseSession(), bimServer, query, java.util.Collections.singleton(roid), packageMetaData);
HashMapVirtualObject next = queryObjectProvider.next();
long totalPrimitives = 0;
while (next != null) {
int nrPrimitives = (int) next.get("primitiveCount");
totalPrimitives += nrPrimitives;
next = queryObjectProvider.next();
}
return totalPrimitives;
} catch (QueryException e) {
e.printStackTrace();
} catch (JsonParseException e) {
e.printStackTrace();
} catch (JsonMappingException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
return null;
}
use of org.bimserver.database.queries.om.QueryPart in project BIMserver by opensourceBIM.
the class StreamingCheckinDatabaseAction method getByOid.
public HashMapVirtualObject getByOid(PackageMetaData packageMetaData, DatabaseSession databaseSession, long roid, long oid) throws JsonParseException, JsonMappingException, IOException, QueryException, BimserverDatabaseException {
Query query = new Query("test", packageMetaData);
QueryPart queryPart = query.createQueryPart();
queryPart.addOid(oid);
QueryObjectProvider queryObjectProvider = new QueryObjectProvider(databaseSession, bimServer, query, Collections.singleton(roid), packageMetaData);
HashMapVirtualObject first = queryObjectProvider.next();
return first;
}
use of org.bimserver.database.queries.om.QueryPart in project BIMserver by opensourceBIM.
the class StreamingCheckinDatabaseAction method fixInverses.
@SuppressWarnings("unchecked")
private void fixInverses(PackageMetaData packageMetaData, long newRoid) throws QueryException, JsonParseException, JsonMappingException, IOException, BimserverDatabaseException {
// TODO remove cache, this is essentially a big part of the model in memory again
Map<Long, HashMapVirtualObject> cache = new HashMap<Long, HashMapVirtualObject>();
Query query = new Query("Inverses fixer", packageMetaData);
int nrTypes = 0;
Set<EClass> uniqueTypes = new HashSet<>();
for (EClass eClass : deserializer.getSummaryMap().keySet()) {
if (packageMetaData.hasInverses(eClass)) {
QueryPart queryPart = query.createQueryPart();
queryPart.addType(eClass, true);
uniqueTypes.add(eClass);
nrTypes++;
for (EReference eReference : packageMetaData.getAllHasInverseReferences(eClass)) {
Include include = queryPart.createInclude();
include.addType(eClass, true);
include.addField(eReference.getName());
}
}
}
QueryObjectProvider queryObjectProvider = new QueryObjectProvider(getDatabaseSession(), bimServer, query, Collections.singleton(newRoid), packageMetaData);
HashMapVirtualObject next = queryObjectProvider.next();
EClass lastEClass = null;
int currentType = 0;
while (next != null) {
if (next.eClass() != lastEClass && uniqueTypes.contains(next.eClass()) && queryObjectProvider.getStackFrame() instanceof QueryTypeStackFrame) {
lastEClass = next.eClass();
currentType++;
setProgress("Generating inverses", (100 * currentType / nrTypes));
}
if (packageMetaData.hasInverses(next.eClass())) {
for (EReference eReference : packageMetaData.getAllHasInverseReferences(next.eClass())) {
Object reference = next.eGet(eReference);
if (reference != null) {
if (eReference.isMany()) {
List<Long> references = (List<Long>) reference;
for (Long refOid : references) {
fixInverses(packageMetaData, newRoid, cache, next, eReference, refOid);
}
} else {
fixInverses(packageMetaData, newRoid, cache, next, eReference, (Long) reference);
}
}
}
}
next = queryObjectProvider.next();
}
setProgress("Storing data", -1);
for (HashMapVirtualObject referencedObject : cache.values()) {
referencedObject.saveOverwrite();
}
}
use of org.bimserver.database.queries.om.QueryPart in project BIMserver by opensourceBIM.
the class AddReferenceChange method execute.
@Override
public void execute(Transaction transaction) throws UserException, BimserverLockConflictException, BimserverDatabaseException, IOException, QueryException {
PackageMetaData packageMetaData = transaction.getDatabaseSession().getMetaDataManager().getPackageMetaData(transaction.getProject().getSchema());
HashMapVirtualObject object = transaction.get(oid);
if (object == null) {
Query query = new Query(packageMetaData);
QueryPart queryPart = query.createQueryPart();
queryPart.addOid(oid);
QueryObjectProvider queryObjectProvider = new QueryObjectProvider(transaction.getDatabaseSession(), transaction.getBimServer(), query, Collections.singleton(transaction.getPreviousRevision().getOid()), packageMetaData);
object = queryObjectProvider.next();
transaction.updated(object);
}
EClass eClass = transaction.getDatabaseSession().getEClassForOid(oid);
if (!ChangeHelper.canBeChanged(eClass)) {
throw new UserException("Only objects from the following schemas are allowed to be changed: Ifc2x3tc1 and IFC4, this object (" + eClass.getName() + ") is from the \"" + eClass.getEPackage().getName() + "\" package");
}
if (object == null) {
throw new UserException("No object of type \"" + eClass.getName() + "\" with oid " + oid + " found in project with pid " + transaction.getProject().getId());
}
EReference eReference = packageMetaData.getEReference(eClass.getName(), referenceName);
if (eReference == null) {
throw new UserException("No reference with the name \"" + referenceName + "\" found in class \"" + eClass.getName() + "\"");
}
if (!eReference.isMany()) {
throw new UserException("Reference is not of type 'many'");
}
EClass eClassForOid = transaction.getDatabaseSession().getEClassForOid(referenceOid);
object.addReference(eReference, eClassForOid, referenceOid);
EReference inverseOrOpposite = packageMetaData.getInverseOrOpposite(eClassForOid, eReference);
if (inverseOrOpposite != null) {
HashMapVirtualObject referencedObject = transaction.get(referenceOid);
if (referencedObject == null) {
Query query = new Query(packageMetaData);
QueryPart queryPart = query.createQueryPart();
queryPart.addOid(referenceOid);
QueryObjectProvider queryObjectProvider = new QueryObjectProvider(transaction.getDatabaseSession(), transaction.getBimServer(), query, Collections.singleton(transaction.getPreviousRevision().getOid()), packageMetaData);
referencedObject = queryObjectProvider.next();
}
if (inverseOrOpposite.isMany()) {
referencedObject.addReference(inverseOrOpposite, eClassForOid, oid);
} else {
referencedObject.setReference(inverseOrOpposite, oid);
}
transaction.updated(referencedObject);
}
}
use of org.bimserver.database.queries.om.QueryPart in project BIMserver by opensourceBIM.
the class RemoveAllReferencesChange method execute.
@SuppressWarnings("rawtypes")
@Override
public void execute(Transaction transaction) throws UserException, BimserverLockConflictException, BimserverDatabaseException, IOException, QueryException {
PackageMetaData packageMetaData = transaction.getDatabaseSession().getMetaDataManager().getPackageMetaData(transaction.getProject().getSchema());
Query query = new Query(packageMetaData);
QueryPart queryPart = query.createQueryPart();
queryPart.addOid(oid);
HashMapVirtualObject object = transaction.get(oid);
if (object == null) {
QueryObjectProvider queryObjectProvider = new QueryObjectProvider(transaction.getDatabaseSession(), transaction.getBimServer(), query, Collections.singleton(transaction.getPreviousRevision().getOid()), packageMetaData);
object = queryObjectProvider.next();
transaction.updated(object);
}
EClass eClass = transaction.getDatabaseSession().getEClassForOid(oid);
if (!ChangeHelper.canBeChanged(eClass)) {
throw new UserException("Only objects from the following schemas are allowed to be changed: Ifc2x3tc1 and IFC4, this object (" + eClass.getName() + ") is from the \"" + eClass.getEPackage().getName() + "\" package");
}
if (object == null) {
throw new UserException("No object of type \"" + eClass.getName() + "\" with oid " + oid + " found in project with pid " + transaction.getProject().getId());
}
EReference eReference = packageMetaData.getEReference(eClass.getName(), referenceName);
if (eReference == null) {
throw new UserException("No reference with the name \"" + referenceName + "\" found in class \"" + eClass.getName() + "\"");
}
if (!eReference.isMany()) {
throw new UserException("Reference is not of type 'many'");
}
List list = (List) object.get(eReference.getName());
while (!list.isEmpty()) {
list.remove(0);
}
}
Aggregations