1 package org.simantics.interop.update.model;
3 import java.util.Collection;
5 import org.simantics.db.Resource;
6 import org.simantics.db.Statement;
7 import org.simantics.db.WriteGraph;
8 import org.simantics.db.exception.DatabaseException;
9 import org.simantics.interop.test.GraphChanges;
10 import org.simantics.layer0.Layer0;
13 * Simple update operation, where
14 * addition is based on copying L0.InstanceOf and L0.HasProperty relations.
20 public class SimpleObjectUpdateOp extends AddDeleteUpdateOp {
23 protected Resource copyObj;
25 public SimpleObjectUpdateOp(Statement r, boolean add, GraphChanges changes) {
32 protected void _apply(WriteGraph g) throws DatabaseException {
34 Resource parent = null;
35 if (getChanges().getComparable().containsRight(r.getSubject()))
36 parent = getChanges().getComparable().getLeft(r.getSubject());
38 Collection<UpdateOp> parentOps = getParentOps();
39 if (parentOps.size() != 1)
40 throw new RuntimeException("Parent not found.");
41 parent = parentOps.iterator().next().getCreatedResource();
44 throw new RuntimeException("Parent not found.");
46 Layer0 L0 = Layer0.getInstance(g);
48 Resource sourceObj = r.getObject();
50 copyObj = g.newResource();
51 copyTypes(g, sourceObj, copyObj);
52 copyProperties(g, sourceObj, copyObj);
53 g.claim(parent, r.getPredicate(), copyObj);
57 Resource sourceObj= r.getObject();
65 public Statement getStatement() {
70 public Resource getResource() {
75 public Resource getCreatedResource() {
80 public String toString() {
81 return super.toString() + " " + r.getSubject() + " " + r.getPredicate() + " " + r.getObject();