generalDatabase
Class DBProcess

java.lang.Object
  extended by PamguardMVC.PamProcess
      extended by generalDatabase.DBProcess
All Implemented Interfaces:
Annotator, PamObserver

public class DBProcess
extends PamProcess


Nested Class Summary
(package private)  class DBProcess.TimerAction
           
(package private)  class DBProcess.ViewTimerAction
           
 
Field Summary
private  DBControl databaseControll
           
private  java.util.ArrayList<PamDataBlock> dataBlocks
           
private  java.util.ArrayList<DbSpecial> dbSpecials
           
private  int dbWriteErrors
           
private  int dbWriteOKs
           
private static java.lang.String expMessage
          From early 2008 (release 1.1) until August 2008 (release 1.1.1) A LocalTime column had been added to database tables to store the local computer time with each record as well as UTC.
private  LogSettings logLastSettings
           
private  LogModules logModules
           
private  LogSettings logSettings
           
private  javax.swing.Timer timer
           
private  javax.swing.Timer viewTimer
           
 
Fields inherited from class PamguardMVC.PamProcess
outputDataBlocks, processName, sampleRate
 
Constructor Summary
DBProcess(DBControl databaseControll)
           
 
Method Summary
private  boolean addColumn(EmptyTableDefinition tableDef, PamTableItem tableItem)
           
 boolean changeColumnFormat(java.lang.String tableName, PamTableItem tableItem)
          Change the format of a column.
 boolean checkColumn(EmptyTableDefinition tableDef, PamTableItem tableItem)
          Check a database table column exists.
 boolean checkTable(EmptyTableDefinition tableDef)
          Check a database table.
 void checkTables()
           
 boolean clearTable(EmptyTableDefinition tableDef)
          Completely clear the contents of a table
 boolean clearTable(java.lang.String tableName)
           
 boolean columnExists(EmptyTableDefinition tableDef, PamTableItem tableItem)
          Check that a specific table column exists
private  boolean columnExists(EmptyTableDefinition tableDef, java.lang.String columnName, int sqlType)
          Check a specific table column exists
private  boolean columnExists(java.lang.String tableName, java.lang.String columnName, int sqlType)
          Check a specific table column exists
private  boolean createTable(EmptyTableDefinition tableDef)
          Create the entire table from scratch using a single SQL command
(package private)  void fixLocalTimeProblem(EmptyTableDefinition tableDef)
           
 LogSettings getLogLastSettings()
           
 LogSettings getLogSettings()
           
private  boolean logData(PamDataBlock block, PamDataUnit unit)
          Hope this doesn't happen during PamguardViewer.
 void newData(PamObservable o, PamDataUnit dataUnit)
           
 void pamStart()
          Called for each process to tell it to start (may not be necessary for processes which are listening for data anyway.
 void pamStop()
          Stops the process.
private  void prepareForMixedMode()
           
private  boolean reLogData(PamDataBlock block, PamDataUnit unit)
          Hope this doesn't happen during PamguardViewer.
private  boolean runStmt(java.lang.String str)
           
 boolean saveSettingsToDB()
          Called from the settings manager whenever settings would normally be saved to file.
protected  boolean saveStartSettings()
           
private  boolean shouldLog(PamDataBlock pamDataBlock, PamDataUnit pamDataUnit)
           
 boolean tableExists(EmptyTableDefinition tableDef)
          Check a database table exists.
 void updateData(PamObservable o, PamDataUnit dataUnit)
           
protected  void updateProcessList()
           
private  void viewTimerAction()
           
 
Methods inherited from class PamguardMVC.PamProcess
absMillisecondsToSamples, absSamplesToMilliseconds, addOutputDataBlock, changedThreading, clearOldData, createAnnotations, destroyProcess, fillXMLElement, fillXMLParameters, getAncestorDataBlock, getAnnotation, getBackendProcess, getChainPosition, getCpuPercent, getNumAnnotations, getNumOutputDataBlocks, getObserverName, getObserverObject, getOfflineData, getOutputDataBlock, getPamControlledUnit, getParentDataBlock, getParentProcess, getProcessName, getRawSourceDataBlock, getRequiredDataHistory, getSampleRate, getSourceDataBlock, getSourceProcess, isCanMultiThread, makePamProcess, masterClockUpdate, noteNewSettings, notifyModelChanged, prepareProcess, relMillisecondsToSamples, relSamplesToMilliseconds, removeObservable, removeOutputDatablock, saveViewerData, setBackendProcess, setCanMultiThread, setParentDataBlock, setParentDataBlock, setProcessName, setSampleRate, setupProcess, toString, update
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

databaseControll

private DBControl databaseControll

dataBlocks

private java.util.ArrayList<PamDataBlock> dataBlocks

timer

private javax.swing.Timer timer

dbWriteOKs

private int dbWriteOKs

dbWriteErrors

private int dbWriteErrors

dbSpecials

private java.util.ArrayList<DbSpecial> dbSpecials

viewTimer

private javax.swing.Timer viewTimer

logModules

private LogModules logModules

logSettings

private LogSettings logSettings

logLastSettings

private LogSettings logLastSettings

expMessage

private static java.lang.String expMessage
From early 2008 (release 1.1) until August 2008 (release 1.1.1) A LocalTime column had been added to database tables to store the local computer time with each record as well as UTC. This feature was only tested with MS Access.

Unfortunately, it transpires that LocalTime is a reserved word in MySQL, so while MS Access databases worked OK, it became impossible to create tables with MySQL.

The column name has now been changed from LocalTime to PCLocalTime. New databases will not be affected, however, there are now old MS Access databases out there that have a LocalTime column, where we need a PCLocalTime column.

This function attempts to fix this automatically.

Constructor Detail

DBProcess

public DBProcess(DBControl databaseControll)
Method Detail

pamStart

public void pamStart()
Description copied from class: PamProcess
Called for each process to tell it to start (may not be necessary for processes which are listening for data anyway.

Specified by:
pamStart in class PamProcess

saveStartSettings

protected boolean saveStartSettings()

pamStop

public void pamStop()
Description copied from class: PamProcess
Stops the process.

Specified by:
pamStop in class PamProcess

saveSettingsToDB

public boolean saveSettingsToDB()
Called from the settings manager whenever settings would normally be saved to file. Just saves the latest of all PAMGUARD settings, first deleting any other settings in the logLastSettings table.

The logSettings object does a slightly different task of always storing the current PAMGAURD settings in a table which grows and grows, giving a permanent record of PAMGUARD settings over time.

Unlike the settings in the growing table of logSettings, the settings stored from logLastSettings are also stored when viewer or mixed mode is exited.

Returns:
true if successful.

prepareForMixedMode

private void prepareForMixedMode()

viewTimerAction

private void viewTimerAction()

checkTables

public void checkTables()

checkTable

public boolean checkTable(EmptyTableDefinition tableDef)
Check a database table. If it does not exist, create it.

Then check all columns and if a column does not exist, create that too.

Parameters:
tableDef - table definition
Returns:
true if table is OK, i.e. table and all columns either existed or were successfully created.

tableExists

public boolean tableExists(EmptyTableDefinition tableDef)
Check a database table exists.

Parameters:
tableDef - table definition
Returns:
true if the table exists

fixLocalTimeProblem

void fixLocalTimeProblem(EmptyTableDefinition tableDef)

checkColumn

public boolean checkColumn(EmptyTableDefinition tableDef,
                           PamTableItem tableItem)
Check a database table column exists. If it doesn't exist, attempt to create it.

Parameters:
tableDef - table definition
tableItem - table item
Returns:
true if column existed or was created.

columnExists

public boolean columnExists(EmptyTableDefinition tableDef,
                            PamTableItem tableItem)
Check that a specific table column exists

Parameters:
tableDef - table definition
tableItem - table item
Returns:
true if the column exists

columnExists

private boolean columnExists(EmptyTableDefinition tableDef,
                             java.lang.String columnName,
                             int sqlType)
Check a specific table column exists

Parameters:
tableDef - table definition
columnName - column name
sqlType - column sql type
Returns:
true if the column exists and has the correct format.

columnExists

private boolean columnExists(java.lang.String tableName,
                             java.lang.String columnName,
                             int sqlType)
Check a specific table column exists

Parameters:
tableName - table name
columnName - column name
sqlType - column sql type
Returns:
true if the column exists and has the correct format.

changeColumnFormat

public boolean changeColumnFormat(java.lang.String tableName,
                                  PamTableItem tableItem)
Change the format of a column.

Returns:
true if change sucessful

runStmt

private boolean runStmt(java.lang.String str)

createTable

private boolean createTable(EmptyTableDefinition tableDef)
Create the entire table from scratch using a single SQL command

Parameters:
tableDef - Tabe definition structure
Returns:
true if table created sucessfully
See Also:
PamTableDefinition

addColumn

private boolean addColumn(EmptyTableDefinition tableDef,
                          PamTableItem tableItem)

clearTable

public boolean clearTable(EmptyTableDefinition tableDef)
Completely clear the contents of a table

Parameters:
tableDef - tabledef identifying the table.
Returns:
true if successful.

clearTable

public boolean clearTable(java.lang.String tableName)

updateProcessList

protected void updateProcessList()

newData

public void newData(PamObservable o,
                    PamDataUnit dataUnit)
Overrides:
newData in class PamProcess

updateData

public void updateData(PamObservable o,
                       PamDataUnit dataUnit)
Overrides:
updateData in class PamProcess

logData

private boolean logData(PamDataBlock block,
                        PamDataUnit unit)
Hope this doesn't happen during PamguardViewer. May sometimes happen during mixed operation. May need some fudges to make sure the right data are logged.

Parameters:
block -
unit -
Returns:

reLogData

private boolean reLogData(PamDataBlock block,
                          PamDataUnit unit)
Hope this doesn't happen during PamguardViewer. May sometimes happen during mixed operation. May need some fudges to make sure the right data are logged.

Parameters:
block -
unit -
Returns:

shouldLog

private boolean shouldLog(PamDataBlock pamDataBlock,
                          PamDataUnit pamDataUnit)

getLogSettings

public LogSettings getLogSettings()

getLogLastSettings

public LogSettings getLogLastSettings()