Class JDBCDictionary

  • All Implemented Interfaces:
    Dictionary

    public class JDBCDictionary
    extends Object
    implements Dictionary
    Provides a Dictionary backed by a database table.
    Author:
    Middleware Services
    • Field Detail

      • dataSource

        protected DataSource dataSource
        JDBC data source.
      • searchStatement

        protected String searchStatement
        SQL search statement.
      • sizeStatement

        protected String sizeStatement
        SQL size statement.
    • Constructor Detail

      • JDBCDictionary

        public JDBCDictionary​(DataSource source,
                              String searchSql,
                              String sizeSql)
        Creates a new JDBC dictionary.
        Parameters:
        source - connection data source
        searchSql - prepared statement to query for words; first parameter is the word
        sizeSql - prepared statement to query for size; no parameters are provided
    • Method Detail

      • search

        public boolean search​(String word)
        Description copied from interface: Dictionary
        Returns whether the supplied word exists in the dictionary.
        Specified by:
        search in interface Dictionary
        Parameters:
        word - to search for
        Returns:
        whether word was found
      • size

        public long size()
        Description copied from interface: Dictionary
        Returns the number of words in this dictionary
        Specified by:
        size in interface Dictionary
        Returns:
        total number of words to search
      • executeStatement

        protected <T> T executeStatement​(String statement,
                                         Class<T> type,
                                         Object... params)
                                  throws SQLException
        Executes a prepared statement against the database. Only the first result is returned.
        Type Parameters:
        T - return type
        Parameters:
        statement - to execute
        type - of object to return
        params - to set on the prepared statement
        Returns:
        first result of the prepared statement
        Throws:
        SQLException - if the statement execution fails
      • getConnection

        protected Connection getConnection()
                                    throws SQLException
        Returns a connection that is ready for use.
        Returns:
        database connection.
        Throws:
        SQLException - if a connection is not available