View Javadoc

1   package net.obsearch.storage;
2   import net.obsearch.exception.OBStorageException;
3   import net.obsearch.exception.OBException;
4   import net.obsearch.storage.OBStorageConfig;
5   import java.math.BigInteger;
6   /*
7    OBSearch: a distributed similarity search engine This project is to
8    similarity search what 'bit-torrent' is to downloads. 
9    Copyright (C) 2008 Arnoldo Jose Muller Molina
10  
11   This program is free software: you can redistribute it and/or modify
12   it under the terms of the GNU General Public License as published by
13   the Free Software Foundation, either version 3 of the License, or
14   (at your option) any later version.
15  
16   This program is distributed in the hope that it will be useful,
17   but WITHOUT ANY WARRANTY; without even the implied warranty of
18   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
19   GNU General Public License for more details.
20  
21   You should have received a copy of the GNU General Public License
22   along with this program.  If not, see <http://www.gnu.org/licenses/>.
23   */
24  
25  /**
26   * OBStoreFactory defines several methods to facilitate the creation of indexes
27   * by OBSearch's indexes. In general, each index should receive an object that
28   * implements OBStoreFactory and from then, the index will get databases from
29   * the factory as needed. Constructors for each factory are expected to define
30   * how and where the data will be accessed. If the factory cannot provide some
31   * of the requested indexes, an
32   * {@link #net.obsearch.exception.UnsupportedStorageException} is thrown.
33   * @author Arnoldo Jose Muller Molina
34   */
35  
36  public interface OBStoreFactory {
37  
38      /**
39       * Creates a generic OBStore.
40       * @param temp
41       *                If true, the database will be configured to be a temporal
42       *                database.
43       * @param name The name of the database.
44  		 * @param duplicates If duplicates are to be allowed.
45  		 * @param bulkMode If we want the storage to be faster for lots of insertions.
46       * @return An OBStore ready to be used.
47       * @throws OBStorageException If the DB cannot be created.
48       */
49      OBStore<TupleBytes> createOBStore(String name, OBStorageConfig config) throws OBStorageException, OBException;
50      
51  		/**
52       * Removes all indexes and structures related to the given storage device.
53  		 * @param storage The storage device to remove.
54  		 * @throws OBStorageException If something goes wrong with the delete operation.
55  		 */
56  		void removeOBStore(OBStore storage) throws OBStorageException, OBException;	
57  
58      
59  
60      /**
61       * Creates an OBStoreByte whose key is based on bytes.
62       * @param name The name of the database.
63       * @param temp
64       *                If true, the database will be configured to be a temporal
65       *                database.
66       * @param duplicates If duplicates are to be allowed.
67  		 * @param bulkMode If we want the storage to be faster for lots of insertions.
68       * @return An OBStoreByte ready to be used.
69       * @throws OBStorageException If the DB cannot be created.
70       */
71  				OBStoreByte createOBStoreByte(String name, OBStorageConfig config) throws OBStorageException, OBException;	
72  
73  
74  		
75  		
76  
77      /**
78       * Creates a binary representation of the given value.
79       * The value must be returned in such a way that it can be sorted
80       * with bytes.
81  		 */
82  		byte[] serializeByte(byte value);
83  
84  
85  		/**
86       * Creates a byte of the given value.
87  		 * Only the required bytes are taken from the input.
88  		 */
89  		 byte deSerializeByte(byte[] value);
90  
91  
92      /**
93       * Creates an OBStoreShort whose key is based on shorts.
94       * @param name The name of the database.
95       * @param temp
96       *                If true, the database will be configured to be a temporal
97       *                database.
98       * @param duplicates If duplicates are to be allowed.
99  		 * @param bulkMode If we want the storage to be faster for lots of insertions.
100      * @return An OBStoreShort ready to be used.
101      * @throws OBStorageException If the DB cannot be created.
102      */
103 				OBStoreShort createOBStoreShort(String name, OBStorageConfig config) throws OBStorageException, OBException;	
104 
105 
106 		
107 		
108 
109     /**
110      * Creates a binary representation of the given value.
111      * The value must be returned in such a way that it can be sorted
112      * with bytes.
113 		 */
114 		byte[] serializeShort(short value);
115 
116 
117 		/**
118      * Creates a short of the given value.
119 		 * Only the required bytes are taken from the input.
120 		 */
121 		 short deSerializeShort(byte[] value);
122 
123 
124     /**
125      * Creates an OBStoreInt whose key is based on ints.
126      * @param name The name of the database.
127      * @param temp
128      *                If true, the database will be configured to be a temporal
129      *                database.
130      * @param duplicates If duplicates are to be allowed.
131 		 * @param bulkMode If we want the storage to be faster for lots of insertions.
132      * @return An OBStoreInt ready to be used.
133      * @throws OBStorageException If the DB cannot be created.
134      */
135 				OBStoreInt createOBStoreInt(String name, OBStorageConfig config) throws OBStorageException, OBException;	
136 
137 
138 		
139 		
140 
141     /**
142      * Creates a binary representation of the given value.
143      * The value must be returned in such a way that it can be sorted
144      * with bytes.
145 		 */
146 		byte[] serializeInt(int value);
147 
148 
149 		/**
150      * Creates a int of the given value.
151 		 * Only the required bytes are taken from the input.
152 		 */
153 		 int deSerializeInt(byte[] value);
154 
155 
156     /**
157      * Creates an OBStoreLong whose key is based on longs.
158      * @param name The name of the database.
159      * @param temp
160      *                If true, the database will be configured to be a temporal
161      *                database.
162      * @param duplicates If duplicates are to be allowed.
163 		 * @param bulkMode If we want the storage to be faster for lots of insertions.
164      * @return An OBStoreLong ready to be used.
165      * @throws OBStorageException If the DB cannot be created.
166      */
167 				OBStoreLong createOBStoreLong(String name, OBStorageConfig config) throws OBStorageException, OBException;	
168 
169 
170 		
171 		
172 
173     /**
174      * Creates a binary representation of the given value.
175      * The value must be returned in such a way that it can be sorted
176      * with bytes.
177 		 */
178 		byte[] serializeLong(long value);
179 
180 
181 		/**
182      * Creates a long of the given value.
183 		 * Only the required bytes are taken from the input.
184 		 */
185 		 long deSerializeLong(byte[] value);
186 
187 
188     /**
189      * Creates an OBStoreFloat whose key is based on floats.
190      * @param name The name of the database.
191      * @param temp
192      *                If true, the database will be configured to be a temporal
193      *                database.
194      * @param duplicates If duplicates are to be allowed.
195 		 * @param bulkMode If we want the storage to be faster for lots of insertions.
196      * @return An OBStoreFloat ready to be used.
197      * @throws OBStorageException If the DB cannot be created.
198      */
199 				OBStoreFloat createOBStoreFloat(String name, OBStorageConfig config) throws OBStorageException, OBException;	
200 
201 
202 		
203 		
204 
205     /**
206      * Creates a binary representation of the given value.
207      * The value must be returned in such a way that it can be sorted
208      * with bytes.
209 		 */
210 		byte[] serializeFloat(float value);
211 
212 
213 		/**
214      * Creates a float of the given value.
215 		 * Only the required bytes are taken from the input.
216 		 */
217 		 float deSerializeFloat(byte[] value);
218 
219 
220     /**
221      * Creates an OBStoreDouble whose key is based on doubles.
222      * @param name The name of the database.
223      * @param temp
224      *                If true, the database will be configured to be a temporal
225      *                database.
226      * @param duplicates If duplicates are to be allowed.
227 		 * @param bulkMode If we want the storage to be faster for lots of insertions.
228      * @return An OBStoreDouble ready to be used.
229      * @throws OBStorageException If the DB cannot be created.
230      */
231 				OBStoreDouble createOBStoreDouble(String name, OBStorageConfig config) throws OBStorageException, OBException;	
232 
233 
234 		
235 		
236 
237     /**
238      * Creates a binary representation of the given value.
239      * The value must be returned in such a way that it can be sorted
240      * with bytes.
241 		 */
242 		byte[] serializeDouble(double value);
243 
244 
245 		/**
246      * Creates a double of the given value.
247 		 * Only the required bytes are taken from the input.
248 		 */
249 		 double deSerializeDouble(byte[] value);
250 
251     
252 		/**
253      * Creates a binary representation of the given value.
254      * The value must be returned in such a way that it can be sorted
255      * with bytes.
256 		 */
257 		byte[] serializeBigInteger(BigInteger value);
258 
259 		/**
260      * Creates a BigInteger of the given value.
261 		 * Only the required bytes are taken from the input.
262 		 */
263 		BigInteger deSerializeBigInteger(byte[] value);
264 		
265     /** 
266      * Close the factory. All opened OBStores must be closed before this
267      * method is called.
268      * @throws OBStorageException if something goes wrong with the
269      * underlying storage system.
270      */ 
271     void close() throws OBStorageException;
272 
273 
274 		/**
275      * Return a stats object that is to be printed
276      * @throws OBStorageException if something goes wrong with the
277      * underlying storage system.
278      */
279 		Object stats() throws OBStorageException;
280 
281 
282 		/**
283 		 * Return the url where this factory is located.
284 		 */
285 		String getFactoryLocation();
286 }