X-Git-Url: https://gerrit.simantics.org/r/gitweb?p=simantics%2Fplatform.git;a=blobdiff_plain;f=bundles%2Forg.simantics.graph.db%2Fsrc%2Forg%2Fsimantics%2Fgraph%2Fdb%2FTransferableGraphs.java;h=2b93df74dceeb0fed0b3f0c871a62fe043968d8a;hp=6aa24637e4a075792121eace6f5b81447d722e6a;hb=69d8f2b115a832560eca0d56903c8977178b71ab;hpb=c26409b1caf2f1e560d37c5befd11b442399c3fe diff --git a/bundles/org.simantics.graph.db/src/org/simantics/graph/db/TransferableGraphs.java b/bundles/org.simantics.graph.db/src/org/simantics/graph/db/TransferableGraphs.java index 6aa24637e..2b93df74d 100644 --- a/bundles/org.simantics.graph.db/src/org/simantics/graph/db/TransferableGraphs.java +++ b/bundles/org.simantics.graph.db/src/org/simantics/graph/db/TransferableGraphs.java @@ -185,7 +185,7 @@ public class TransferableGraphs { final IImportAdvisor2 advisor = (advisor_ instanceof IImportAdvisor2) ? ((IImportAdvisor2)advisor_) : new WrapperAdvisor(advisor_); - final StreamingTransferableGraphImportProcess process = new StreamingTransferableGraphImportProcess(session, vg, tg, advisor); + final StreamingTransferableGraphImportProcess process = new StreamingTransferableGraphImportProcess(session, vg, tg, advisor, monitor); session.syncRequest(new ReadRequest() { @Override public void run(ReadGraph graph) throws DatabaseException { @@ -440,15 +440,23 @@ public class TransferableGraphs { } public static void writeTransferableGraph(RequestProcessor processor, String format, int version, TreeMap metadata, TransferableGraphSource source, File target, TGStatusMonitor monitor) throws Exception { - final Serializer datatypeSerializer = Bindings.getSerializerUnchecked(Datatype.class); try (RandomAccessBinary out = new BinaryFile(target, 128*1024)) { - DataContainer container = new DataContainer(format, version, metadata, null); - DataContainers.writeHeader(out, container); - datatypeSerializer.serialize((DataOutput) out, Datatypes.getDatatypeUnchecked(TransferableGraph1.class)); - writeTransferableGraph(processor, source, out, monitor); + DataContainers.writeHeader(out, new DataContainer(format, version, metadata, null)); + writeTransferableGraphVariant(processor, source, out, monitor); + } + } + + public static void writeTransferableGraph(RequestProcessor processor, TransferableGraphSource source, File target, TGStatusMonitor monitor) throws Exception { + try (RandomAccessBinary out = new BinaryFile(target, 128*1024)) { + writeTransferableGraphVariant(processor, source, out, monitor); } } + public static void writeTransferableGraphVariant(RequestProcessor processor, TransferableGraphSource source, RandomAccessBinary out, TGStatusMonitor monitor) throws Exception { + Bindings.getSerializerUnchecked(Datatype.class).serialize(out, Datatypes.getDatatypeUnchecked(TransferableGraph1.class)); + writeTransferableGraph(processor, source, out, monitor); + } + private static TGStatusMonitor safeMonitor(TGStatusMonitor mon) { return mon == null ? TGStatusMonitor.NULL_MONITOR : mon; } @@ -589,15 +597,14 @@ public class TransferableGraphs { public static TransferableGraph1 create(ReadGraph graph, TransferableGraphSource source) throws DatabaseException { - final TIntArrayList statements = new TIntArrayList(); - final ArrayList values = new ArrayList<>(); - final ArrayList identities = new ArrayList<>(); - try { + ArrayList identities = new ArrayList<>(source.getIdentityCount()); + source.forIdentities(graph, i -> identities.add(i)); + TIntArrayList statements = new TIntArrayList(source.getStatementCount()); source.forStatements(graph, r -> statements.addAll(r)); + ArrayList values = new ArrayList<>(source.getValueCount()); source.forValues(graph, v -> values.add(v)); - source.forIdentities(graph, i -> identities.add(i)); return new TransferableGraph1(source.getResourceCount(), identities.toArray(new Identity[identities.size()]),