]> gerrit.simantics Code Review - simantics/platform.git/blobdiff - 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
diff --git a/bundles/org.simantics.db/src/org/simantics/db/service/internal/RawDataSupport.java b/bundles/org.simantics.db/src/org/simantics/db/service/internal/RawDataSupport.java
new file mode 100644 (file)
index 0000000..af33a6a
--- /dev/null
@@ -0,0 +1,79 @@
+/*******************************************************************************\r
+ * Copyright (c) 2007, 2010 Association for Decentralized Information Management\r
+ * in Industry THTH ry.\r
+ * All rights reserved. This program and the accompanying materials\r
+ * are made available under the terms of the Eclipse Public License v1.0\r
+ * which accompanies this distribution, and is available at\r
+ * http://www.eclipse.org/legal/epl-v10.html\r
+ *\r
+ * Contributors:\r
+ *     VTT Technical Research Centre of Finland - initial API and implementation\r
+ *******************************************************************************/\r
+package org.simantics.db.service.internal;\r
+\r
+import java.io.IOException;\r
+import java.io.InputStream;\r
+import java.io.OutputStream;\r
+\r
+import org.simantics.db.AsyncReadGraph;\r
+import org.simantics.db.Resource;\r
+import org.simantics.db.VirtualGraph;\r
+import org.simantics.db.WriteOnlyGraph;\r
+import org.simantics.db.exception.DatabaseException;\r
+import org.simantics.db.service.TransferableGraphSupport;\r
+\r
+/**\r
+ * This interface is a proposition of a replacement for\r
+ * {@link TransferableGraphSupport}. The main arguments for this interface are:\r
+ * <ol>\r
+ * <li>Streaming support for large data (using I/O streams)</li>\r
+ * <li>Remaining performant with small data (using OutputStream in\r
+ * {@link #getValue(AsyncReadGraph, Resource, OutputStream)})</li>\r
+ * <li>Still very similar to {@link TransferableGraphSupport} and therefore\r
+ * should be easy to implement</li>\r
+ * </ol>\r
+ * \r
+ * @author Tuukka Lehtonen\r
+ */\r
+public interface RawDataSupport {\r
+\r
+    /**\r
+     * Retrieve raw value/file data attached to the specified resource into the\r
+     * specified output stream.\r
+     * \r
+     * @param graph valid database read handle to prove the request is performed\r
+     *        from within a read or write transaction.\r
+     * @param resource resource to get value/file from\r
+     * @param output stream to write the raw data into\r
+     * @return -1 if resource contained no value/file, number of bytes written\r
+     *         to the stream otherwise.\r
+     * @throws IOException problems writing the output stream\r
+     * @throws DatabaseException error occurred while writing the database\r
+     */\r
+    long getValue(AsyncReadGraph graph, Resource resource, OutputStream stream) throws IOException, DatabaseException;\r
+\r
+    /**\r
+     * Set raw value/file data attached to the specified resource from the\r
+     * specified input stream.\r
+     * \r
+     * <p>\r
+     * Write transactions are single-threaded and exclusive which implies that a\r
+     * client cannot invoke\r
+     * {@link #getValue(AsyncReadGraph, Resource, OutputStream)} and\r
+     * {@link #setValue(WriteOnlyGraph, Resource, VirtualGraph, InputStream)}\r
+     * simultaneously in another read transaction.\r
+     * \r
+     * @param graph valid database read handle to prove the request is performed\r
+     *        from within a write transaction.\r
+     * @param resource resource to set value/file for\r
+     * @param provider provider for writing to virtual graphs, may be\r
+     *        <code>null</code>\r
+     * @param input stream to read the raw data from\r
+     * @return number of raw data bytes written to the database.\r
+     * @throws IOException problems reading the input stream\r
+     * @throws DatabaseException error occurred while writing the database\r
+     */\r
+    long setValue(WriteOnlyGraph graph, Resource resource, VirtualGraph provider, InputStream input)\r
+    throws IOException, DatabaseException;\r
+\r
+}\r