]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.db.layer0/src/org/simantics/db/layer0/adapter/impl/TGRemover.java
aae4b581bf5242fa215ac75ddcb52dfdbc4e176b
[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         ModelTransferableGraphSource source = graph.syncRequest(new ModelTransferableGraphSourceRequest(conf));
47         final SerialisationSupport ss = graph.getService(SerialisationSupport.class);
48         
49         try {
50                         source.forResourceStatements(graph, new TransferableGraphSourceProcedure<int[]>() {
51                                 
52                                 @Override
53                                 public void execute(int[] value) throws Exception {
54                                         Resource s = ss.getResource(value[0]);
55                                         Resource p = ss.getResource(value[1]);
56                                         Resource i = null;
57                                         if(value[2] != -1) i = ss.getResource(value[2]);
58                                         Resource o = ss.getResource(value[3]);
59                                         
60 //                                      System.err.println("s=" + s + " p=" + graph.getPossibleURI(p) + " o=" + o + " p:" + p + " i:" + i);
61                                         
62                                         graph.deny(s,p,i,o);
63                                 }
64                                 
65                         });
66                         
67                         source.forValueResources(graph, new TransferableGraphSourceProcedure<int[]>() {
68                                 
69                                 @Override
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);
73                                         graph.denyValue(s);
74                                 }
75                                 
76                         });
77                         
78                         source.closeStreams();
79                         
80                 } catch (Exception e) {
81                         throw new DatabaseException(e);
82                 }
83         
84     }
85
86 }