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