Class SQLiteDBManager
- java.lang.Object
-
- com.inductiveautomation.ignition.gateway.localdb.sqlite.SQLiteDBManager
-
-
Field Summary
Fields Modifier and Type Field Description protected intautoBackupCountNumber of auto-backups to keep, if autoBackupsEnabled is trueprotected intautoBackupDelayDelay, in minutes, between checking if an auto-backup is necessary.protected java.io.FileautoBackupDirprotected booleanautoBackupsEnabledWhether or not to use any autobackups.protected GatewayContextcontextprotected CountingDataSourcedatasourceWhen 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.FiledbDirThe home directory that the database lives inprotected java.lang.StringdbNameThe name of the databaseprotected intdefragDelayDelay, in minutes, between defragmentation.static java.lang.StringDRIVER_CLASSprotected intfaultCountNumber of faulted copies to keepprotected LoggerExlogprotected booleannewDatabaseFlag that will be set true when this manager was started up with no database and created an initial one on connect()
-
Constructor Summary
Constructors Constructor Description SQLiteDBManager(GatewayContext context, java.io.File dbDir, java.lang.String dbName)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description java.io.FilebackupDatabase(java.io.File targetFolder, java.lang.String baseFilename)Creates a single-file backup of the internal db in the specified folder.TablecreateTable()protected java.lang.Stringdesc()intgetAutoBackupCount()intgetAutoBackupDelay()java.io.FilegetAutoBackupDir()longgetDatabaseSize()Calculates the harddrive footprint of the files that make up this sqlite instance.javax.sql.DataSourcegetDataSource()SDrivergetDriver()Returns the driver for the DBManager.intgetFaultCount()InternalDBFlavorgetFlavor()voidinitDriver()booleanisAutoBackupsEnabled()booleanisNewDatabase()booleanisRunning()protected voidonConnected(javax.sql.DataSource datasource)Called after we have been successfully connected to a sqlite database.protected voidonCreateInitial(java.sql.Statement stmt)Called on creation of a new database, after the password has been set.protected voidonShutdown()voidrestoreFromDBBackup(java.io.File dbFile)Deletes the database files and restores the provided db filevoidsetAutoBackupCount(int autoBackupCount)voidsetAutoBackupDelay(int autoBackupDelay)voidsetAutoBackupDir(java.io.File autoBackupDir)voidsetAutoBackupsEnabled(boolean autoBackupsEnabled)voidsetDefragDelay(int defragDelayMin)voidsetFaultCount(int faultCount)voidshutdown()voidshutdown(boolean compact)voidstartup()
-
-
-
Field Detail
-
DRIVER_CLASS
public static final java.lang.String DRIVER_CLASS
- 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 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.
-
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 manager was started up with no database and created an initial one on connect()
-
log
protected LoggerEx log
-
-
Constructor Detail
-
SQLiteDBManager
public SQLiteDBManager(GatewayContext context, java.io.File dbDir, java.lang.String dbName)
-
-
Method Detail
-
initDriver
public void initDriver() throws DBStartupException- Throws:
DBStartupException
-
startup
public void startup() throws DBStartupException- Specified by:
startupin interfaceDBManager- Throws:
DBStartupException
-
getDataSource
public javax.sql.DataSource getDataSource()
- Specified by:
getDataSourcein interfaceDBManager
-
onCreateInitial
protected void onCreateInitial(java.sql.Statement stmt) throws java.sql.SQLExceptionCalled 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.SQLExceptionCalled after we have been successfully connected to a sqlite database.- Throws:
java.sql.SQLException
-
onShutdown
protected void onShutdown()
-
desc
protected java.lang.String desc()
-
restoreFromDBBackup
public void restoreFromDBBackup(java.io.File dbFile) throws java.io.IOExceptionDeletes the database files and restores the provided db file- Specified by:
restoreFromDBBackupin interfaceDBManager- Throws:
java.io.IOException
-
backupDatabase
public java.io.File backupDatabase(java.io.File targetFolder, java.lang.String baseFilename) throws java.io.IOExceptionDescription copied from interface:DBManagerCreates 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:
backupDatabasein interfaceDBManager- Throws:
java.io.IOException
-
isNewDatabase
public boolean isNewDatabase()
- Specified by:
isNewDatabasein interfaceDBManager
-
shutdown
public void shutdown()
-
getDatabaseSize
public long getDatabaseSize()
Calculates the harddrive footprint of the files that make up this sqlite instance.- Specified by:
getDatabaseSizein 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:
setFaultCountin interfaceDBManager
-
getAutoBackupCount
public int getAutoBackupCount()
-
setAutoBackupCount
public void setAutoBackupCount(int autoBackupCount)
- Specified by:
setAutoBackupCountin interfaceDBManager
-
isAutoBackupsEnabled
public boolean isAutoBackupsEnabled()
-
setAutoBackupsEnabled
public void setAutoBackupsEnabled(boolean autoBackupsEnabled)
- Specified by:
setAutoBackupsEnabledin interfaceDBManager
-
getAutoBackupDelay
public int getAutoBackupDelay()
-
setAutoBackupDelay
public void setAutoBackupDelay(int autoBackupDelay)
- Specified by:
setAutoBackupDelayin interfaceDBManager
-
setDefragDelay
public void setDefragDelay(int defragDelayMin)
- Specified by:
setDefragDelayin interfaceDBManager
-
getFlavor
public InternalDBFlavor getFlavor()
-
getDriver
public SDriver getDriver()
Description copied from interface:DBManagerReturns 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:
createTablein interfaceDBManager
-
-