Class IndexedObjectDatabase
IndexedObjectDatabase
class provides a mechanism for
using a key value to an object serialized to a file.
A IndexedObjectDatabase
object encapsulates access to a
ObjectDatabaseFile
via a set of ObjectIndex
s.
When an object is stored, it is associated with a key value by storing the
key and an object reference in each attached ObjectIndex
.
Objects may then be retrieved either by providing a key and index pair,
or through an iterator created for an index associated with the database.
Rationale
: The Java Database Connection (JDBC) is
often overkill for many applications. Sun designed JDBC to access
enterprise-level database systems, such as DB2, SQL Server, and Oracle.
Those systems, while very flexible and expansive, come with a high
price tag, both in terms of system requirements and database overhead.
BTreeDatabase
provides a simpler tool for associating
"key" information with data in external storage.
- See Also:
-
Field Summary
Fields inherited from class com.coyotegulch.jisp.ObjectDatabaseFile
DEL_LIST_END, IS_ACTIVE, IS_DELETED, m_dataFile, m_fileName, m_filter, m_firstDeleted
-
Constructor Summary
ConstructorsConstructorDescriptionIndexedObjectDatabase
(String filename, boolean is_new) Opens an existingIndexedObjectDatabase
, using a supplied file name. -
Method Summary
Modifier and TypeMethodDescriptionvoid
attachIndex
(ObjectIndex index) Attaches an index object to this database.void
insert
(KeyObject[] key, Serializable obj) Write a new object to the database, associating it with the provided keys.read
(IndexIterator iterator) Read the object associated with a given iterator.read
(KeyObject key, ObjectIndex index) Read the object associated with a given key.void
Delete the record associated with a given key.void
removeIndex
(ObjectIndex index) Removes the association of an index with this database.void
write
(KeyObject[] key, Serializable obj) Writes an object to the database, associating it with the provided key, replacing an existing object with a new one.Methods inherited from class com.coyotegulch.jisp.ObjectDatabaseFile
assignFilter, close, compact, createObjectInputStream, createObjectOutputStream, delete, getFD, getFilePointer, length, readObject, rewind, rewriteObject, seek, skip, writeObject
-
Constructor Details
-
IndexedObjectDatabase
Opens an existingIndexedObjectDatabase
, using a supplied file name.- Parameters:
filename
- The name of an external database file containing serialized objects. Iffilename
exists, it is opened; otherwise, the constructor creates the file and initializes it.- Throws:
IOException
- when an I/O exception is thrown by an underlying java.io.* class
-
-
Method Details
-
attachIndex
Attaches an index object to this database. This index will be updated for every object recorded in the database.- Parameters:
index
- AnObjectIndex
to be associated with this database.- See Also:
-
removeIndex
Removes the association of an index with this database. The index will no longer be updated for objects recorded in the database.- Parameters:
index
- AnObjectIndex
that should no longer be associated with this database.- See Also:
-
insert
Write a new object to the database, associating it with the provided keys.- Parameters:
key
- The key values associated withobj
. There must be one key for each attached index; the keys are associated with the indexes in order of attachment; in other words, the first key is associated with the first index attached, etc.obj
- The object to be stored in the database.- Throws:
IOException
- when an I/O exception is thrown by an underlying java.io.* classClassNotFoundException
- for a casting error, usually when a persistent object or index does match the expected typeDatabaseException
- when an error occurs during database processing- See Also:
-
write
Writes an object to the database, associating it with the provided key, replacing an existing object with a new one.- Parameters:
key
- key values associated withobj
. There must be one key for each attached index; the keys are associated with the indexes in order of attachment; in other words, the first key is associated with the first index attached, etc.obj
- record object to be stored in the database.- Throws:
IOException
- when an I/O exception is thrown by an underlying java.io.* classClassNotFoundException
- for a casting error, usually when a persistent object or index does match the expected typeDatabaseException
- when an error occurs during database processing- See Also:
-
read
Read the object associated with a given key.- Parameters:
key
- key identifying the record to be readindex
- index used to retrieve the object bykey
.- Returns:
- The record object associated with
key
, ornull
if no such object could be found. - Throws:
IOException
- when an I/O exception is thrown by an underlying java.io.* classClassNotFoundException
- for a casting error, usually when a persistent object or index does match the expected typeDatabaseException
- when an error occurs during database processing- See Also:
-
read
Read the object associated with a given iterator.- Parameters:
iterator
- aBTreeIterator
pointing to the requested record- Returns:
- The record object associated with
iterator
, ornull
if the iterator was invalid or no such record could be found. - Throws:
IOException
- when an I/O exception is thrown by an underlying java.io.* classClassNotFoundException
- for a casting error, usually when a persistent object or index does match the expected typeDatabaseException
- when an error occurs during database processing- See Also:
-
remove
Delete the record associated with a given key.- Parameters:
key
- array of keys identifying the record to be deleted.index
- index used to retrive the object bykey
.- Throws:
IOException
- when an I/O exception is thrown by an underlying java.io.* classClassNotFoundException
- for a casting error, usually when a persistent object or index does match the expected typeDatabaseException
- when an error occurs during database processing- See Also:
-