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.layer0.utils.writer;
14 import org.simantics.db.Resource;
15 import org.simantics.db.WriteGraph;
16 import org.simantics.db.exception.DatabaseException;
17 import org.simantics.layer0.Layer0;
19 public class DirectGraphWriter extends GraphWriterPartial {
24 public DirectGraphWriter(WriteGraph graph) {
31 public GraphWriter create() throws DatabaseException {
32 current = wg.newResource();
37 public GraphWriter create(Resource type) throws DatabaseException {
38 current = wg.newResource();
39 Layer0 b = Layer0.getInstance(wg);
40 wg.claim(current, b.InstanceOf, null, type);
45 public Resource get() {
50 public GraphWriter handle(Resource s) {
56 public GraphWriter let(Resource p, Resource o) throws DatabaseException {
58 throw new RuntimeException("Should call create or handle before let.");
59 wg.claim(current, p, o);
64 public GraphWriter let(Resource p, Object value, Resource dataType) throws DatabaseException {
66 throw new RuntimeException("Should call create or handle before let.");
67 Resource temp = wg.newResource();
68 wg.claim(temp, l0.InstanceOf, null, dataType);
69 wg.claimValue(temp, value);
70 wg.claim(current, p, temp);
75 public GraphWriter flush() throws DatabaseException {
81 public GraphWriter createLiteral(Object value, Resource dataType) throws DatabaseException {
82 current = wg.newResource();
83 wg.claim(current, l0.InstanceOf, null, dataType);
84 wg.claimValue(current, value);
89 public GraphWriter createInverse(Resource r) throws DatabaseException {
90 current = wg.newResource();
91 wg.claim(r, l0.InverseOf, current);