-/*******************************************************************************\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.layer0.utils.writer;\r
-\r
-import org.simantics.db.Resource;\r
-import org.simantics.db.WriteGraph;\r
-import org.simantics.db.exception.DatabaseException;\r
-import org.simantics.layer0.Layer0;\r
-\r
-public class DirectGraphWriter extends GraphWriterPartial {\r
-\r
- Resource current;\r
- WriteGraph wg;\r
- \r
- public DirectGraphWriter(WriteGraph graph) {\r
- super(graph);\r
- this.wg = graph;\r
- this.current = null;\r
- }\r
-\r
- @Override\r
- public GraphWriter create() throws DatabaseException {\r
- current = wg.newResource();\r
- return this;\r
- }\r
-\r
- @Override\r
- public GraphWriter create(Resource type) throws DatabaseException {\r
- current = wg.newResource();\r
- Layer0 b = Layer0.getInstance(wg);\r
- wg.claim(current, b.InstanceOf, null, type);\r
- return this;\r
- }\r
-\r
- @Override\r
- public Resource get() {\r
- return current;\r
- }\r
-\r
- @Override\r
- public GraphWriter handle(Resource s) {\r
- current = s;\r
- return this;\r
- }\r
-\r
- @Override\r
- public GraphWriter let(Resource p, Resource o) throws DatabaseException {\r
- if(current == null)\r
- throw new RuntimeException("Should call create or handle before let.");\r
- wg.claim(current, p, o);\r
- return this;\r
- }\r
-\r
- @Override\r
- public GraphWriter let(Resource p, Object value, Resource dataType) throws DatabaseException {\r
- if(current == null)\r
- throw new RuntimeException("Should call create or handle before let.");\r
- Resource temp = wg.newResource(); \r
- wg.claim(temp, l0.InstanceOf, null, dataType);\r
- wg.claimValue(temp, value);\r
- wg.claim(current, p, temp);\r
- return this;\r
- }\r
-\r
- @Override\r
- public GraphWriter flush() throws DatabaseException {\r
- wg.flushCluster();\r
- return this;\r
- }\r
- \r
- @Override\r
- public GraphWriter createLiteral(Object value, Resource dataType) throws DatabaseException {\r
- current = wg.newResource();\r
- wg.claim(current, l0.InstanceOf, null, dataType);\r
- wg.claimValue(current, value);\r
- return this;\r
- }\r
-\r
- @Override\r
- public GraphWriter createInverse(Resource r) throws DatabaseException {\r
- current = wg.newResource();\r
- wg.claim(r, l0.InverseOf, current);\r
- return this;\r
- }\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.layer0.utils.writer;
+
+import org.simantics.db.Resource;
+import org.simantics.db.WriteGraph;
+import org.simantics.db.exception.DatabaseException;
+import org.simantics.layer0.Layer0;
+
+public class DirectGraphWriter extends GraphWriterPartial {
+
+ Resource current;
+ WriteGraph wg;
+
+ public DirectGraphWriter(WriteGraph graph) {
+ super(graph);
+ this.wg = graph;
+ this.current = null;
+ }
+
+ @Override
+ public GraphWriter create() throws DatabaseException {
+ current = wg.newResource();
+ return this;
+ }
+
+ @Override
+ public GraphWriter create(Resource type) throws DatabaseException {
+ current = wg.newResource();
+ Layer0 b = Layer0.getInstance(wg);
+ wg.claim(current, b.InstanceOf, null, type);
+ return this;
+ }
+
+ @Override
+ public Resource get() {
+ return current;
+ }
+
+ @Override
+ public GraphWriter handle(Resource s) {
+ current = s;
+ return this;
+ }
+
+ @Override
+ public GraphWriter let(Resource p, Resource o) throws DatabaseException {
+ if(current == null)
+ throw new RuntimeException("Should call create or handle before let.");
+ wg.claim(current, p, o);
+ return this;
+ }
+
+ @Override
+ public GraphWriter let(Resource p, Object value, Resource dataType) throws DatabaseException {
+ if(current == null)
+ throw new RuntimeException("Should call create or handle before let.");
+ Resource temp = wg.newResource();
+ wg.claim(temp, l0.InstanceOf, null, dataType);
+ wg.claimValue(temp, value);
+ wg.claim(current, p, temp);
+ return this;
+ }
+
+ @Override
+ public GraphWriter flush() throws DatabaseException {
+ wg.flushCluster();
+ return this;
+ }
+
+ @Override
+ public GraphWriter createLiteral(Object value, Resource dataType) throws DatabaseException {
+ current = wg.newResource();
+ wg.claim(current, l0.InstanceOf, null, dataType);
+ wg.claimValue(current, value);
+ return this;
+ }
+
+ @Override
+ public GraphWriter createInverse(Resource r) throws DatabaseException {
+ current = wg.newResource();
+ wg.claim(r, l0.InverseOf, current);
+ return this;
+ }
+
+}