]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.db/src/org/simantics/db/service/internal/RawDataSupport.java
Fixed all line endings of the repository
[simantics/platform.git] / bundles / org.simantics.db / src / org / simantics / db / service / internal / RawDataSupport.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.db.service.internal;
13
14 import java.io.IOException;
15 import java.io.InputStream;
16 import java.io.OutputStream;
17
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;
24
25 /**
26  * This interface is a proposition of a replacement for
27  * {@link TransferableGraphSupport}. The main arguments for this interface are:
28  * <ol>
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>
34  * </ol>
35  * 
36  * @author Tuukka Lehtonen
37  */
38 public interface RawDataSupport {
39
40     /**
41      * Retrieve raw value/file data attached to the specified resource into the
42      * specified output stream.
43      * 
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
52      */
53     long getValue(AsyncReadGraph graph, Resource resource, OutputStream stream) throws IOException, DatabaseException;
54
55     /**
56      * Set raw value/file data attached to the specified resource from the
57      * specified input stream.
58      * 
59      * <p>
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.
65      * 
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
70      *        <code>null</code>
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
75      */
76     long setValue(WriteOnlyGraph graph, Resource resource, VirtualGraph provider, InputStream input)
77     throws IOException, DatabaseException;
78
79 }