1 /*******************************************************************************
2 * Copyright (c) 2007, 2010 Association for Decentralized Information Management
4 * All rights reserved. This program and the accompanying materials
5 * are made available under the terms of the Eclipse Public License v1.0
6 * which accompanies this distribution, and is available at
7 * http://www.eclipse.org/legal/epl-v10.html
10 * VTT Technical Research Centre of Finland - initial API and implementation
11 *******************************************************************************/
12 package org.simantics.db.common.primitiverequest;
14 import java.util.Collection;
16 import org.simantics.db.AsyncReadGraph;
17 import org.simantics.db.ReadGraph;
18 import org.simantics.db.Resource;
19 import org.simantics.db.common.request.ResourceRead2;
20 import org.simantics.db.exception.DatabaseException;
21 import org.simantics.db.procedure.AsyncMultiProcedure;
22 import org.simantics.db.service.CollectionSupport;
23 import org.simantics.utils.DataContainer;
25 final public class ForEachAssertedObject extends ResourceRead2<Collection<Resource>> {
27 public ForEachAssertedObject(Resource subject, Resource relation) {
28 super(subject, relation);
32 public Collection<Resource> perform(ReadGraph graph) throws DatabaseException {
33 CollectionSupport cs = graph.getService(CollectionSupport.class);
34 Collection<Resource> result = cs.createSet();
35 DataContainer<Throwable> throwable = new DataContainer<Throwable>(null);
36 graph.forEachAssertedObject(resource, resource2, new AsyncMultiProcedure<Resource>() {
39 public void finished(AsyncReadGraph graph) {
43 public void execute(AsyncReadGraph graph, Resource r) {
48 public void exception(AsyncReadGraph graph, Throwable t) {
52 Throwable t = throwable.get();
54 if(t instanceof DatabaseException)
55 throw (DatabaseException)t;
56 else throw new DatabaseException(t);