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