|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object net.obsearch.index.AbstractOBIndex<O>
public abstract class AbstractOBIndex<O extends OB>
AbstractOBIndex contains functionality regarding object storage. Children of this class should define a way of searching those objects. This class provides default implementations of methods that are considered optional in the Index interface.
Field Summary | |
---|---|
protected OBStoreLong |
A
Objects are stored by their id's here. |
protected OBStoreFactory |
fact
Factory used by this class and by subclasses to create appropiate storage devices. |
protected boolean |
isFrozen
True if this index is frozen. |
protected Statistics |
stats
Statistics related to this index. |
protected Class<O> |
type
The type used to instantiate objects of type O. |
Fields inherited from interface net.obsearch.Index |
---|
ID_SIZE |
Constructor Summary | |
---|---|
|
AbstractOBIndex()
|
protected |
AbstractOBIndex(Class<O> type)
Constructors of an AbstractOBIndex should receive only parameters related to the operation of the index. |
Method Summary | |
---|---|
protected void |
assertFrozen()
If the database is frozen returns silently if it is not throws NotFrozenException. |
protected O |
bytesToObject(byte[] data)
Instantiates an object O from the given data array. |
protected O |
bytesToObject(ByteBuffer data)
Instantiates an object O from the given data array. |
protected void |
clearACache()
Clear A cache. |
void |
close()
Closes the database. |
long |
databaseSize()
Returns the database size. |
String |
debug(O object)
Routine that helps to debug objects. |
OperationStatus |
delete(O object)
Deletes the given object from the database. |
protected abstract OperationStatus |
deleteAux(O object)
Deletes the entry of this object in the index. |
protected double |
distance(O a2,
O b)
|
O[] |
emptyPivotsArray(int size)
Create an empty pivots array. |
protected OperationStatus |
findAux(O object)
Find the Id of the given object. |
void |
freeze()
Freezes the index. |
long |
getBox(O object)
Returns the box where the given object is stored. |
O |
getObject(long id)
This method returns the object with internal id "i". |
Statistics |
getStats()
|
Class<O> |
getType()
Returns the type of the object to be stored. |
void |
init(OBStoreFactory fact)
Initialize the index. |
protected void |
initCache()
Initializes the object cache aCache . |
protected void |
initStorageDevices()
Initializes storage devices required by this class. |
OperationStatus |
insert(O object)
Inserts the given object into the index. |
OperationStatus |
insert(O object,
long id)
Inserts the given object into the index. |
protected abstract OperationStatus |
insertAux(long id,
O object)
Inserts the given object into the particular index. |
protected abstract OperationStatus |
insertAuxBulk(long id,
O object)
Inserts the given object into the particular index. |
OperationStatus |
insertBulk(O object)
Inserts the given object into the index. |
OperationStatus |
insertBulk(O object,
long id)
Inserts the given object into the index. |
double |
intrinsicDimensionality(int sampleSize)
Calculate the intrinsic dimension of the underlying database |
boolean |
isFrozen()
Returns true if the index is frozen. |
boolean |
isPreFreeze()
If we are going to check for the existence of data before freezing. |
boolean |
isPreFreezeCheck()
|
void |
loadObject(long i,
O object)
Loads object i into the given object |
protected O[] |
loadPivots(byte[][] serializedPivots)
|
protected byte[] |
objectToByteBuffer(O object)
|
protected byte[] |
objectToBytes(O object)
Converts an object into an array of bytes. |
void |
resetStats()
Resets all the stats counters. |
protected byte[][] |
serializePivots(long[] ids)
Finds the given objects in A and serializes them. |
void |
setFixedRecord(boolean fixedRecord)
|
void |
setFixedRecord(int fixedRecordSize)
|
void |
setIdAutoGeneration(boolean auto)
|
void |
setPreFreeze(boolean isPreFreeze)
If we are going to check for the existence of data before freezing preFreezeCheck should be set to true. |
void |
setPreFreezeCheck(boolean preFreezeCheck)
If the index should check for existent objects before freeze. |
long |
totalBoxes()
Returns the total number of boxes this index can hold. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Methods inherited from interface net.obsearch.Index |
---|
exists |
Field Detail |
---|
protected transient Statistics stats
protected transient OBStoreLong A
protected transient OBStoreFactory fact
protected boolean isFrozen
protected Class<O extends OB> type
Constructor Detail |
---|
public AbstractOBIndex()
protected AbstractOBIndex(Class<O> type) throws OBStorageException, OBException
init(OBStoreFactory)
type
-
OBStorageException
OBException
Method Detail |
---|
public boolean isPreFreezeCheck()
public void setPreFreezeCheck(boolean preFreezeCheck)
Index
setPreFreezeCheck
in interface Index<O extends OB>
preFreezeCheck
- Set the flag.protected void clearACache()
public final Class<O> getType()
getType
in interface Index<O extends OB>
type
protected void assertFrozen() throws NotFrozenException
NotFrozenException
- if the index has not been frozen.public void init(OBStoreFactory fact) throws OBStorageException, OBException, NotFrozenException, IllegalAccessException, InstantiationException, OBException
init
in interface Index<O extends OB>
fact
- The storage factory that will be used to store the data.
OBStorageException
OBException
NotFrozenException
- if the index has not been frozen.
IllegalAccessException
- If there is a problem when instantiating objects O
InstantiationException
- If there is a problem when instantiating objects Oprotected void initStorageDevices() throws OBStorageException, OBException
OBStorageException
- If the storage device could not be created.
OBException
public void setFixedRecord(boolean fixedRecord)
public void setFixedRecord(int fixedRecordSize)
protected void initCache() throws OBException
aCache
.
DatabaseException
- If something goes wrong with the DB.
OBException
public void loadObject(long i, O object) throws OBException
loadObject
in interface Index<O extends OB>
i
- The object to load.object
- Where we will upload the data.
IOException
OBException
public double intrinsicDimensionality(int sampleSize) throws IllegalIdException, IllegalAccessException, InstantiationException, OBException
sample
-
OBException
InstantiationException
IllegalAccessException
IllegalIdException
protected double distance(O a2, O b) throws OBException
OBException
public boolean isPreFreeze()
public void setPreFreeze(boolean isPreFreeze)
preFreezeCheck
- true (quality, data integrity) false (performance)protected O bytesToObject(ByteBuffer data) throws OBException, InstantiationException, IllegalAccessException, IllegalIdException
OBException
InstantiationException
IllegalAccessException
IllegalIdException
protected O bytesToObject(byte[] data) throws OBException, InstantiationException, IllegalAccessException, IllegalIdException
OBException
InstantiationException
IllegalAccessException
IllegalIdException
public void close() throws OBException
Index
close
in interface Index<O extends OB>
OBStorageException
- If something goes wrong with the DB.
OBException
public long databaseSize() throws OBStorageException
Index
databaseSize
in interface Index<O extends OB>
OBStorageException
- If something goes wrong with the DBpublic String debug(O object) throws OBException, InstantiationException, IllegalAccessException
Index
debug
in interface Index<O extends OB>
OBException
InstantiationException
IllegalAccessException
public OperationStatus delete(O object) throws OBException, IllegalAccessException, InstantiationException, NotFrozenException
Index
delete
in interface Index<O extends OB>
object
- The object to be deleted
Status.OK
and the deleted object's id
if the object was found and successfully deleted.
Status.NOT_EXISTS
if the object is not
in the database.
NotFrozenException
- if the index has not been frozen.
OBStorageException
- If something goes wrong with the DB
OBException
- User generated exception
IllegalAccessException
- If there is a problem when instantiating objects O
InstantiationException
- If there is a problem when instantiating objects Oprotected abstract OperationStatus deleteAux(O object) throws OBException, IllegalAccessException, InstantiationException
Status.OK
.
object
- object to be deleted.
Status.OK
if the object was deleted.
Status.NOT_EXISTS
no object matched.
OBException
IllegalAccessException
InstantiationException
protected byte[] objectToBytes(O object) throws OBException
object
- Object to convert.
OBException
protected byte[] objectToByteBuffer(O object) throws OBException
OBException
public O getObject(long id) throws IllegalIdException, IllegalAccessException, InstantiationException, OBException
Index
getObject
in interface Index<O extends OB>
id
- The id to be retrieved
IllegalAccessException
- If there is a problem when instantiating objects O
InstantiationException
- If there is a problem when instantiating objects O
OBStorageException
- If something goes wrong with the DB
OBException
- User generated exception
IllegalIdException
protected OperationStatus findAux(O object) throws IllegalIdException, IllegalAccessException, InstantiationException, OBException
object
- The object to search
Status.OK
if the object is found (with the
id) otherwise, Status.NOT_EXISTS
IllegalIdException
IllegalAccessException
InstantiationException
OBException
public Statistics getStats() throws OBStorageException
getStats
in interface Index<O extends OB>
OBStorageException
public void setIdAutoGeneration(boolean auto) throws OBException
OBException
public OperationStatus insert(O object) throws OBStorageException, OBException, IllegalAccessException, InstantiationException
Index
insert
in interface Index<O extends OB>
object
- The object to be added.
Status.OK
if the object was inserted.
Status.EXISTS
if the object existed in the DB.
The method getId() of OperationStatus
will return
the id used by the object.
OBStorageException
- If something goes wrong with the DB
OBException
- User generated exception
IllegalAccessException
- If there is a problem when instantiating objects O
InstantiationException
- If there is a problem when instantiating objects Opublic OperationStatus insertBulk(O object) throws OBStorageException, OBException, IllegalAccessException, InstantiationException
Index
insertBulk
in interface Index<O extends OB>
object
- The object to be added.
Status.OK
OBStorageException
- If something goes wrong with the DB
OBException
- User generated exception
IllegalAccessException
- If there is a problem when instantiating objects O
InstantiationException
- If there is a problem when instantiating objects Opublic OperationStatus insertBulk(O object, long id) throws OBStorageException, OBException, IllegalAccessException, InstantiationException
Index
insertBulk
in interface Index<O extends OB>
object
- The object to be added.id
- The id that will be used for the object.
Status.OK
OBStorageException
- If something goes wrong with the DB
OBException
- User generated exception
IllegalAccessException
- If there is a problem when instantiating objects O
InstantiationException
- If there is a problem when instantiating objects Opublic OperationStatus insert(O object, long id) throws OBStorageException, OBException, IllegalAccessException, InstantiationException
Index
insert
in interface Index<O extends OB>
object
- The object to be added.id
- The id that will be used for the object.
Status.OK
or
Status.EXISTS
then the result will hold
the id of the inserted object and the operation is successful.
Otherwise an exception will be thrown.
OBStorageException
- If something goes wrong with the DB
OBException
- User generated exception
IllegalAccessException
- If there is a problem when instantiating objects O
InstantiationException
- If there is a problem when instantiating objects Oprotected abstract OperationStatus insertAux(long id, O object) throws OBStorageException, OBException, IllegalAccessException, InstantiationException
id
- The id that will be used to insert the object.object
- The object that will be inserted.
Status.OK
or
Status.EXISTS
then the result will hold the
id of the inserted object and the operation is successful.
Otherwise an exception will be thrown.
OBStorageException
OBException
IllegalAccessException
InstantiationException
protected abstract OperationStatus insertAuxBulk(long id, O object) throws OBStorageException, OBException, IllegalAccessException, InstantiationException
id
- The id that will be used to insert the object.object
- The object that will be inserted.
Status.OK
OBStorageException
OBException
IllegalAccessException
InstantiationException
public void freeze() throws AlreadyFrozenException, IllegalIdException, IllegalAccessException, InstantiationException, OBStorageException, OutOfRangeException, OBException, PivotsUnavailableException, IOException
Index
freeze
in interface Index<O extends OB>
PivotsUnavailableException
IOException
AlreadyFrozenException
- If the index was already frozen and the user attempted to
freeze it again
IllegalIdException
- This exception is left as a Debug flag. If you receive
this exception please report the problem to:
http://code.google.com/p/obsearch/issues/list
IllegalAccessException
- If there is a problem when instantiating objects O
InstantiationException
- If there is a problem when instantiating objects O
OBStorageException
- If something goes wrong with the DB
OutOfRangeException
- If the distance of any object to any other object exceeds
the range defined by the user.
OBException
- User generated exceptionIndex.freeze()
public long getBox(O object) throws OBException
Index
getBox
in interface Index<O extends OB>
object
- The object to be analyzed
OBException
- User generated exceptionpublic boolean isFrozen()
Index
isFrozen
in interface Index<O extends OB>
public void resetStats()
Index
resetStats
in interface Index<O extends OB>
public long totalBoxes()
Index
totalBoxes
in interface Index<O extends OB>
protected byte[][] serializePivots(long[] ids) throws IllegalIdException, IllegalAccessException, InstantiationException, OBException
ids
- Objects that will be loaded
OBException
InstantiationException
IllegalAccessException
IllegalIdException
public O[] emptyPivotsArray(int size)
#pivotsCount
.protected O[] loadPivots(byte[][] serializedPivots) throws IllegalIdException, OBException, InstantiationException, IllegalAccessException
IllegalIdException
OBException
InstantiationException
IllegalAccessException
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |