Package adams.db

Class AbstractIndexedTable

    • Field Detail

      • m_init

        protected boolean m_init
        has this object been initialised.
    • Constructor Detail

      • AbstractIndexedTable

        protected AbstractIndexedTable​(AbstractDatabaseConnection dbcon,
                                       String tableName)
        Constructor.
        Parameters:
        dbcon - the database context this table is used in
        tableName - the name of the table
    • Method Detail

      • getIndices

        protected abstract Indices getIndices()
        Implement this method to return required indices for this table.
        Returns:
        Indices
      • getColumnMapping

        protected abstract ColumnMapping getColumnMapping()
        Implement this method to return column names and data types.
        Returns:
        Column Mapping
      • getAllColumns

        public String getAllColumns()
        Returns the SELECT part with all columns listed.
        Returns:
        the SELECT part
      • columnsMatchTest

        protected boolean columnsMatchTest​(ColumnMapping cm,
                                           boolean print,
                                           boolean tryAgain,
                                           boolean addMissing)
        Determine if columns (name & datatype) of table match table specification.
        Parameters:
        cm - the column mapping to use
        print - whether to print error messages etc
        tryAgain - whether to try again
        addMissing - whether to add the missing columns (if possible)
        Returns:
        columns match?
      • columnsMatch

        protected boolean columnsMatch​(ColumnMapping cm,
                                       boolean print,
                                       boolean addMissing)
        Determine if columns (name & datatype) of table match table specification.
        Parameters:
        cm - the column mapping to use
        print - whether to print error messages etc
        addMissing - whether to add missing columns if possible
        Returns:
        columns match?
      • init

        public boolean init()
        Initialise table. Create if necessary, else compare with spec.
        Specified by:
        init in class AbstractTable
        Returns:
        success?
      • create

        protected boolean create()
        Create the table in database according to column and index specs.
        Returns:
        success?
      • postCreate

        protected boolean postCreate()
        Optional post-create hook for filling the table with initial values. The default implementation does nothing and just returns true.
        Returns:
        true if successfully run
      • isThere

        public boolean isThere​(String condition)
        Returns true if this table holds data that satisfies 'condition'.
        Parameters:
        condition - boolean SQL eg "JOBNO=100 AND SAMPLENO=2"
        Returns:
        true if condition holds for tablename
      • update

        public int update​(String updateString,
                          String where)
                   throws Exception
        Update table.
        Parameters:
        updateString - comma separated updates. e.g weight='80',height=180
        where - condition. e.g name='bob smith'
        Returns:
        number of rows affected
        Throws:
        Exception - if something goes wrong
      • truncate

        public boolean truncate()
        Empty table.
        Returns:
        success?
      • select

        public ResultSet select​(String columns)
                         throws Exception
        Do a select on given columns for all data in table.
        Parameters:
        columns - comma separated column list
        Returns:
        resulset of data
        Throws:
        Exception - if something goes wrong
      • select

        public ResultSet select​(String columns,
                                String where)
                         throws Exception
        Do a select on given columns for all data in table, with condition.
        Parameters:
        columns - columns to select
        where - condition
        Returns:
        resultset of data
        Throws:
        Exception - if something goes wrong
      • selectDistinct

        public ResultSet selectDistinct​(String columns)
                                 throws Exception
        Do a select distinct on given columns for all data in table, with condition.
        Parameters:
        columns - columns to select
        Returns:
        resultset of data
        Throws:
        Exception - if something goes wrong
      • selectDistinct

        public ResultSet selectDistinct​(String columns,
                                        String where)
                                 throws Exception
        Do a select distinct on given columns for all data in table, with condition.
        Parameters:
        columns - columns to select
        where - condition
        Returns:
        resultset of data
        Throws:
        Exception - if something goes wrong
      • getTables

        public static String[] getTables()
        Returns a list with classnames of tables.
        Returns:
        the table classnames
      • initTables

        public static void initTables​(AbstractDatabaseConnection dbcon)
        Initializes all tables.
        Parameters:
        dbcon - the database context