/******************************************************************************* * 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; } }