X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=blobdiff_plain;f=bundles%2Forg.simantics.db.common%2Fsrc%2Forg%2Fsimantics%2Fdb%2Fcommon%2Fprimitiverequest%2FForEachAssertedObject.java;h=541aee94e10d31c50480f7a2508a3f432face183;hb=1e957fc9da518f3bef8a2c19cad72772087e1b6a;hp=1cef1de4586757d3632709ac7187d41065665dd5;hpb=969bd23cab98a79ca9101af33334000879fb60c5;p=simantics%2Fplatform.git diff --git a/bundles/org.simantics.db.common/src/org/simantics/db/common/primitiverequest/ForEachAssertedObject.java b/bundles/org.simantics.db.common/src/org/simantics/db/common/primitiverequest/ForEachAssertedObject.java index 1cef1de45..541aee94e 100644 --- a/bundles/org.simantics.db.common/src/org/simantics/db/common/primitiverequest/ForEachAssertedObject.java +++ b/bundles/org.simantics.db.common/src/org/simantics/db/common/primitiverequest/ForEachAssertedObject.java @@ -1,30 +1,60 @@ -/******************************************************************************* - * Copyright (c) 2007, 2010 Association for Decentralized Information Management - * in Industry THTH ry. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * VTT Technical Research Centre of Finland - initial API and implementation - *******************************************************************************/ -package org.simantics.db.common.primitiverequest; - -import org.simantics.db.AsyncReadGraph; -import org.simantics.db.Resource; -import org.simantics.db.common.request.ResourceAsyncMultiRead2; -import org.simantics.db.procedure.AsyncMultiProcedure; - -final public class ForEachAssertedObject extends ResourceAsyncMultiRead2 { - - public ForEachAssertedObject(Resource subject, Resource relation) { - super(subject, relation); - } - - @Override - public void perform(AsyncReadGraph graph, AsyncMultiProcedure procedure) { - graph.forEachAssertedObject(resource, resource2, procedure); - } - -} +/******************************************************************************* + * Copyright (c) 2007, 2010 Association for Decentralized Information Management + * in Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.db.common.primitiverequest; + +import java.util.Collection; + +import org.simantics.db.AsyncReadGraph; +import org.simantics.db.ReadGraph; +import org.simantics.db.Resource; +import org.simantics.db.common.request.ResourceRead2; +import org.simantics.db.exception.DatabaseException; +import org.simantics.db.procedure.AsyncMultiProcedure; +import org.simantics.db.service.CollectionSupport; +import org.simantics.utils.DataContainer; + +final public class ForEachAssertedObject extends ResourceRead2> { + + public ForEachAssertedObject(Resource subject, Resource relation) { + super(subject, relation); + } + + @Override + public Collection perform(ReadGraph graph) throws DatabaseException { + CollectionSupport cs = graph.getService(CollectionSupport.class); + Collection result = cs.createSet(); + DataContainer throwable = new DataContainer(null); + graph.forEachAssertedObject(resource, resource2, new AsyncMultiProcedure() { + + @Override + public void finished(AsyncReadGraph graph) { + } + + @Override + public void execute(AsyncReadGraph graph, Resource r) { + result.add(r); + } + + @Override + public void exception(AsyncReadGraph graph, Throwable t) { + throwable.set(t); + } + }); + Throwable t = throwable.get(); + if(t != null) + if(t instanceof DatabaseException) + throw (DatabaseException)t; + else throw new DatabaseException(t); + return result; + } + +}