Package nxt.db

Class FullTextTrigger

  • All Implemented Interfaces:
    TransactionalDb.TransactionCallback, org.h2.api.Trigger

    public class FullTextTrigger
    extends java.lang.Object
    implements org.h2.api.Trigger, TransactionalDb.TransactionCallback
    FullTextTrigger provides Lucene search support. Each searchable database has a database trigger defined. The Lucene index is updated whenever a row is inserted, updated or deleted. The DB_ID column is used to identify each row and will be returned as the COLUMNS and KEYS values in the search results. Schema, table and column names are converted to uppercase to match the way H2 stores the information. Function aliases and triggers are created in the default schema (PUBLIC). The database aliases are defined as follows: CREATE ALIAS FTL_CREATE_INDEX FOR "nxt.db.FullTextTrigger.createIndex" CALL FTL_CREATE(schema, table, columnList) CREATE ALIAS FTL_DROP_INDEX FOR "nxt.db.FullTextTrigger.dropIndex" CALL FTL_DROP(schema, table) CREATE ALIAS FTL_SEARCH FOR "nxt.db.FullTextTrigger.search" CALL FTL_SEARCH(schema, table, query, limit, offset) FTL_CREATE_INDEX is called to create a fulltext index for a table. It is provided as a convenience for use in NxtDbVersion when creating a new index after the database has been created. FTL_DROP_INDEX is called to drop a fulltext index for a table. It is provided as a convenience for use in NxtDbVersion when dropping a table after the database has been created. FTL_SEARCH is used to return the search result set as part of a SELECT statement. The result set columns are the following: SCHEMA - the schema name (String) TABLE - the table name (String) COLUMNS - the primary key columns (String[]) - this is always DB_ID for NRS KEYS - the primary key values (Long[]) - DB_ID value for the row SCORE - the search hit score (Float) The table index trigger is defined as follows: CREATE TRIGGER trigger_name AFTER INSERT,UPDATE,DELETE ON table_name FOR EACH ROW CALL "nxt.db.FullTextTrigger"
    • Field Summary

      • Fields inherited from interface org.h2.api.Trigger

        DELETE, INSERT, SELECT, UPDATE
    • Constructor Summary

      Constructors 
      Constructor Description
      FullTextTrigger()  
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void close()
      Close the trigger (Trigger interface)
      void commit()
      Commit the table changes for the current transaction (TransactionCallback interface)
      static void createIndex​(java.sql.Connection conn, java.lang.String schema, java.lang.String table, java.lang.String columnList)
      Create the fulltext index for a table
      static void dropAll​(java.sql.Connection conn)
      Drop all fulltext indexes
      static void dropIndex​(java.sql.Connection conn, java.lang.String schema, java.lang.String table)
      Drop the fulltext index for a table
      void fire​(java.sql.Connection conn, java.lang.Object[] oldRow, java.lang.Object[] newRow)
      Trigger has fired (Trigger interface)
      static void init()
      Initialize the fulltext support for a new database This method should be called from NxtDbVersion when performing the database version update that enables NRS fulltext search support
      void init​(java.sql.Connection conn, java.lang.String schema, java.lang.String trigger, java.lang.String table, boolean before, int type)
      Initialize the trigger (Trigger interface)
      static void reindex​(java.sql.Connection conn)
      Reindex all of the indexed tables
      void remove()
      Remove the trigger (Trigger interface)
      void rollback()
      Discard the table changes for the current transaction (TransactionCallback interface)
      static java.sql.ResultSet search​(java.sql.Connection conn, java.lang.String schema, java.lang.String table, java.lang.String queryText, int limit, int offset)
      Search the Lucene index The result set will have the following columns: SCHEMA - Schema name (String) TABLE - Table name (String) COLUMNS - Primary key column names (String[]) - this is always DB_ID KEYS - Primary key values (Long[]) - this is always the DB_ID value for the table row SCORE - Lucene score (Float)
      static void setActive​(boolean active)
      This method is called by NRS initialization to indicate NRS is active.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • FullTextTrigger

        public FullTextTrigger()
    • Method Detail

      • setActive

        public static void setActive​(boolean active)
        This method is called by NRS initialization to indicate NRS is active. This is required since database triggers will be initialized when the database is opened outside the NRS environment (for example, from the H2 console) The database triggers cannot be re-activated after they have been deactivated.
        Parameters:
        active - TRUE to enable database triggers
      • init

        public static void init()
        Initialize the fulltext support for a new database This method should be called from NxtDbVersion when performing the database version update that enables NRS fulltext search support
      • reindex

        public static void reindex​(java.sql.Connection conn)
                            throws java.sql.SQLException
        Reindex all of the indexed tables
        Parameters:
        conn - SQL connection
        Throws:
        java.sql.SQLException - Unable to reindex tables
      • createIndex

        public static void createIndex​(java.sql.Connection conn,
                                       java.lang.String schema,
                                       java.lang.String table,
                                       java.lang.String columnList)
                                throws java.sql.SQLException
        Create the fulltext index for a table
        Parameters:
        conn - SQL connection
        schema - Schema name
        table - Table name
        columnList - Indexed column names separated by commas
        Throws:
        java.sql.SQLException - Unable to create fulltext index
      • dropIndex

        public static void dropIndex​(java.sql.Connection conn,
                                     java.lang.String schema,
                                     java.lang.String table)
                              throws java.sql.SQLException
        Drop the fulltext index for a table
        Parameters:
        conn - SQL connection
        schema - Schema name
        table - Table name
        Throws:
        java.sql.SQLException - Unable to drop fulltext index
      • dropAll

        public static void dropAll​(java.sql.Connection conn)
                            throws java.sql.SQLException
        Drop all fulltext indexes
        Parameters:
        conn - SQL connection
        Throws:
        java.sql.SQLException - Unable to drop fulltext indexes
      • search

        public static java.sql.ResultSet search​(java.sql.Connection conn,
                                                java.lang.String schema,
                                                java.lang.String table,
                                                java.lang.String queryText,
                                                int limit,
                                                int offset)
                                         throws java.sql.SQLException
        Search the Lucene index The result set will have the following columns: SCHEMA - Schema name (String) TABLE - Table name (String) COLUMNS - Primary key column names (String[]) - this is always DB_ID KEYS - Primary key values (Long[]) - this is always the DB_ID value for the table row SCORE - Lucene score (Float)
        Parameters:
        conn - SQL connection
        schema - Schema name
        table - Table name
        queryText - Query expression
        limit - Number of rows to return
        offset - Offset with result set
        Returns:
        Search results
        Throws:
        java.sql.SQLException - Unable to search the index
      • init

        public void init​(java.sql.Connection conn,
                         java.lang.String schema,
                         java.lang.String trigger,
                         java.lang.String table,
                         boolean before,
                         int type)
                  throws java.sql.SQLException
        Initialize the trigger (Trigger interface)
        Specified by:
        init in interface org.h2.api.Trigger
        Parameters:
        conn - Database connection
        schema - Database schema name
        trigger - Database trigger name
        table - Database table name
        before - TRUE if trigger is called before database operation
        type - Trigger type
        Throws:
        java.sql.SQLException - A SQL error occurred
      • close

        public void close()
        Close the trigger (Trigger interface)
        Specified by:
        close in interface org.h2.api.Trigger
      • remove

        public void remove()
        Remove the trigger (Trigger interface)
        Specified by:
        remove in interface org.h2.api.Trigger
      • fire

        public void fire​(java.sql.Connection conn,
                         java.lang.Object[] oldRow,
                         java.lang.Object[] newRow)
        Trigger has fired (Trigger interface)
        Specified by:
        fire in interface org.h2.api.Trigger
        Parameters:
        conn - Database connection
        oldRow - The old row or null
        newRow - The new row or null