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.db.layer0.adapter.impl;
14 import org.eclipse.core.runtime.IProgressMonitor;
15 import org.simantics.db.Resource;
16 import org.simantics.db.WriteGraph;
17 import org.simantics.db.exception.DatabaseException;
18 import org.simantics.db.layer0.util.ModelTransferableGraphSource;
19 import org.simantics.db.layer0.util.ModelTransferableGraphSourceRequest;
20 import org.simantics.db.layer0.util.TransferableGraphConfiguration2;
21 import org.simantics.db.service.SerialisationSupport;
22 import org.simantics.graph.db.TransferableGraphSource.TransferableGraphSourceProcedure;
25 * @author Tuukka Lehtonen
27 public class TGRemover extends AbstractRemover {
29 @SuppressWarnings("unused")
30 private IProgressMonitor monitor;
32 public TGRemover(Resource resource) {
36 public TGRemover(IProgressMonitor monitor, Resource resource) {
38 this.monitor = monitor;
42 public void remove(final WriteGraph graph) throws DatabaseException {
44 TransferableGraphConfiguration2 conf = new TransferableGraphConfiguration2(graph, resource);
46 ModelTransferableGraphSource source = graph.syncRequest(new ModelTransferableGraphSourceRequest(conf));
47 final SerialisationSupport ss = graph.getService(SerialisationSupport.class);
50 source.forResourceStatements(graph, new TransferableGraphSourceProcedure<int[]>() {
53 public void execute(int[] value) throws Exception {
54 Resource s = ss.getResource(value[0]);
55 Resource p = ss.getResource(value[1]);
57 if(value[2] != -1) i = ss.getResource(value[2]);
58 Resource o = ss.getResource(value[3]);
60 // System.err.println("s=" + s + " p=" + graph.getPossibleURI(p) + " o=" + o + " p:" + p + " i:" + i);
67 source.forValueResources(graph, new TransferableGraphSourceProcedure<int[]>() {
70 public void execute(int[] value) throws Exception {
71 Resource s = ss.getResource(value[0]);
72 // System.err.println("s=" + s + " p=" + graph.getPossibleURI(p) + " o=" + o + " " + i);
78 source.closeStreams();
80 } catch (Exception e) {
81 throw new DatabaseException(e);