91e60944162d2245bd4fb46fe98dc6eb4a44e214
[sixth-data.git] / src / main / java / eu / svjatoslav / sixth / data / store / DataStore.java
1 /*
2  * Sixth - System for data storage, computation, exploration and interaction.
3  * Copyright ©2012-2016, Svjatoslav Agejenko, svjatoslav@svjatoslav.eu
4  * 
5  * This program is free software; you can redistribute it and/or
6  * modify it under the terms of version 3 of the GNU Lesser General Public License
7  * or later as published by the Free Software Foundation.
8  */
9
10 package eu.svjatoslav.sixth.data.store;
11
12 import java.io.IOException;
13
14 /**
15  * Data store acts as a numerical ID to corresponding record map.
16  * <p>
17  * Record is basically an array of bytes of arbitrary length, identifiable by ID
18  * that is assigned to record during record creation.
19  * <p>
20  * Records can be updated with alternative content and length. Data store takes
21  * care of data fragmentation.
22  */
23 public interface DataStore {
24
25     /**
26      * Close datastore.
27      */
28     void close() throws IOException;
29
30     /**
31      * Create new record and set its initial contents.
32      */
33     int createRecord(byte[] value) throws IOException;
34
35     /**
36      * Delete record identified by given ID. DataStore will mark given ID as
37      * unused, and could reuse this ID later for another newly created record.
38      */
39     void deleteRecord(int id) throws IOException;
40
41     /**
42      * Read entire record into byte array.
43      */
44     byte[] readRecord(int id) throws IOException;
45
46     /**
47      * Update record with new value.
48      */
49     void updateRecord(int id, byte[] value) throws IOException;
50
51 }