Class HsqlDbManager
- java.lang.Object
-
- com.inductiveautomation.ignition.gateway.localdb.hsql.HsqlDbManager
-
-
Field Summary
Fields Modifier and Type Field Description protected int
autoBackupCount
Number of auto-backups to keep, if autoBackupsEnabled is trueprotected int
autoBackupDelay
Delay, in minutes, between checking if an auto-backup is necessary.protected java.io.File
autoBackupDir
protected boolean
autoBackupsEnabled
Whether or not to use any autobackups.protected GatewayContext
context
protected CountingDataSource
datasource
When this manager is connected, this will be a non-null reference to a javax.sql.DataSource that can be used to get connections to the databaseprotected java.io.File
dbDir
The home directory that the database lives inprotected java.lang.String
dbName
The name of the HSQLDB databaseprotected int
defragDelay
Delay, in minutes, between defragmentation.protected int
faultCount
Number of faulted copies to keepprotected LoggerEx
log
static java.lang.String
LOGGER_NAME
protected boolean
newDatabase
Flag that will be set true when this managaer was started up with no database and created an initial one on connect()protected java.lang.String
password
The password for the "sa" user for the database
-
Constructor Summary
Constructors Constructor Description HsqlDbManager(GatewayContext context, java.io.File dbDir, java.lang.String dbName, java.lang.String password)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
archiveDatabaseTo(java.lang.String folderName, boolean clear)
java.io.File
backupDatabase(java.io.File targetFolder, java.lang.String baseFilename)
Creates a single-file backup of the internal db in the specified folder.void
checkpoint()
protected java.util.Properties
createConnectionProps()
Table
createTable()
protected java.lang.String
desc()
int
getAutoBackupCount()
int
getAutoBackupDelay()
java.io.File
getAutoBackupDir()
long
getDatabaseSize()
Calculates the harddrive footprint of the files that make up this HSQLDB instance.javax.sql.DataSource
getDataSource()
SDriver
getDriver()
Returns the driver for the DBManager.int
getFaultCount()
InternalDBFlavor
getFlavor()
void
initDriver()
boolean
isAutoBackupsEnabled()
boolean
isNewDatabase()
boolean
isRunning()
protected LoggerEx
newLogger()
protected void
onConnected(javax.sql.DataSource datasource)
Called after we have been successfully connected to an HSQLDB database.protected void
onCreateInitial(java.sql.Statement stmt)
Called on creation of a new database, after the password has been set.protected void
onShutdown()
void
restoreFromDBBackup(java.io.File dbBackupTarball)
Deletes the database files and extracts the tarball into the database home directory.void
setAutoBackupCount(int autoBackupCount)
void
setAutoBackupDelay(int autoBackupDelay)
void
setAutoBackupDir(java.io.File autoBackupDir)
void
setAutoBackupsEnabled(boolean autoBackupsEnabled)
void
setDefragDelay(int defragDelayMin)
void
setFaultCount(int faultCount)
void
shutdown()
void
shutdown(boolean compact)
void
startup()
-
-
-
Field Detail
-
LOGGER_NAME
public static final java.lang.String LOGGER_NAME
- See Also:
- Constant Field Values
-
context
protected GatewayContext context
-
dbDir
protected java.io.File dbDir
The home directory that the database lives in
-
autoBackupDir
protected java.io.File autoBackupDir
-
dbName
protected java.lang.String dbName
The name of the HSQLDB database
-
faultCount
protected int faultCount
Number of faulted copies to keep
-
autoBackupCount
protected int autoBackupCount
Number of auto-backups to keep, if autoBackupsEnabled is true
-
autoBackupDelay
protected int autoBackupDelay
Delay, in minutes, between checking if an auto-backup is necessary.
-
defragDelay
protected int defragDelay
Delay, in minutes, between defragmentation. If 0, defrag checkpoints will not be executed. *
-
autoBackupsEnabled
protected boolean autoBackupsEnabled
Whether or not to use any autobackups. Note that setting this to false doesn net prevent the creation of autobackups - for that you'd set autoBackupCount to zero.
-
password
protected java.lang.String password
The password for the "sa" user for the database
-
datasource
protected CountingDataSource datasource
When this manager is connected, this will be a non-null reference to a javax.sql.DataSource that can be used to get connections to the database
-
newDatabase
protected boolean newDatabase
Flag that will be set true when this managaer was started up with no database and created an initial one on connect()
-
log
protected LoggerEx log
-
-
Constructor Detail
-
HsqlDbManager
public HsqlDbManager(GatewayContext context, java.io.File dbDir, java.lang.String dbName, java.lang.String password)
-
-
Method Detail
-
initDriver
public void initDriver() throws DBStartupException
- Throws:
DBStartupException
-
newLogger
protected LoggerEx newLogger()
-
createConnectionProps
protected java.util.Properties createConnectionProps()
-
startup
public void startup() throws DBStartupException
- Specified by:
startup
in interfaceDBManager
- Throws:
DBStartupException
-
archiveDatabaseTo
public void archiveDatabaseTo(java.lang.String folderName, boolean clear) throws java.lang.Exception
- Throws:
java.lang.Exception
-
getDataSource
public javax.sql.DataSource getDataSource()
- Specified by:
getDataSource
in interfaceDBManager
-
checkpoint
public void checkpoint()
-
onCreateInitial
protected void onCreateInitial(java.sql.Statement stmt) throws java.sql.SQLException
Called on creation of a new database, after the password has been set.- Throws:
java.sql.SQLException
-
onConnected
protected void onConnected(javax.sql.DataSource datasource) throws java.sql.SQLException
Called after we have been successfully connected to an HSQLDB database. A CHECKPOINT will be issued after this completes.- Throws:
java.sql.SQLException
-
onShutdown
protected void onShutdown()
-
desc
protected java.lang.String desc()
-
restoreFromDBBackup
public void restoreFromDBBackup(java.io.File dbBackupTarball) throws java.io.IOException
Deletes the database files and extracts the tarball into the database home directory.- Specified by:
restoreFromDBBackup
in interfaceDBManager
- Throws:
java.io.IOException
-
backupDatabase
public java.io.File backupDatabase(java.io.File targetFolder, java.lang.String baseFilename) throws java.io.IOException
Description copied from interface:DBManager
Creates a single-file backup of the internal db in the specified folder. The full path to the backup is returned. The filename should start with the base, but should then be identifiable by the specific db system.- Specified by:
backupDatabase
in interfaceDBManager
- Throws:
java.io.IOException
-
isNewDatabase
public boolean isNewDatabase()
- Specified by:
isNewDatabase
in interfaceDBManager
-
shutdown
public void shutdown()
-
getDatabaseSize
public long getDatabaseSize()
Calculates the harddrive footprint of the files that make up this HSQLDB instance.- Specified by:
getDatabaseSize
in interfaceDBManager
-
getAutoBackupDir
public java.io.File getAutoBackupDir()
-
setAutoBackupDir
public void setAutoBackupDir(java.io.File autoBackupDir)
-
getFaultCount
public int getFaultCount()
-
setFaultCount
public void setFaultCount(int faultCount)
- Specified by:
setFaultCount
in interfaceDBManager
-
getAutoBackupCount
public int getAutoBackupCount()
-
setAutoBackupCount
public void setAutoBackupCount(int autoBackupCount)
- Specified by:
setAutoBackupCount
in interfaceDBManager
-
isAutoBackupsEnabled
public boolean isAutoBackupsEnabled()
-
setAutoBackupsEnabled
public void setAutoBackupsEnabled(boolean autoBackupsEnabled)
- Specified by:
setAutoBackupsEnabled
in interfaceDBManager
-
getAutoBackupDelay
public int getAutoBackupDelay()
-
setAutoBackupDelay
public void setAutoBackupDelay(int autoBackupDelay)
- Specified by:
setAutoBackupDelay
in interfaceDBManager
-
setDefragDelay
public void setDefragDelay(int defragDelayMin)
- Specified by:
setDefragDelay
in interfaceDBManager
-
getFlavor
public InternalDBFlavor getFlavor()
-
getDriver
public SDriver getDriver()
Description copied from interface:DBManager
Returns the driver for the DBManager. Important: the driver holds a session, so a new instance should be created each time.
-
createTable
public Table createTable()
- Specified by:
createTable
in interfaceDBManager
-
-