1 /*******************************************************************************
\r
2 * Copyright (c) 2007, 2010 Association for Decentralized Information Management
\r
3 * in Industry THTH ry.
\r
4 * All rights reserved. This program and the accompanying materials
\r
5 * are made available under the terms of the Eclipse Public License v1.0
\r
6 * which accompanies this distribution, and is available at
\r
7 * http://www.eclipse.org/legal/epl-v10.html
\r
10 * VTT Technical Research Centre of Finland - initial API and implementation
\r
11 *******************************************************************************/
\r
12 package org.simantics.mapping.constraint.instructions;
\r
14 import gnu.trove.set.hash.TIntHashSet;
\r
16 import java.util.Collection;
\r
17 import java.util.Iterator;
\r
19 import org.simantics.db.ReadGraph;
\r
20 import org.simantics.db.Resource;
\r
21 import org.simantics.db.exception.DatabaseException;
\r
23 public class TripletObjectQuery extends TripletInstruction {
\r
25 public TripletObjectQuery(int variable0, int variable1, int variable2) {
\r
26 super(variable0, variable1, variable2);
\r
30 public Object query(ReadGraph g, Object[] bindings) throws DatabaseException {
\r
31 Resource r0 = (Resource)bindings[variable0];
\r
32 Resource r1 = (Resource)bindings[variable1];
\r
33 Collection<Resource> result = g.getObjects(r0, r1);
\r
34 if(result.isEmpty())
\r
35 return IInstruction.FAILURE;
\r
36 Iterator<Resource> it = result.iterator();
\r
37 bindings[variable2] = it.next();
\r
44 @SuppressWarnings("unchecked")
\r
46 public Object next(ReadGraph g, Object[] bindings, Object continuation) {
\r
47 Iterator<Resource> it = (Iterator<Resource>)continuation;
\r
49 bindings[variable2] = it.next();
\r
56 return IInstruction.FAILURE;
\r
60 public void collectVariables(TIntHashSet reads, TIntHashSet writes) {
\r
61 super.collectVariables(reads, writes);
\r
62 writes.add(variable2);
\r