Class DBControl

All Implemented Interfaces:
PamSettings, PamSettingsSource, SettingsNameProvider
Direct Known Subclasses:
DBControlSettings, DBControlUnit

public abstract class DBControl extends PamControlledUnit implements PamSettings, PamSettingsSource
Database system for accessing data in just about any type of odbc database.

This gets used in two slightly different ways in Pamguard. The first is the obvious reading and writing of data to a variety of tables. The second is the loading of settings from the PAmguard_settings and the PamguardModules tables tables in which all program settings were serialised and stored as 6 bit ascii strings each time PAMGUARD started collecting data.

So that an instance of DBControl can be made that doesn't load settings, two sub classes have been made: DBContorlUnit for normal use and DBControlSettings for reading in settings information.

Author:
Doug Gillespie
See Also:
  • Field Details

  • Constructor Details

    • DBControl

      public DBControl(PamConfiguration pamconfiguration, String unitName, int settingsStore, boolean openImmediately)
  • Method Details

    • selectSystem

      public boolean selectSystem(Class systemClass, boolean openDatabase, String forcedName)
    • selectSystem

      public boolean selectSystem(int systemNumber, boolean openDatabase)
      Select a database system
      Parameters:
      systemNumber - index of the database system
      openDatabase - flag to immediately open the database
      Returns:
      true if all ok
    • selectSystem

      public boolean selectSystem(int systemNumber, boolean openDatabase, String forcedName)
      Select a database system
      Parameters:
      systemNumber - index of the database system
      openDatabase - flag to immediately open the database
      Returns:
      true if all ok
    • openDatabase

      public boolean openDatabase(String forcedName)
    • getSystem

      public DBSystem getSystem(int systemNumber)
      Get the specified database system.
      Parameters:
      systemNumber - - the index of the system.
      Returns:
      the database systems at the specified index.
    • canClose

      public boolean canClose()
      Description copied from class: PamControlledUnit
      Called before Pamguard shuts down. Rather than returning false, this function can be used as a final oportunity to save settings, write to the database, etc.
      Overrides:
      canClose in class PamControlledUnit
      Returns:
      true if OK for Pamguard to shut down, false otherwise.
    • commitChanges

      public boolean commitChanges()
      Commit any unsaved database changes.
      Returns:
      true if successful. false if no database or exception thrown.
    • pamClose

      public void pamClose()
      Description copied from class: PamControlledUnit
      Called when PAMGUARD is finally closing down so that a module may free any remaining resources (e.g. files or COMM ports).
      Overrides:
      pamClose in class PamControlledUnit
    • browseDatabases

      public String browseDatabases(Component parent)
    • notifyModelChanged

      public void notifyModelChanged(int changeType)
      Description copied from class: PamControlledUnit
      General notification when the PAMGAURD model changes.
      Overrides:
      notifyModelChanged in class PamControlledUnit
      Parameters:
      changeType - type of change
    • fillSettingsStore

      public void fillSettingsStore()
      Read all the settings in from storage.
    • getConnection

      public PamConnection getConnection()
    • getSettingsReference

      public Serializable getSettingsReference()
      Specified by:
      getSettingsReference in interface PamSettings
      Returns:
      The serialisable object that will be stored
    • getSettingsVersion

      public long getSettingsVersion()
      Specified by:
      getSettingsVersion in interface PamSettings
      Returns:
      An integer version number for the settings
    • restoreSettings

      public boolean restoreSettings(PamControlledUnitSettings pamControlledUnitSettings)
      Specified by:
      restoreSettings in interface PamSettings
      Returns:
      true if successful The object performs final checks (if needed) and then casts the settings data pamcontrolledunitSettings.settings into the correct type and uses as required
    • createFileMenu

      public JMenuItem createFileMenu(JFrame parentFrame)
      Overrides:
      createFileMenu in class PamControlledUnit
      Parameters:
      parentFrame - parent frame for the menu
      Returns:
      the file menu item
    • getSidePanel

      public PamSidePanel getSidePanel()
      Description copied from class: PamControlledUnit
      Gets a reference to a small panel to be displayed along the left hand edge of the main tab panel. Side panels should be small since they are always visible and any space they take will be taken from the main tab panel.

      It is possible for a PamControlled unit to have a side panel without having a pamTabPanel.

      Overrides:
      getSidePanel in class PamControlledUnit
      Returns:
      a pamSidePanel object.
      See Also:
    • getDbUnitType

      public static String getDbUnitType()
    • getDbProcess

      public DBProcess getDbProcess()
    • saveSettingsToDB

      public boolean saveSettingsToDB()
    • saveStartSettings

      public boolean saveStartSettings(long timeNow)
      Description copied from interface: PamSettingsSource
      Save the settings in some way or another.
      Specified by:
      saveStartSettings in interface PamSettingsSource
      Parameters:
      timeNow - current time.
      Returns:
      true if settings saved successfully
    • saveEndSettings

      public boolean saveEndSettings(long timeNow)
      Description copied from interface: PamSettingsSource
      Save settings when processing ends. This may just be an update of the settings saves with saveStartSettings, e.g. an end time.
      Specified by:
      saveEndSettings in interface PamSettingsSource
      Returns:
      true if saved correctly.
    • getNumSettings

      public int getNumSettings()
      Description copied from interface: PamSettingsSource
      Get the number of different settings within the settings source.
      Specified by:
      getNumSettings in interface PamSettingsSource
      Returns:
      the number of PamSettingsGroups.
    • getSettings

      public PamSettingsGroup getSettings(int settingsIndex)
      Description copied from interface: PamSettingsSource
      Get a specific PamSettingsGroup
      Specified by:
      getSettings in interface PamSettingsSource
      Parameters:
      settingsIndex - index of group
      Returns:
      a settings group
    • getSettingsSourceName

      public String getSettingsSourceName()
      Description copied from interface: PamSettingsSource
      Get a name for the settings source
      Specified by:
      getSettingsSourceName in interface PamSettingsSource
      Returns:
      a name
    • isFullTablesCheck

      public boolean isFullTablesCheck()
    • setFullTablesCheck

      public void setFullTablesCheck(boolean fullTablesCheck)
    • getDatabaseName

      public String getDatabaseName()
      Returns:
      the name of the current database
    • getLongDatabaseName

      public String getLongDatabaseName()
      Returns:
      the name of the current database
    • createPamCursor

      public PamCursor createPamCursor(EmptyTableDefinition tableDefinition)
    • getDatabaseSystem

      public DBSystem getDatabaseSystem()
      Returns:
      the current databaseSystem
    • reOpenConnection

      public PamConnection reOpenConnection()
      Reopen a database connection. This has a default action of doing absolutely nothing since it's only actually required by SqLite before it writes after doing some reading.

      Turned out this was never needed, but leave in in case it get's handy lter for some reason. e.g. see http://www.sqlite.org/lockingv3.html

      Parameters:
      connection - existing connection
      Returns:
      new connection.
    • getDbParameters

      public DBParameters getDbParameters()
      Returns:
      the dbParameters
    • getDatabaseSystems

      public ArrayList<DBSystem> getDatabaseSystems()
      Get all the available database systems
      Returns:
      an arrya of all available database systems .
    • selectDatabase

      public boolean selectDatabase(Frame frame, String selectTitle)
      Open the database dialog.
      Parameters:
      frame - - the GUI frame
      selectTitle - - the title of the dialog
      Returns:
      - true if a database has been successfully selected.
    • setDBParameters

      public void setDBParameters(DBParameters dbParameters)
      Set dB paramaters
      Parameters:
      dbParameters -
    • getGUI

      public PamControlledUnitGUI getGUI(int flag)
      Description copied from class: PamControlledUnit
      Get the GUI for the PAMControlled unit. This has multiple GUI options which are instantiated depending on the view type.
      Overrides:
      getGUI in class PamControlledUnit
      Parameters:
      flag - . The GUI type flag defined in PAMGuiManager.
      Returns:
      the GUI for the PamControlledUnit unit.
    • getLastErrorCount

      public int getLastErrorCount()
      Returns:
      the lastErrorCount