]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.graph.db/src/org/simantics/graph/db/old/OldTransferableGraphs.java
Migrated source code from Simantics SVN
[simantics/platform.git] / bundles / org.simantics.graph.db / src / org / simantics / graph / db / old / OldTransferableGraphs.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.graph.db.old;\r
13 \r
14 import org.simantics.db.ReadGraph;\r
15 import org.simantics.db.Session;\r
16 import org.simantics.db.WriteGraph;\r
17 import org.simantics.db.WriteOnlyGraph;\r
18 import org.simantics.db.common.request.ReadRequest;\r
19 import org.simantics.db.common.request.WriteOnlyRequest;\r
20 import org.simantics.db.exception.DatabaseException;\r
21 import org.simantics.graph.db.IImportAdvisor;\r
22 import org.simantics.graph.db.ImportAdvisor;\r
23 import org.simantics.graph.db.TransferableGraphException;\r
24 import org.simantics.graph.representation.old.OldTransferableGraph1;\r
25 import org.simantics.utils.datastructures.BinaryFunction;\r
26 \r
27 public class OldTransferableGraphs {\r
28 \r
29     public static void importGraph1(Session session, final OldTransferableGraph1 tg, IImportAdvisor advisor, final BinaryFunction<Boolean, WriteOnlyGraph, OldTransferableGraphImportProcess1> callback) throws DatabaseException, TransferableGraphException {\r
30         final OldTransferableGraphImportProcess1 process = new OldTransferableGraphImportProcess1(tg, \r
31                 advisor == null ? new ImportAdvisor() : advisor);\r
32         session.syncRequest(new ReadRequest() {\r
33             @Override\r
34             public void run(ReadGraph graph) throws DatabaseException {\r
35                 process.prepare(graph);\r
36             }\r
37         });\r
38         session.syncRequest(new WriteOnlyRequest() {\r
39             @Override\r
40             public void perform(WriteOnlyGraph graph) throws DatabaseException {\r
41                 process.write(graph);\r
42                 if(callback != null)\r
43                     callback.call(graph, process);\r
44             }\r
45         });\r
46     }\r
47     \r
48     public static void importGraph1(WriteGraph graph, final OldTransferableGraph1 tg, IImportAdvisor advisor) throws DatabaseException {\r
49         final OldTransferableGraphImportProcess1 process = new OldTransferableGraphImportProcess1(tg, \r
50                 advisor == null ? new ImportAdvisor() : advisor);\r
51         process.prepare(graph);\r
52         process.write2(graph);\r
53        \r
54     }\r
55     \r
56 }\r