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.mapping.constraint.instructions;
14 import gnu.trove.set.hash.TIntHashSet;
16 import java.util.Collection;
17 import java.util.Iterator;
19 import org.simantics.db.ReadGraph;
20 import org.simantics.db.Resource;
21 import org.simantics.db.common.utils.NameUtils;
22 import org.simantics.db.exception.DatabaseException;
23 import org.simantics.layer0.utils.binaryPredicates.IBinaryPredicate;
25 public class BinaryPredicateObjectQuery extends BinaryPredicateInstruction {
27 public BinaryPredicateObjectQuery(int variable0, int variable1,
28 IBinaryPredicate predicate) {
29 super(variable0, variable1, predicate);
33 public Object query(ReadGraph g, Object[] bindings) throws DatabaseException {
34 Resource r0 = (Resource)bindings[variable0];
35 // ITask task = ThreadLogger.getInstance().begin("g");
36 Collection<Resource> result = predicate.getObjects(g, r0);
38 System.out.println("getObjects(" +
39 NameUtils.getSafeName(g, r0) + ", " +
40 predicate.toString(g) + ") returned " + result.size() + " objects"
45 return IInstruction.FAILURE;
46 Iterator<Resource> it = result.iterator();
47 bindings[variable1] = it.next();
54 @SuppressWarnings("unchecked")
56 public Object next(ReadGraph g, Object[] bindings, Object continuation) {
57 Iterator<Resource> it = (Iterator<Resource>)continuation;
59 bindings[variable1] = it.next();
66 return IInstruction.FAILURE;
70 public void collectVariables(TIntHashSet reads, TIntHashSet writes) {
71 super.collectVariables(reads, writes);
72 writes.add(variable1);