Package jade.domain

Class DFDBKB

  • Direct Known Subclasses:
    DFHSQLKB

    public class DFDBKB
    extends DBKB
    This class implements a knowledge base used by the DF which stores its content in an external database.
    Author:
    Elisabetta Cortese - TILab, Roland Mungenast - Profactor
    • Field Detail

      • DEFAULT_LONGVARCHAR_TYPE

        protected String DEFAULT_LONGVARCHAR_TYPE
        Default data type for very long strings
    • Constructor Detail

      • DFDBKB

        public DFDBKB​(int maxResultLimit,
                      String drv,
                      String url,
                      String user,
                      String passwd,
                      boolean cleanTables)
               throws SQLException
        Constructor
        Parameters:
        maxResultLimit - internal limit for the number of maximum search results.
        drv - database driver
        url - database URL
        user - database user name
        passwd - database password
        cleanTables - specifies whether the KB should delete all existing tables for the DF at startup
        Throws:
        SQLException - an error occured while opening a connection to the database
    • Method Detail

      • setup

        public void setup()
                   throws SQLException
        Initializes all used SQL statements, the DB tables and the logging
        Specified by:
        setup in class DBKB
        Throws:
        SQLException
      • getLongVarCharType

        protected String getLongVarCharType()
        Returns the name of the SQL type used in the database to represent very long strings.
      • getGUID

        protected String getGUID()
        Returns a global unique identifier
      • dropTable

        protected void dropTable​(Statement stmt,
                                 String tableName)
        Drops a DB table or does nothing if the table doesn't exist.
      • dropDFTables

        protected void dropDFTables()
                             throws SQLException
        Drops all existing DB tables used by the DF.
        Throws:
        SQLException
      • tableExists

        protected boolean tableExists​(String name)
        Check whether a database table already exists
        Parameters:
        name - name of the table
      • createTable

        protected void createTable​(String name,
                                   String[] entries)
        Creates a new DB table
        Parameters:
        name - name of the table
        entries - array of column and constraint specifications
        Throws:
        SQLException - If the table cannot be created
      • createIndices

        protected void createIndices()
        Adds explicit indices to the database to speed up queries
      • createDFTables

        protected void createDFTables()
        Creates the proper DB tables.
      • getSubscriptions

        public Enumeration getSubscriptions()
        Return all known subscriptions at the DF
        Specified by:
        getSubscriptions in class DBKB
        Returns:
        Enumeration with instances of the class jade.proto.SubscriptionResponder&Subscription
      • getHashValue

        protected String getHashValue​(Object obj)
                               throws Exception
        Returns an MD5 hash value for an object
        Parameters:
        obj - Object to use for the hash value calcualtion
        Returns:
        an MD5 value encoded in ISO-8859-1
        Throws:
        Exception - The hash value couldn't be generated
      • prepDBStr

        protected String prepDBStr​(String s)
        This method must be used when inserting text values into a DB. It doubles all ' and " characters If the passed parameter is null, then an empty string is returned.
      • replace

        protected String replace​(String str,
                                 String pattern,
                                 String replaceWith)
        Replaces all occurences of a pattern in str with replaceWith
        Parameters:
        str - source string
        pattern - pattern string to search for
        replaceWith - new string