-/*******************************************************************************\r
- * Copyright (c) 2007, 2010 Association for Decentralized Information Management\r
- * in Industry THTH ry.\r
- * All rights reserved. This program and the accompanying materials\r
- * are made available under the terms of the Eclipse Public License v1.0\r
- * which accompanies this distribution, and is available at\r
- * http://www.eclipse.org/legal/epl-v10.html\r
- *\r
- * Contributors:\r
- * VTT Technical Research Centre of Finland - initial API and implementation\r
- *******************************************************************************/\r
-package org.simantics.mapping.constraint.instructions;\r
-\r
-import org.simantics.db.ReadGraph;\r
-import org.simantics.db.Resource;\r
-import org.simantics.db.WriteGraph;\r
-import org.simantics.db.common.utils.NameUtils;\r
-import org.simantics.db.exception.DatabaseException;\r
-import org.simantics.mapping.IContextualModification;\r
-\r
-public class TripletInstruction extends Instruction3 {\r
- \r
- public TripletInstruction(int variable0, int variable1, int variable2) {\r
- super(variable0, variable1, variable2);\r
- }\r
-\r
- @Override\r
- public IContextualModification claim(ReadGraph g, Object[] bindings) throws DatabaseException {\r
- Resource r0 = (Resource)bindings[variable0];\r
- Resource r1 = (Resource)bindings[variable1];\r
- Resource r2 = (Resource)bindings[variable2];\r
-// ITask task = ThreadLogger.getInstance().begin("g");\r
- if(!g.hasStatement(r0, r1, r2)) {\r
-// task.finish(); \r
- return new IContextualModification() {\r
-\r
- @Override\r
- public void perform(WriteGraph g, Object[] bindings) throws DatabaseException {\r
- Resource r0 = (Resource)bindings[variable0];\r
- Resource r1 = (Resource)bindings[variable1];\r
- Resource r2 = (Resource)bindings[variable2];\r
- if(DEBUG_MODI)\r
- System.out.println("claim(" +\r
- NameUtils.getSafeName(g, r0) + ", " +\r
- NameUtils.getSafeName(g, r1) + ", " +\r
- NameUtils.getSafeName(g, r2) + ")"\r
- );\r
- if(!DISABLE_MODI)\r
- g.claim(r0, r1, r2);\r
- }\r
- \r
- };\r
- }\r
-// task.finish();\r
- return null;\r
- }\r
- \r
- @Override\r
- public void doClaim(WriteGraph g, Object[] bindings) throws DatabaseException {\r
- Resource r0 = (Resource)bindings[variable0];\r
- Resource r1 = (Resource)bindings[variable1];\r
- Resource r2 = (Resource)bindings[variable2];\r
- if(DEBUG) {\r
- System.out.println("@ claim(" +\r
- NameUtils.getSafeName(g, r0) + ", " +\r
- NameUtils.getSafeName(g, r1) + ", " +\r
- NameUtils.getSafeName(g, r2) + ")");\r
- }\r
- if(DEBUG_MODI)\r
- System.out.println("claim(" +\r
- NameUtils.getSafeName(g, r0) + ", " +\r
- NameUtils.getSafeName(g, r1) + ", " +\r
- NameUtils.getSafeName(g, r2) + ")"\r
- );\r
-// ITask task = ThreadLogger.getInstance().begin("g"); \r
- if(!DISABLE_MODI)\r
- g.claim(r0, r1, r2);\r
-// task.finish();\r
- }\r
-\r
- @Override\r
- public IContextualModification deny(ReadGraph g, Object[] bindings) throws DatabaseException {\r
- Resource r0 = (Resource)bindings[variable0];\r
- Resource r1 = (Resource)bindings[variable1];\r
- Resource r2 = (Resource)bindings[variable2];\r
- if(g.hasStatement(r0, r1, r2))\r
- return new IContextualModification() {\r
-\r
- @Override\r
- public void perform(WriteGraph g, Object[] bindings) throws DatabaseException {\r
- Resource r0 = (Resource)bindings[variable0];\r
- Resource r1 = (Resource)bindings[variable1];\r
- Resource r2 = (Resource)bindings[variable2];\r
- if(DEBUG_MODI)\r
- System.out.println("deny(" +\r
- NameUtils.getSafeName(g, r0) + ", " +\r
- NameUtils.getSafeName(g, r1) + ", " +\r
- NameUtils.getSafeName(g, r2) + ")"\r
- );\r
- if(!DISABLE_MODI)\r
- g.denyStatement(r0, r1, r2);\r
- }\r
- \r
- };\r
- return null;\r
- }\r
- \r
- @Override\r
- public void doDeny(WriteGraph g, Object[] bindings) throws DatabaseException {\r
- Resource r0 = (Resource)bindings[variable0];\r
- Resource r1 = (Resource)bindings[variable1];\r
- Resource r2 = (Resource)bindings[variable2];\r
- if(DEBUG) {\r
- System.out.println("deny(" +\r
- NameUtils.getSafeName(g, r0) + ", " +\r
- NameUtils.getSafeName(g, r1) + ", " +\r
- NameUtils.getSafeName(g, r2) + ")");\r
- }\r
- if(DEBUG_MODI)\r
- System.out.println("deny(" +\r
- NameUtils.getSafeName(g, r0) + ", " +\r
- NameUtils.getSafeName(g, r1) + ", " +\r
- NameUtils.getSafeName(g, r2) + ")"\r
- );\r
- if(!DISABLE_MODI)\r
- g.denyStatement(r0, r1, r2); \r
- }\r
-\r
- @Override\r
- public Object next(ReadGraph g, Object[] bindings, Object continuation) throws DatabaseException {\r
- return IInstruction.FAILURE;\r
- }\r
-\r
- @Override\r
- public Object query(ReadGraph g, Object[] bindings) throws DatabaseException {\r
- Resource r0 = (Resource)bindings[variable0];\r
- Resource r1 = (Resource)bindings[variable1];\r
- Resource r2 = (Resource)bindings[variable2];\r
- if(DEBUG) {\r
- System.out.print("hasStatement(" +\r
- NameUtils.getSafeName(g, r0) + ", " +\r
- NameUtils.getSafeName(g, r1) + ", " +\r
- NameUtils.getSafeName(g, r2) + ")");\r
- }\r
- if(g.hasStatement(r0, r1, r2)) {\r
- if(DEBUG)\r
- System.out.println(" -> true");\r
- return null;\r
- }\r
- else {\r
- if(DEBUG)\r
- System.out.println(" -> false");\r
- return IInstruction.FAILURE;\r
- }\r
- }\r
-\r
- @Override\r
- public void toString(StringBuilder b, int indent) {\r
- b.append('<');\r
- b.append(variable0);\r
- b.append(',');\r
- b.append(variable1);\r
- b.append(',');\r
- b.append(variable2);\r
- b.append('>');\r
- }\r
-}\r
+/*******************************************************************************
+ * 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.mapping.constraint.instructions;
+
+import org.simantics.db.ReadGraph;
+import org.simantics.db.Resource;
+import org.simantics.db.WriteGraph;
+import org.simantics.db.common.utils.NameUtils;
+import org.simantics.db.exception.DatabaseException;
+import org.simantics.mapping.IContextualModification;
+
+public class TripletInstruction extends Instruction3 {
+
+ public TripletInstruction(int variable0, int variable1, int variable2) {
+ super(variable0, variable1, variable2);
+ }
+
+ @Override
+ public IContextualModification claim(ReadGraph g, Object[] bindings) throws DatabaseException {
+ Resource r0 = (Resource)bindings[variable0];
+ Resource r1 = (Resource)bindings[variable1];
+ Resource r2 = (Resource)bindings[variable2];
+// ITask task = ThreadLogger.getInstance().begin("g");
+ if(!g.hasStatement(r0, r1, r2)) {
+// task.finish();
+ return new IContextualModification() {
+
+ @Override
+ public void perform(WriteGraph g, Object[] bindings) throws DatabaseException {
+ Resource r0 = (Resource)bindings[variable0];
+ Resource r1 = (Resource)bindings[variable1];
+ Resource r2 = (Resource)bindings[variable2];
+ if(DEBUG_MODI)
+ System.out.println("claim(" +
+ NameUtils.getSafeName(g, r0) + ", " +
+ NameUtils.getSafeName(g, r1) + ", " +
+ NameUtils.getSafeName(g, r2) + ")"
+ );
+ if(!DISABLE_MODI)
+ g.claim(r0, r1, r2);
+ }
+
+ };
+ }
+// task.finish();
+ return null;
+ }
+
+ @Override
+ public void doClaim(WriteGraph g, Object[] bindings) throws DatabaseException {
+ Resource r0 = (Resource)bindings[variable0];
+ Resource r1 = (Resource)bindings[variable1];
+ Resource r2 = (Resource)bindings[variable2];
+ if(DEBUG) {
+ System.out.println("@ claim(" +
+ NameUtils.getSafeName(g, r0) + ", " +
+ NameUtils.getSafeName(g, r1) + ", " +
+ NameUtils.getSafeName(g, r2) + ")");
+ }
+ if(DEBUG_MODI)
+ System.out.println("claim(" +
+ NameUtils.getSafeName(g, r0) + ", " +
+ NameUtils.getSafeName(g, r1) + ", " +
+ NameUtils.getSafeName(g, r2) + ")"
+ );
+// ITask task = ThreadLogger.getInstance().begin("g");
+ if(!DISABLE_MODI)
+ g.claim(r0, r1, r2);
+// task.finish();
+ }
+
+ @Override
+ public IContextualModification deny(ReadGraph g, Object[] bindings) throws DatabaseException {
+ Resource r0 = (Resource)bindings[variable0];
+ Resource r1 = (Resource)bindings[variable1];
+ Resource r2 = (Resource)bindings[variable2];
+ if(g.hasStatement(r0, r1, r2))
+ return new IContextualModification() {
+
+ @Override
+ public void perform(WriteGraph g, Object[] bindings) throws DatabaseException {
+ Resource r0 = (Resource)bindings[variable0];
+ Resource r1 = (Resource)bindings[variable1];
+ Resource r2 = (Resource)bindings[variable2];
+ if(DEBUG_MODI)
+ System.out.println("deny(" +
+ NameUtils.getSafeName(g, r0) + ", " +
+ NameUtils.getSafeName(g, r1) + ", " +
+ NameUtils.getSafeName(g, r2) + ")"
+ );
+ if(!DISABLE_MODI)
+ g.denyStatement(r0, r1, r2);
+ }
+
+ };
+ return null;
+ }
+
+ @Override
+ public void doDeny(WriteGraph g, Object[] bindings) throws DatabaseException {
+ Resource r0 = (Resource)bindings[variable0];
+ Resource r1 = (Resource)bindings[variable1];
+ Resource r2 = (Resource)bindings[variable2];
+ if(DEBUG) {
+ System.out.println("deny(" +
+ NameUtils.getSafeName(g, r0) + ", " +
+ NameUtils.getSafeName(g, r1) + ", " +
+ NameUtils.getSafeName(g, r2) + ")");
+ }
+ if(DEBUG_MODI)
+ System.out.println("deny(" +
+ NameUtils.getSafeName(g, r0) + ", " +
+ NameUtils.getSafeName(g, r1) + ", " +
+ NameUtils.getSafeName(g, r2) + ")"
+ );
+ if(!DISABLE_MODI)
+ g.denyStatement(r0, r1, r2);
+ }
+
+ @Override
+ public Object next(ReadGraph g, Object[] bindings, Object continuation) throws DatabaseException {
+ return IInstruction.FAILURE;
+ }
+
+ @Override
+ public Object query(ReadGraph g, Object[] bindings) throws DatabaseException {
+ Resource r0 = (Resource)bindings[variable0];
+ Resource r1 = (Resource)bindings[variable1];
+ Resource r2 = (Resource)bindings[variable2];
+ if(DEBUG) {
+ System.out.print("hasStatement(" +
+ NameUtils.getSafeName(g, r0) + ", " +
+ NameUtils.getSafeName(g, r1) + ", " +
+ NameUtils.getSafeName(g, r2) + ")");
+ }
+ if(g.hasStatement(r0, r1, r2)) {
+ if(DEBUG)
+ System.out.println(" -> true");
+ return null;
+ }
+ else {
+ if(DEBUG)
+ System.out.println(" -> false");
+ return IInstruction.FAILURE;
+ }
+ }
+
+ @Override
+ public void toString(StringBuilder b, int indent) {
+ b.append('<');
+ b.append(variable0);
+ b.append(',');
+ b.append(variable1);
+ b.append(',');
+ b.append(variable2);
+ b.append('>');
+ }
+}