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