]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.db.layer0/src/org/simantics/db/layer0/adapter/impl/TGRemover.java
Migrated source code from Simantics SVN
[simantics/platform.git] / bundles / org.simantics.db.layer0 / src / org / simantics / db / layer0 / adapter / impl / TGRemover.java
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
8  *\r
9  * Contributors:\r
10  *     VTT Technical Research Centre of Finland - initial API and implementation\r
11  *******************************************************************************/\r
12 package org.simantics.db.layer0.adapter.impl;\r
13 \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
23 \r
24 /**\r
25  * @author Tuukka Lehtonen\r
26  */\r
27 public class TGRemover extends AbstractRemover {\r
28 \r
29     @SuppressWarnings("unused")\r
30     private IProgressMonitor monitor;\r
31 \r
32     public TGRemover(Resource resource) {\r
33         super(resource);\r
34     }\r
35 \r
36     public TGRemover(IProgressMonitor monitor, Resource resource) {\r
37         super(resource);\r
38         this.monitor = monitor;\r
39     }\r
40 \r
41     @Override\r
42     public void remove(final WriteGraph graph) throws DatabaseException {\r
43         \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
48         \r
49         try {\r
50                         source.forResourceStatements(graph, new TransferableGraphSourceProcedure<int[]>() {\r
51                                 \r
52                                 @Override\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
56                                         Resource i = null;\r
57                                         if(value[2] != -1) i = ss.getResource(value[2]);\r
58                                         Resource o = ss.getResource(value[3]);\r
59                                         \r
60 //                                      System.err.println("s=" + s + " p=" + graph.getPossibleURI(p) + " o=" + o + " p:" + p + " i:" + i);\r
61                                         \r
62                                         graph.deny(s,p,i,o);\r
63                                 }\r
64                                 \r
65                         });\r
66                         \r
67                         source.forValueResources(graph, new TransferableGraphSourceProcedure<int[]>() {\r
68                                 \r
69                                 @Override\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
73                                         graph.denyValue(s);\r
74                                 }\r
75                                 \r
76                         });\r
77                         \r
78                         source.closeStreams();\r
79                         \r
80                 } catch (Exception e) {\r
81                         throw new DatabaseException(e);\r
82                 }\r
83         \r
84     }\r
85 \r
86 }\r