Debian Codegraph @

jdbm1/src/main/java/jdbm/RecordManager.java

raw
1 /**
2 * JDBM LICENSE v1.00
3 *
4 * Redistribution and use of this software and associated documentation
5 * ("Software"), with or without modification, are permitted provided
6 * that the following conditions are met:
7 *
8 * 1. Redistributions of source code must retain copyright
9 * statements and notices. Redistributions must also contain a
10 * copy of this document.
11 *
12 * 2. Redistributions in binary form must reproduce the
13 * above copyright notice, this list of conditions and the
14 * following disclaimer in the documentation and/or other
15 * materials provided with the distribution.
16 *
17 * 3. The name "JDBM" must not be used to endorse or promote
18 * products derived from this Software without prior written
19 * permission of Cees de Groot. For written permission,
20 * please contact [email protected].
21 *
22 * 4. Products derived from this Software may not be called "JDBM"
23 * nor may "JDBM" appear in their names without prior written
24 * permission of Cees de Groot.
25 *
26 * 5. Due credit should be given to the JDBM Project
27 * (http://jdbm.sourceforge.net/).
28 *
29 * THIS SOFTWARE IS PROVIDED BY THE JDBM PROJECT AND CONTRIBUTORS
30 * ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT
31 * NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
32 * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
33 * CEES DE GROOT OR ANY CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
34 * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
35 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
36 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
37 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
38 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
39 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
40 * OF THE POSSIBILITY OF SUCH DAMAGE.
41 *
42 * Copyright 2000 (C) Cees de Groot. All Rights Reserved.
43 * Copyright 2000-2001 (C) Alex Boisvert. All Rights Reserved.
44 * Contributions are Copyright (C) 2000 by their associated contributors.
45 *
46 * $Id: RecordManager.java,v 1.3 2005/06/25 23:12:31 doomdark Exp $
47 */
48 package jdbm;
49
50
51 import java.io.IOException;
52 import jdbm.helper.Serializer;
53
54
55 /**
56 * An interface to manages records, which are uninterpreted blobs of data.
57 * <p>
58 * The set of record operations is simple: fetch, insert, update and delete.
59 * Each record is identified using a "rowid" and contains a byte[] data block.
60 * Rowids are returned on inserts and you can store them someplace safe
61 * to be able to get back to them. Data blocks can be as long as you wish,
62 * and may have lengths different from the original when updating.
63 *
64 * @author <a href="mailto:[email protected]">Alex Boisvert</a>
65 * @author <a href="[email protected]">Cees de Groot</a>
66 */
67 public interface RecordManager
68 {
69 /** Reserved slot for name directory. */
70 int NAME_DIRECTORY_ROOT = 0;
71
72
73 /**
74 * Inserts a new record using standard java object serialization.
75 *
76 * @param obj the object for the new record.
77 * @return the rowid for the new record.
78 * @throws IOException when one of the underlying I/O operations fails.
79 */
80 long insert( Object obj ) throws IOException;
81
82
83 /**
84 * Inserts a new record using a custom serializer.
85 *
86 * @param obj the object for the new record.
87 * @param serializer a custom serializer
88 * @return the rowid for the new record.
89 * @throws IOException when one of the underlying I/O operations fails.
90 */
91 long insert( Object obj, Serializer serializer ) throws IOException;
92
93
94 /**
95 * Deletes a record.
96 *
97 * @param recid the rowid for the record that should be deleted.
98 * @throws IOException when one of the underlying I/O operations fails.
99 */
100 void delete( long recid ) throws IOException;
101
102
103 /**
104 * Updates a record using standard java object serialization.
105 *
106 * @param recid the recid for the record that is to be updated.
107 * @param obj the new object for the record.
108 * @throws IOException when one of the underlying I/O operations fails.
109 */
110 void update( long recid, Object obj ) throws IOException;
111
112
113 /**
114 * Updates a record using a custom serializer.
115 *
116 * @param recid the recid for the record that is to be updated.
117 * @param obj the new object for the record.
118 * @param serializer a custom serializer
119 * @throws IOException when one of the underlying I/O operations fails.
120 */
121 void update( long recid, Object obj, Serializer serializer ) throws IOException;
122
123
124 /**
125 * Fetches a record using standard java object serialization.
126 *
127 * @param recid the recid for the record that must be fetched.
128 * @return the object contained in the record.
129 * @throws IOException when one of the underlying I/O operations fails.
130 */
131 Object fetch( long recid ) throws IOException;
132
133
134 /**
135 * Fetches a record using a custom serializer.
136 *
137 * @param recid the recid for the record that must be fetched.
138 * @param serializer a custom serializer
139 * @return the object contained in the record.
140 * @throws IOException when one of the underlying I/O operations fails.
141 */
142 Object fetch( long recid, Serializer serializer ) throws IOException;
143
144
145 /**
146 * Closes the record manager.
147 *
148 * @throws IOException when one of the underlying I/O operations fails.
149 */
150 void close() throws IOException;
151
152
153 /**
154 * Returns the number of slots available for "root" rowids. These slots
155 * can be used to store special rowids, like rowids that point to
156 * other rowids. Root rowids are useful for bootstrapping access to
157 * a set of data.
158 */
159 int getRootCount();
160
161
162 /**
163 * Returns the indicated root rowid.
164 *
165 * @see #getRootCount
166 */
167 long getRoot( int id ) throws IOException;
168
169
170 /**
171 * Sets the indicated root rowid.
172 *
173 * @see #getRootCount
174 */
175 void setRoot( int id, long rowid ) throws IOException;
176
177
178 /** Commit (make persistent) all changes since beginning of transaction. */
179 void commit() throws IOException;
180
181
182 /** Rollback (cancel) all changes since beginning of transaction. */
183 void rollback() throws IOException;
184
185
186 /** Obtain the record id of a named object. Returns 0 if named object doesn't exist. */
187 long getNamedObject( String name ) throws IOException;
188
189
190 /** Set the record id of a named object. */
191 void setNamedObject( String name, long recid ) throws IOException;
192 }
193