Package tkrzw

Class Index

Object
Index

public class Index extends Object
Secondary index interface.
Note:
All operations except for "open" and "close" are thread-safe; Multiple threads can access the same dindex concurrently. You can specify a data structure when you call the "open" method. Every opened index must be closed explicitly by the "close" method to avoid data corruption.
  • Constructor Details

    • Index

      public Index()
      Constructor.
  • Method Details

    • destruct

      public void destruct()
      Destructs the object and releases resources.
      Note:
      The index is closed implicitly if it has not been closed. As long as you close the index explicitly, you don't have to call this method.
    • open

      public Status open(String path, boolean writable, Map<String,String> params)
      Opens an index file.
      Parameters:
      path - A path of the file.
      writable - If true, the file is writable. If false, it is read-only.
      params - Optional parameters. If it is null, it is ignored.
      Returns:
      The result status.
      Note:
      If the path is empty, BabyDBM is used internally, which is equivalent to using the MemIndex class. If the path ends with ".tkt", TreeDBM is used internally, which is equivalent to using the FileIndex class. If the key comparator of the tuning parameter is not set, PairLexicalKeyComparator is set implicitly. Other compatible key comparators are PairLexicalCaseKeyComparator, PairDecimalKeyComparator, PairHexadecimalKeyComparator, and PairRealNumberKeyComparator. Other options can be specified as with DBM::open.
    • open

      public Status open(String path, boolean writable, String params)
      Opens an index file, with a string expression for optional parameters.
      Parameters:
      path - A path of the file.
      writable - If true, the file is writable. If false, it is read-only.
      params - The optional parameter expression in "key=value,key=value" format.
      Returns:
      The result status.
    • open

      public Status open(String path, boolean writable)
      Opens an index file, without optional parameters.
      Parameters:
      path - A path of the file.
      writable - If true, the file is writable. If false, it is read-only.
      Returns:
      The result status.
    • close

      public Status close()
      Closes the index file.
      Returns:
      The result status.
    • contains

      public boolean contains(byte[] key, byte[] value)
      Checks if a record exists or not.
      Parameters:
      key - The key of the record.
      value - The key of the record.
      Returns:
      True if the record exists, or false if not.
    • contains

      public boolean contains(String key, String value)
      Checks if a record exists or not, with string data.
      Parameters:
      key - The key of the record.
      value - The key of the record.
      Returns:
      True if the record exists, or false if not.
    • getValues

      public byte[][] getValues(byte[] key, int max)
      Gets all values of records of a key.
      Parameters:
      key - The key to look for.
      max - The maximum number of values to get. 0 means unlimited.
      Returns:
      All values of the key. An empty array is returned on failure.
    • getValues

      public String[] getValues(String key, int max)
      Gets all values of records of a key, with string data.
      Parameters:
      key - The key to look for.
      max - The maximum number of values to get. 0 means unlimited.
      Returns:
      All values of the key. An empty array is returned on failure.
    • add

      public Status add(byte[] key, byte[] value)
      Adds a record.
      Parameters:
      key - The key of the record. This can be an arbitrary expression to search the index.
      value - The value of the record. This should be a primary value of another database.
      Returns:
      The result status.
    • add

      public Status add(String key, String value)
      Adds a record, with string data.
      Parameters:
      key - The key of the record. This can be an arbitrary expression to search the index.
      value - The value of the record. This should be a primary value of another database.
      Returns:
      The result status.
    • remove

      public Status remove(byte[] key, byte[] value)
      Removes a record.
      Parameters:
      key - The key of the record.
      value - The value of the record.
      Returns:
      The result status.
    • remove

      public Status remove(String key, String value)
      Removes a record, with string data.
      Parameters:
      key - The key of the record.
      value - The value of the record.
      Returns:
      The result status.
    • count

      public long count()
      Gets the number of records.
      Returns:
      The number of records, or -1 on failure.
    • getFilePath

      public String getFilePath()
      Gets the path of the index file.
      Returns:
      The file path of the index, or an empty string on failure.
    • clear

      public Status clear()
      Removes all records.
      Returns:
      The result status.
    • rebuild

      public Status rebuild()
      Rebuilds the entire index.
      Returns:
      The result status.
    • synchronize

      public Status synchronize(boolean hard)
      Synchronizes the content of the index to the file system.
      Parameters:
      hard - True to do physical synchronization with the hardware or false to do only logical synchronization with the file system.
      Returns:
      The result status.
    • isOpen

      public boolean isOpen()
      Checks whether the index is open.
      Returns:
      True if the index is open, or false if not.
    • isWritable

      public boolean isWritable()
      Checks whether the index is writable.
      Returns:
      True if the index is writable, or false if not.
    • makeIterator

      public IndexIterator makeIterator()
      Makes an iterator for each record.
      Returns:
      The iterator for each record.
      Note:
      Every iterator should be destructed explicitly by the "destruct" method.
    • toString

      public String toString()
      Gets a string representation of the index.
      Overrides:
      toString in class Object