Class IndexedObjectDatabase
- java.lang.Object
-
- com.coyotegulch.jisp.ObjectDatabaseFile
-
- com.coyotegulch.jisp.IndexedObjectDatabase
-
public class IndexedObjectDatabase extends ObjectDatabaseFile
TheIndexedObjectDatabaseclass provides a mechanism for using a key value to an object serialized to a file.A
IndexedObjectDatabaseobject encapsulates access to aObjectDatabaseFilevia a set ofObjectIndexs. When an object is stored, it is associated with a key value by storing the key and an object reference in each attachedObjectIndex. 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.BTreeDatabaseprovides a simpler tool for associating "key" information with data in external storage.- See Also:
BTreeIndex,DatabaseException,KeyObject,ObjectIndex
-
-
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
Constructors Constructor Description IndexedObjectDatabase(java.lang.String filename, boolean is_new)Opens an existingIndexedObjectDatabase, using a supplied file name.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidattachIndex(ObjectIndex index)Attaches an index object to this database.voidinsert(KeyObject[] key, java.io.Serializable obj)Write a new object to the database, associating it with the provided keys.java.lang.Objectread(IndexIterator iterator)Read the object associated with a given iterator.java.lang.Objectread(KeyObject key, ObjectIndex index)Read the object associated with a given key.voidremove(KeyObject[] key)Delete the record associated with a given key.voidremoveIndex(ObjectIndex index)Removes the association of an index with this database.voidwrite(KeyObject[] key, java.io.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 Detail
-
IndexedObjectDatabase
public IndexedObjectDatabase(java.lang.String filename, boolean is_new) throws java.io.IOExceptionOpens an existingIndexedObjectDatabase, using a supplied file name.- Parameters:
filename- The name of an external database file containing serialized objects. Iffilenameexists, it is opened; otherwise, the constructor creates the file and initializes it.- Throws:
java.io.IOException- when an I/O exception is thrown by an underlying java.io.* class
-
-
Method Detail
-
attachIndex
public void attachIndex(ObjectIndex index)
Attaches an index object to this database. This index will be updated for every object recorded in the database.- Parameters:
index- AnObjectIndexto be associated with this database.- See Also:
ObjectIndex
-
removeIndex
public void removeIndex(ObjectIndex index)
Removes the association of an index with this database. The index will no longer be updated for objects recorded in the database.- Parameters:
index- AnObjectIndexthat should no longer be associated with this database.- See Also:
ObjectIndex
-
insert
public void insert(KeyObject[] key, java.io.Serializable obj) throws java.io.IOException, java.lang.ClassNotFoundException
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:
java.io.IOException- when an I/O exception is thrown by an underlying java.io.* classjava.lang.ClassNotFoundException- 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:
DatabaseException,KeyObject
-
write
public void write(KeyObject[] key, java.io.Serializable obj) throws java.io.IOException, java.lang.ClassNotFoundException
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:
java.io.IOException- when an I/O exception is thrown by an underlying java.io.* classjava.lang.ClassNotFoundException- 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:
DatabaseException,KeyObject
-
read
public java.lang.Object read(KeyObject key, ObjectIndex index) throws java.io.IOException, java.lang.ClassNotFoundException
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, ornullif no such object could be found. - Throws:
java.io.IOException- when an I/O exception is thrown by an underlying java.io.* classjava.lang.ClassNotFoundException- 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:
DatabaseException,KeyObject
-
read
public java.lang.Object read(IndexIterator iterator) throws java.io.IOException, java.lang.ClassNotFoundException
Read the object associated with a given iterator.- Parameters:
iterator- aBTreeIteratorpointing to the requested record- Returns:
- The record object associated with
iterator, ornullif the iterator was invalid or no such record could be found. - Throws:
java.io.IOException- when an I/O exception is thrown by an underlying java.io.* classjava.lang.ClassNotFoundException- 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:
DatabaseException,BTreeIterator,KeyObject
-
remove
public void remove(KeyObject[] key) throws java.io.IOException, DatabaseException, java.lang.ClassNotFoundException
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:
java.io.IOException- when an I/O exception is thrown by an underlying java.io.* classjava.lang.ClassNotFoundException- 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:
DatabaseException,KeyObject
-
-