Class DbNameIndex

  • All Implemented Interfaces:
    StringIndex
    Direct Known Subclasses:
    NGKDbNameIndex, PostgreSQLNameIndex

    public class DbNameIndex
    extends Object
    implements StringIndex
    Implements a StringIndex that stores and retrieves the names from a table in a database.

    Note that this class is not threadsafe by itself. it needs to be synchronized by the using application.

    Due to a bug with oracle that treats empty strings a null values (see JCR-815), all empty strings are replaced by a ' '. since names never start with a space, this it not problematic yet.

    • Field Detail

      • nameSelectSQL

        protected String nameSelectSQL
      • indexSelectSQL

        protected String indexSelectSQL
      • nameInsertSQL

        protected String nameInsertSQL
    • Constructor Detail

    • Method Detail

      • init

        protected void init​(String schemaObjectPrefix)
                     throws SQLException
        Inits this index and prepares the statements.
        Parameters:
        schemaObjectPrefix - the prefix for table names
        Throws:
        SQLException - if the statements cannot be prepared.
      • close

        public void close()
        Closes this index and releases it's resources.
      • stringToIndex

        public int stringToIndex​(String string)
        Returns the index for a given string. If the given string is not already indexed, the implementation can either automatically index it or throw an exception.
        Specified by:
        stringToIndex in interface StringIndex
        Parameters:
        string - the indexed (or to be indexed) string
        Returns:
        index of the string
      • insertString

        protected int insertString​(String string)
        Inserts a string into the database and returns the new index.
        Parameters:
        string - the string to insert
        Returns:
        the new index.
      • getIndex

        protected int getIndex​(String string)
        Retrieves the index from the database for the given string.
        Parameters:
        string - the string to retrieve the index for
        Returns:
        the index or -1 if not found.