1 /*******************************************************************************
\r
2 * Copyright (c) 2007, 2010 Association for Decentralized Information Management
\r
3 * in Industry THTH ry.
\r
4 * All rights reserved. This program and the accompanying materials
\r
5 * are made available under the terms of the Eclipse Public License v1.0
\r
6 * which accompanies this distribution, and is available at
\r
7 * http://www.eclipse.org/legal/epl-v10.html
\r
10 * VTT Technical Research Centre of Finland - initial API and implementation
\r
11 *******************************************************************************/
\r
12 package org.simantics.db.layer0.adapter.impl;
\r
14 import org.eclipse.core.runtime.IProgressMonitor;
\r
15 import org.simantics.db.Resource;
\r
16 import org.simantics.db.WriteGraph;
\r
17 import org.simantics.db.exception.DatabaseException;
\r
18 import org.simantics.db.layer0.util.ModelTransferableGraphSource;
\r
19 import org.simantics.db.layer0.util.ModelTransferableGraphSourceRequest;
\r
20 import org.simantics.db.layer0.util.TransferableGraphConfiguration2;
\r
21 import org.simantics.db.service.SerialisationSupport;
\r
22 import org.simantics.graph.db.TransferableGraphSource.TransferableGraphSourceProcedure;
\r
25 * @author Tuukka Lehtonen
\r
27 public class TGRemover extends AbstractRemover {
\r
29 @SuppressWarnings("unused")
\r
30 private IProgressMonitor monitor;
\r
32 public TGRemover(Resource resource) {
\r
36 public TGRemover(IProgressMonitor monitor, Resource resource) {
\r
38 this.monitor = monitor;
\r
42 public void remove(final WriteGraph graph) throws DatabaseException {
\r
44 TransferableGraphConfiguration2 conf = new TransferableGraphConfiguration2(graph, resource);
\r
45 conf.values = false;
\r
46 ModelTransferableGraphSource source = graph.syncRequest(new ModelTransferableGraphSourceRequest(conf));
\r
47 final SerialisationSupport ss = graph.getService(SerialisationSupport.class);
\r
50 source.forResourceStatements(graph, new TransferableGraphSourceProcedure<int[]>() {
\r
53 public void execute(int[] value) throws Exception {
\r
54 Resource s = ss.getResource(value[0]);
\r
55 Resource p = ss.getResource(value[1]);
\r
57 if(value[2] != -1) i = ss.getResource(value[2]);
\r
58 Resource o = ss.getResource(value[3]);
\r
60 // System.err.println("s=" + s + " p=" + graph.getPossibleURI(p) + " o=" + o + " p:" + p + " i:" + i);
\r
62 graph.deny(s,p,i,o);
\r
67 source.forValueResources(graph, new TransferableGraphSourceProcedure<int[]>() {
\r
70 public void execute(int[] value) throws Exception {
\r
71 Resource s = ss.getResource(value[0]);
\r
72 // System.err.println("s=" + s + " p=" + graph.getPossibleURI(p) + " o=" + o + " " + i);
\r
78 source.closeStreams();
\r
80 } catch (Exception e) {
\r
81 throw new DatabaseException(e);
\r