gov.nih.nlm.nls.dbm
Class UncommonJDbm

java.lang.Object
  extended bygov.nih.nlm.nls.dbm.UncommonJDbm
All Implemented Interfaces:
JDbmInterface

public class UncommonJDbm
extends java.lang.Object
implements JDbmInterface

UncommonJDbmDbm is an implementation of Russell Loane's newer Store package. It is a primitive file based store mechanism designed to be as fast as possible. This class includes methods that can handle WRITE_ONLY and READ_WRITE modes. Please note that any method that performs a write needs to be in a single threaded environment, or in an environment where only one thread has the handle to to the file during this task. This class does not include the syncronization gateways. It is up to those who use this class. Tue Dec 04 12:00:16 EST 2001, divita Initial Version


Constructor Summary
UncommonJDbm(java.lang.String pFileName, int pMode)
          This is a constructor for StoreJDbm.
 
Method Summary
 java.util.ArrayList beginsWith(java.lang.String pKey)
          Method beginsWith [TBD]
 java.util.ArrayList beginsWithWord(java.lang.String pString)
          Method beginsWithWord [TBD]
 void close()
          Method close closes the db.
 java.util.Enumeration elements()
          Method elements [TBD]
 int get(long pRowId)
          Method get retrieves an int from the datastore using an int as the key This method returns a -1 if nothing was found.
 byte[] getBytes(int pRowId)
          Method getBytes
 byte[] getBytes(java.lang.String pRowId)
          Method getBytes
 int getInt(java.lang.String pKey)
          Method getInt gets an int back from the datastore, using a string as the key This method will return -1 if nothing is found.
 int[] getInts(int pKey)
          Method getInts retrieves an array of ints from the datastore using an int as the key
 int[] getInts(java.lang.String pKey)
          Method getInts retrieves an array of ints from the datastore using a string as the key
 int[] getNonUniqInts(java.lang.String pKey)
          Method getNonUniqInts retrieves an array of ints from the datastore using a string as the key
 long getNumberOfRecords()
          Method getNumberOfRecords retrieves the number of records from the table that is keyed by a record id.
 long getNumberOfStringKeyedRows()
          Method getNumberOfStringKeyedRows retrieves the number of rows in the table that contains strings as keys.
 java.lang.Object getObject(int pRowId)
          Method getObject
 java.lang.Object getObject(java.lang.String pRowId)
          Method getObject
 java.lang.String getString(int pRowId)
          Method getString retrieves UTF-8 Strings from the datastore using an int as the key
 java.lang.String getString(java.lang.String pKey)
          Method getString retrieves from the datastore using a String as the key
 java.lang.String[] getStrings(java.lang.String pKey)
          Method getStrings retrieves an array of Strings from the datastore using a string as the key
 java.util.Iterator keyIterator()
          Method keyIterator [TBD]
 java.util.Enumeration keys()
          Method keys [TBD]
 void open(java.lang.String pFileName)
          Method open opens the database
 void put(int pKey, int pValue)
          Method put
 void put(java.lang.String pKey, int pValue)
          Method put
 void put(java.lang.String pKey, java.lang.String pValue)
          Method put
 void putAString(java.lang.String pKey, java.lang.String pValue)
          Method putAString
 void putBytes(int pKey, byte[] pValue)
          Method putBytes
 void putBytes(java.lang.String pKey, byte[] pValue)
          Method putBytes
 void putInts(int pKey, int[] pValue)
          Method putInts
 void putInts(java.lang.String pKey, int[] pValue)
          Method putInts
 void putNonUniqInts(java.lang.String pKey, int pValue)
          Method putNonUniqInts.
 void putObject(int pKey, java.lang.Object pValue)
          Method putObject
 void putObject(java.lang.String pKey, java.lang.Object pValue)
          Method putObject
 void putString(int pRowId, java.lang.String pValue)
          Method putString
 void putStrings(java.lang.String pKey, java.lang.String[] pValue)
          Method putStrings[]
 void reorganize()
          Method reorganize reorganizes the db into an optimized or balanced btree and does a save as a side effect.
 void save()
          Method save writes out the current state to disk.
 byte[] serializeObject(java.lang.Object pObject)
          Method serializeObject
 void setDbType(int pDbType)
          Method setDbType set's whether the index will be all loaded into memory, partially loaded into memory or will be all kept on disk.
 java.lang.Object unSerializeObject(byte[] pBytes)
          Method unSerializeObject
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

UncommonJDbm

public UncommonJDbm(java.lang.String pFileName,
                    int pMode)
             throws java.lang.Exception
This is a constructor for StoreJDbm.

Parameters:
pFileName -
pMode - JDBM.WRITE_ONLY|JDBM.READ_WRITE|JDBM.READ_ONLY
Throws:
java.lang.Exception
Method Detail

setDbType

public void setDbType(int pDbType)
Method setDbType set's whether the index will be all loaded into memory, partially loaded into memory or will be all kept on disk. By default, the dbType is set to kMixedLocation. This is just for the uncommon implementation of the dbm package.

Parameters:
pDbType - SingleStoreFactory.kDiskLocation|kMixedLocation|kRAMLocation

open

public void open(java.lang.String pFileName)
          throws java.lang.Exception
Method open opens the database

Specified by:
open in interface JDbmInterface
Parameters:
pFileName -
Throws:
java.lang.Exception

close

public void close()
           throws java.lang.Exception
Method close closes the db. This method does do a flush and a save before closing when opened with write modes.

Specified by:
close in interface JDbmInterface
Throws:
java.lang.Exception

save

public void save()
          throws java.lang.Exception
Method save writes out the current state to disk. This does not close the db, but makes sure the current state is saved.

Specified by:
save in interface JDbmInterface
Throws:
java.lang.Exception

reorganize

public void reorganize()
                throws java.lang.Exception
Method reorganize reorganizes the db into an optimized or balanced btree and does a save as a side effect. This method is useful when you've done some substantial number of updates where the underlying tree could get out of balance. This method does not apply to this implementation

Specified by:
reorganize in interface JDbmInterface
Throws:
java.lang.Exception

putObject

public void putObject(java.lang.String pKey,
                      java.lang.Object pValue)
               throws java.lang.Exception
Method putObject

Specified by:
putObject in interface JDbmInterface
Parameters:
pKey -
pValue -
Throws:
java.lang.Exception

putBytes

public void putBytes(java.lang.String pKey,
                     byte[] pValue)
              throws java.lang.Exception
Method putBytes

Specified by:
putBytes in interface JDbmInterface
Parameters:
pKey -
pValue -
Throws:
java.lang.Exception

putBytes

public void putBytes(int pKey,
                     byte[] pValue)
              throws java.lang.Exception
Method putBytes

Specified by:
putBytes in interface JDbmInterface
Parameters:
pKey -
pValue -
Throws:
java.lang.Exception

put

public void put(java.lang.String pKey,
                java.lang.String pValue)
         throws java.lang.Exception
Method put

Specified by:
put in interface JDbmInterface
Parameters:
pKey -
pValue -
Throws:
java.lang.Exception

putObject

public void putObject(int pKey,
                      java.lang.Object pValue)
               throws java.lang.Exception
Method putObject

Specified by:
putObject in interface JDbmInterface
Parameters:
pKey -
pValue -
Throws:
java.lang.Exception

put

public void put(int pKey,
                int pValue)
         throws java.lang.Exception
Method put

Specified by:
put in interface JDbmInterface
Parameters:
pKey -
pValue -
Throws:
java.lang.Exception

putInts

public void putInts(java.lang.String pKey,
                    int[] pValue)
             throws java.lang.Exception
Method putInts

Specified by:
putInts in interface JDbmInterface
Parameters:
pKey -
pValue -
Throws:
java.lang.Exception

putInts

public void putInts(int pKey,
                    int[] pValue)
             throws java.lang.Exception
Method putInts

Specified by:
putInts in interface JDbmInterface
Parameters:
pKey -
pValue -
Throws:
java.lang.Exception

putStrings

public void putStrings(java.lang.String pKey,
                       java.lang.String[] pValue)
                throws java.lang.Exception
Method putStrings[]

Specified by:
putStrings in interface JDbmInterface
Parameters:
pKey -
pValue -
Throws:
java.lang.Exception

putAString

public void putAString(java.lang.String pKey,
                       java.lang.String pValue)
                throws java.lang.Exception
Method putAString

Specified by:
putAString in interface JDbmInterface
Parameters:
pKey -
pValue -
Throws:
java.lang.Exception

putNonUniqInts

public void putNonUniqInts(java.lang.String pKey,
                           int pValue)
                    throws java.lang.Exception
Method putNonUniqInts. Since we cannot do a read when writing out, this index is going to have to be built in memory,and written out when the file gets closed. Note: This method is a write-only method.

Specified by:
putNonUniqInts in interface JDbmInterface
Parameters:
pKey -
pValue -
Throws:
java.lang.Exception

putString

public void putString(int pRowId,
                      java.lang.String pValue)
               throws java.lang.Exception
Method putString

Specified by:
putString in interface JDbmInterface
Parameters:
pRowId -
pValue -
Throws:
java.lang.Exception

put

public void put(java.lang.String pKey,
                int pValue)
         throws java.lang.Exception
Method put

Specified by:
put in interface JDbmInterface
Parameters:
pKey -
pValue -
Throws:
java.lang.Exception

getObject

public java.lang.Object getObject(java.lang.String pRowId)
                           throws java.lang.Exception
Method getObject

Specified by:
getObject in interface JDbmInterface
Parameters:
pRowId -
Returns:
Object
Throws:
java.lang.Exception

getBytes

public byte[] getBytes(java.lang.String pRowId)
                throws java.lang.Exception
Method getBytes

Specified by:
getBytes in interface JDbmInterface
Parameters:
pRowId -
Returns:
byte[]
Throws:
java.lang.Exception

getBytes

public byte[] getBytes(int pRowId)
                throws java.lang.Exception
Method getBytes

Specified by:
getBytes in interface JDbmInterface
Parameters:
pRowId -
Returns:
byte[]
Throws:
java.lang.Exception

getInt

public int getInt(java.lang.String pKey)
           throws java.lang.Exception
Method getInt gets an int back from the datastore, using a string as the key This method will return -1 if nothing is found.

Specified by:
getInt in interface JDbmInterface
Parameters:
pKey -
Returns:
int
Throws:
java.lang.Exception

getObject

public java.lang.Object getObject(int pRowId)
                           throws java.lang.Exception
Method getObject

Specified by:
getObject in interface JDbmInterface
Parameters:
pRowId -
Returns:
Object
Throws:
java.lang.Exception

getInts

public int[] getInts(java.lang.String pKey)
              throws java.lang.Exception
Method getInts retrieves an array of ints from the datastore using a string as the key

Specified by:
getInts in interface JDbmInterface
Parameters:
pKey -
Returns:
int[]
Throws:
java.lang.Exception

getInts

public int[] getInts(int pKey)
              throws java.lang.Exception
Method getInts retrieves an array of ints from the datastore using an int as the key

Specified by:
getInts in interface JDbmInterface
Parameters:
pKey -
Returns:
int[]
Throws:
java.lang.Exception

getStrings

public java.lang.String[] getStrings(java.lang.String pKey)
                              throws java.lang.Exception
Method getStrings retrieves an array of Strings from the datastore using a string as the key

Specified by:
getStrings in interface JDbmInterface
Parameters:
pKey -
Returns:
String[]
Throws:
java.lang.Exception

getNonUniqInts

public int[] getNonUniqInts(java.lang.String pKey)
                     throws java.lang.Exception
Method getNonUniqInts retrieves an array of ints from the datastore using a string as the key

Specified by:
getNonUniqInts in interface JDbmInterface
Parameters:
pKey -
Returns:
int[]
Throws:
java.lang.Exception

get

public int get(long pRowId)
        throws java.lang.Exception
Method get retrieves an int from the datastore using an int as the key This method returns a -1 if nothing was found.

Specified by:
get in interface JDbmInterface
Parameters:
pRowId - ( (long) needs to be distinguished from the other get(int) signature)
Returns:
int
Throws:
java.lang.Exception

getString

public java.lang.String getString(int pRowId)
                           throws java.lang.Exception
Method getString retrieves UTF-8 Strings from the datastore using an int as the key

Specified by:
getString in interface JDbmInterface
Parameters:
pRowId -
Returns:
String pValue
Throws:
java.lang.Exception

getString

public java.lang.String getString(java.lang.String pKey)
                           throws java.lang.Exception
Method getString retrieves from the datastore using a String as the key

Specified by:
getString in interface JDbmInterface
Parameters:
pKey -
Returns:
String pValue
Throws:
java.lang.Exception

elements

public java.util.Enumeration elements()
                               throws java.lang.Exception
Method elements [TBD]

Specified by:
elements in interface JDbmInterface
Returns:
Enumeration
Throws:
java.lang.Exception

keys

public java.util.Enumeration keys()
                           throws java.lang.Exception
Method keys [TBD]

Specified by:
keys in interface JDbmInterface
Returns:
Enumeration
Throws:
java.lang.Exception

keyIterator

public java.util.Iterator keyIterator()
                               throws java.lang.Exception
Method keyIterator [TBD]

Specified by:
keyIterator in interface JDbmInterface
Returns:
Iterator
Throws:
java.lang.Exception

getNumberOfRecords

public long getNumberOfRecords()
Method getNumberOfRecords retrieves the number of records from the table that is keyed by a record id. (from the IntStringStore)

Specified by:
getNumberOfRecords in interface JDbmInterface
Returns:
int

getNumberOfStringKeyedRows

public long getNumberOfStringKeyedRows()
Method getNumberOfStringKeyedRows retrieves the number of rows in the table that contains strings as keys. (from the StringInt store )

Specified by:
getNumberOfStringKeyedRows in interface JDbmInterface
Returns:
int

beginsWith

public java.util.ArrayList beginsWith(java.lang.String pKey)
                               throws java.lang.Exception
Method beginsWith [TBD]

Specified by:
beginsWith in interface JDbmInterface
Parameters:
pKey -
Returns:
ArrayList
Throws:
java.lang.Exception

beginsWithWord

public java.util.ArrayList beginsWithWord(java.lang.String pString)
                                   throws java.lang.Exception
Method beginsWithWord [TBD]

Specified by:
beginsWithWord in interface JDbmInterface
Parameters:
pString -
Returns:
ArrayList (Of Objects)
Throws:
java.lang.Exception

serializeObject

public byte[] serializeObject(java.lang.Object pObject)
                       throws java.lang.Exception
Method serializeObject

Parameters:
pObject -
Returns:
byte[]
Throws:
java.lang.Exception

unSerializeObject

public java.lang.Object unSerializeObject(byte[] pBytes)
                                   throws java.lang.Exception
Method unSerializeObject

Parameters:
pBytes -
Returns:
Object
Throws:
java.lang.Exception


The use and distribution of this material is subject to the terms and conditions included in the file SPECIALIST_NLP_TOOLS_TERMS_AND_CONDITIONS.TXT, located in the root directory of the distribution.