1 /*******************************************************************************
2 * Copyright (c) 2007, 2010 Association for Decentralized Information Management
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
10 * VTT Technical Research Centre of Finland - initial API and implementation
11 *******************************************************************************/
12 package org.simantics.db.service.internal;
14 import java.io.IOException;
15 import java.io.InputStream;
16 import java.io.OutputStream;
18 import org.simantics.db.AsyncReadGraph;
19 import org.simantics.db.Resource;
20 import org.simantics.db.VirtualGraph;
21 import org.simantics.db.WriteOnlyGraph;
22 import org.simantics.db.exception.DatabaseException;
23 import org.simantics.db.service.TransferableGraphSupport;
26 * This interface is a proposition of a replacement for
27 * {@link TransferableGraphSupport}. The main arguments for this interface are:
29 * <li>Streaming support for large data (using I/O streams)</li>
30 * <li>Remaining performant with small data (using OutputStream in
31 * {@link #getValue(AsyncReadGraph, Resource, OutputStream)})</li>
32 * <li>Still very similar to {@link TransferableGraphSupport} and therefore
33 * should be easy to implement</li>
36 * @author Tuukka Lehtonen
38 public interface RawDataSupport {
41 * Retrieve raw value/file data attached to the specified resource into the
42 * specified output stream.
44 * @param graph valid database read handle to prove the request is performed
45 * from within a read or write transaction.
46 * @param resource resource to get value/file from
47 * @param output stream to write the raw data into
48 * @return -1 if resource contained no value/file, number of bytes written
49 * to the stream otherwise.
50 * @throws IOException problems writing the output stream
51 * @throws DatabaseException error occurred while writing the database
53 long getValue(AsyncReadGraph graph, Resource resource, OutputStream stream) throws IOException, DatabaseException;
56 * Set raw value/file data attached to the specified resource from the
57 * specified input stream.
60 * Write transactions are single-threaded and exclusive which implies that a
61 * client cannot invoke
62 * {@link #getValue(AsyncReadGraph, Resource, OutputStream)} and
63 * {@link #setValue(WriteOnlyGraph, Resource, VirtualGraph, InputStream)}
64 * simultaneously in another read transaction.
66 * @param graph valid database read handle to prove the request is performed
67 * from within a write transaction.
68 * @param resource resource to set value/file for
69 * @param provider provider for writing to virtual graphs, may be
71 * @param input stream to read the raw data from
72 * @return number of raw data bytes written to the database.
73 * @throws IOException problems reading the input stream
74 * @throws DatabaseException error occurred while writing the database
76 long setValue(WriteOnlyGraph graph, Resource resource, VirtualGraph provider, InputStream input)
77 throws IOException, DatabaseException;