]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.db/src/org/simantics/db/service/internal/RawDataSupport.java
Migrated source code from Simantics SVN
[simantics/platform.git] / bundles / org.simantics.db / src / org / simantics / db / service / internal / RawDataSupport.java
1 /*******************************************************************************\r
2  * Copyright (c) 2007, 2010 Association for Decentralized Information Management\r
3  * in Industry THTH ry.\r
4  * All rights reserved. This program and the accompanying materials\r
5  * are made available under the terms of the Eclipse Public License v1.0\r
6  * which accompanies this distribution, and is available at\r
7  * http://www.eclipse.org/legal/epl-v10.html\r
8  *\r
9  * Contributors:\r
10  *     VTT Technical Research Centre of Finland - initial API and implementation\r
11  *******************************************************************************/\r
12 package org.simantics.db.service.internal;\r
13 \r
14 import java.io.IOException;\r
15 import java.io.InputStream;\r
16 import java.io.OutputStream;\r
17 \r
18 import org.simantics.db.AsyncReadGraph;\r
19 import org.simantics.db.Resource;\r
20 import org.simantics.db.VirtualGraph;\r
21 import org.simantics.db.WriteOnlyGraph;\r
22 import org.simantics.db.exception.DatabaseException;\r
23 import org.simantics.db.service.TransferableGraphSupport;\r
24 \r
25 /**\r
26  * This interface is a proposition of a replacement for\r
27  * {@link TransferableGraphSupport}. The main arguments for this interface are:\r
28  * <ol>\r
29  * <li>Streaming support for large data (using I/O streams)</li>\r
30  * <li>Remaining performant with small data (using OutputStream in\r
31  * {@link #getValue(AsyncReadGraph, Resource, OutputStream)})</li>\r
32  * <li>Still very similar to {@link TransferableGraphSupport} and therefore\r
33  * should be easy to implement</li>\r
34  * </ol>\r
35  * \r
36  * @author Tuukka Lehtonen\r
37  */\r
38 public interface RawDataSupport {\r
39 \r
40     /**\r
41      * Retrieve raw value/file data attached to the specified resource into the\r
42      * specified output stream.\r
43      * \r
44      * @param graph valid database read handle to prove the request is performed\r
45      *        from within a read or write transaction.\r
46      * @param resource resource to get value/file from\r
47      * @param output stream to write the raw data into\r
48      * @return -1 if resource contained no value/file, number of bytes written\r
49      *         to the stream otherwise.\r
50      * @throws IOException problems writing the output stream\r
51      * @throws DatabaseException error occurred while writing the database\r
52      */\r
53     long getValue(AsyncReadGraph graph, Resource resource, OutputStream stream) throws IOException, DatabaseException;\r
54 \r
55     /**\r
56      * Set raw value/file data attached to the specified resource from the\r
57      * specified input stream.\r
58      * \r
59      * <p>\r
60      * Write transactions are single-threaded and exclusive which implies that a\r
61      * client cannot invoke\r
62      * {@link #getValue(AsyncReadGraph, Resource, OutputStream)} and\r
63      * {@link #setValue(WriteOnlyGraph, Resource, VirtualGraph, InputStream)}\r
64      * simultaneously in another read transaction.\r
65      * \r
66      * @param graph valid database read handle to prove the request is performed\r
67      *        from within a write transaction.\r
68      * @param resource resource to set value/file for\r
69      * @param provider provider for writing to virtual graphs, may be\r
70      *        <code>null</code>\r
71      * @param input stream to read the raw data from\r
72      * @return number of raw data bytes written to the database.\r
73      * @throws IOException problems reading the input stream\r
74      * @throws DatabaseException error occurred while writing the database\r
75      */\r
76     long setValue(WriteOnlyGraph graph, Resource resource, VirtualGraph provider, InputStream input)\r
77     throws IOException, DatabaseException;\r
78 \r
79 }\r