]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.db.layer0/src/org/simantics/db/layer0/adapter/impl/TGRemover.java
88594883488f71059dd6ef128b53e9d5176ce85c
[simantics/platform.git] / bundles / org.simantics.db.layer0 / src / org / simantics / db / layer0 / adapter / impl / TGRemover.java
1 /*******************************************************************************
2  * Copyright (c) 2007, 2010 Association for Decentralized Information Management
3  * in Industry THTH ry.
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
8  *
9  * Contributors:
10  *     VTT Technical Research Centre of Finland - initial API and implementation
11  *******************************************************************************/
12 package org.simantics.db.layer0.adapter.impl;
13
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;
23
24 /**
25  * @author Tuukka Lehtonen
26  */
27 public class TGRemover extends AbstractRemover {
28
29     @SuppressWarnings("unused")
30     private IProgressMonitor monitor;
31
32     public TGRemover(Resource resource) {
33         super(resource);
34     }
35
36     public TGRemover(IProgressMonitor monitor, Resource resource) {
37         super(resource);
38         this.monitor = monitor;
39     }
40
41     @Override
42     public void remove(final WriteGraph graph) throws DatabaseException {
43         
44         TransferableGraphConfiguration2 conf = new TransferableGraphConfiguration2(graph, resource);
45         conf.values = false;
46         final SerialisationSupport ss = graph.getService(SerialisationSupport.class);
47         
48         try (ModelTransferableGraphSource source = graph.syncRequest(new ModelTransferableGraphSourceRequest(conf))) {
49                         source.forResourceStatements(graph, new TransferableGraphSourceProcedure<int[]>() {
50                                 
51                                 @Override
52                                 public void execute(int[] value) throws Exception {
53                                         Resource s = ss.getResource(value[0]);
54                                         Resource p = ss.getResource(value[1]);
55                                         Resource i = null;
56                                         if(value[2] != -1) i = ss.getResource(value[2]);
57                                         Resource o = ss.getResource(value[3]);
58                                         
59 //                                      System.err.println("s=" + s + " p=" + graph.getPossibleURI(p) + " o=" + o + " p:" + p + " i:" + i);
60                                         
61                                         graph.deny(s,p,i,o);
62                                 }
63                                 
64                         });
65                         
66                         source.forValueResources(graph, new TransferableGraphSourceProcedure<int[]>() {
67                                 
68                                 @Override
69                                 public void execute(int[] value) throws Exception {
70                                         Resource s = ss.getResource(value[0]);
71 //                                      System.err.println("s=" + s + " p=" + graph.getPossibleURI(p) + " o=" + o + " " + i);
72                                         graph.denyValue(s);
73                                 }
74                                 
75                         });
76                         
77                 } catch (Exception e) {
78                         throw new DatabaseException(e);
79                 }
80         
81     }
82
83 }