Class SqlJetDb
Connection to database. This class currently is main entry point in SQLJet API.
It allows to perform next tasks:
- Open existed and create new SQLite database.
- Get and modify database's schema.
- Control transactions.
- Read, search and modify data in database.
- Get and set database's options.
-
Field Summary
FieldsFields inherited from class org.tmatesoft.sqljet.core.table.engine.SqlJetEngine
btree, dbHandle, file, FILE_SYSTEM_MANAGER, fileSystem, open, writable
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionalterTable
(String sql) Alters table.protected void
createIndex
(String sql) Create index from SQL clause.createTable
(String sql) Create table from SQL clause.createTrigger
(String sql) Creates trigger from SQL clause.createView
(String sql) Creates view from SQL clause.createVirtualTable
(String sql) Creates virtual table from SQL clause.void
Drop index.void
Drop table.void
dropTrigger
(String triggerName) Drop trigger.void
Drop view.Get database schema.Open table.getTemporaryDatabase
(boolean inMemory) Opens temporary on-disk database which life span is less or equal to that of this object.static SqlJetDb
Opens connection to data base.static SqlJetDb
static SqlJetDb
open
(File file, boolean write, ISqlJetFileSystem fs) Executes pragma statement.Run read-only transaction.Run transaction.Do some actions with locking database's internal threads synchronization mutex.Run modifications in write transaction.Methods inherited from class org.tmatesoft.sqljet.core.table.engine.SqlJetEngine
beginTransaction, checkOpen, close, commit, finalize, getBusyHandler, getCacheSize, getFile, getFileSystem, getJournalMode, getMutex, getOptions, getSafetyLevel, getSchemaInternal, getTransactionMode, isInTransaction, isOpen, isWritable, open, readSchema, refreshSchema, registerFileSystem, rollback, runEngineTransaction, runSynchronized, setBusyHandler, setCacheSize, setJournalMode, setSafetyLevel, unregisterFileSystem
-
Field Details
-
IN_MEMORY
File name for in memory database.
-
-
Constructor Details
-
SqlJetDb
Creates connection to database but not open it. Doesn't open database file until not called method
SqlJetEngine.open()
.File could be null or have special value
IN_MEMORY
. If file is null then will be created temporary file which will be deleted at close. If file isIN_MEMORY
then file doesn't created and instead database will placed in memory. If regular file is specified but doesn't exist then it will be tried to created.- Parameters:
file
- path to data base. Could be null orIN_MEMORY
.writable
- if true then will allow data modification.
-
SqlJetDb
-
SqlJetDb
- Throws:
SqlJetException
-
-
Method Details
-
open
Opens connection to data base. It does not create any locking on database. First lock will be created when be called any method which requires real access to options or schema.
File could be null or have special value
IN_MEMORY
. If file is null then will be created temporary file which will be deleted at close. If file isIN_MEMORY
then file doesn't created and instead database will placed in memory. If regular file is specified but doesn't exist then it will be tried to created.- Parameters:
file
- path to data base. Could be null orIN_MEMORY
.write
- open for writing if true.- Throws:
SqlJetException
- if any trouble with access to file or database format.
-
open
- Parameters:
file
-write
-fs
-- Returns:
- SqlJetDb object for opened database
- Throws:
SqlJetException
-
open
- Parameters:
file
-write
-fsName
-- Returns:
- SqlJetDb object for opened database
- Throws:
SqlJetException
-
runWithLock
Do some actions with locking database's internal threads synchronization mutex. It is related only with synchronization of access to one connection from multiple threads. It is not related with transactions and locks of database file. For concurrent access to database from threads or processes use transactions.- Parameters:
op
- operation to run- Returns:
- result of the
ISqlJetRunnableWithLock.runWithLock(SqlJetDb)
call. - Throws:
SqlJetException
- in case operation fails to run.
-
getSchema
Get database schema.- Returns:
- database schema.
- Throws:
SqlJetException
-
getTable
Open table.- Parameters:
tableName
- name of the table to open.- Returns:
- opened table
- Throws:
SqlJetException
-
runWriteTransaction
Run modifications in write transaction.- Parameters:
op
- transaction to run.- Returns:
- result of the
ISqlJetTransaction.run(SqlJetDb)
call. - Throws:
SqlJetException
-
runReadTransaction
Run read-only transaction.- Parameters:
op
- transaction to run.- Returns:
- result of the
ISqlJetTransaction.run(SqlJetDb)
call. - Throws:
SqlJetException
-
runTransaction
public Object runTransaction(ISqlJetTransaction op, SqlJetTransactionMode mode) throws SqlJetException Run transaction.- Parameters:
op
- transaction's body (closure).mode
- transaction's mode.- Returns:
- result of the
ISqlJetTransaction.run(SqlJetDb)
call. - Throws:
SqlJetException
-
pragma
Executes pragma statement. If statement queries pragma value then pragma value will be returned.- Throws:
SqlJetException
-
createTable
Create table from SQL clause.- Parameters:
sql
- CREATE TABLE ... sentence.- Returns:
- definition of create table.
- Throws:
SqlJetException
-
createIndex
Create index from SQL clause.- Parameters:
sql
- CREATE INDEX ... sentence.- Returns:
- definition of created index.
- Throws:
SqlJetException
-
dropTable
Drop table.- Parameters:
tableName
- name of table to drop.- Throws:
SqlJetException
-
dropIndex
Drop index.- Parameters:
indexName
- name of the index to drop.- Throws:
SqlJetException
-
dropView
Drop view.- Parameters:
viewName
- name of the view to drop.- Throws:
SqlJetException
-
dropTrigger
Drop trigger.- Parameters:
triggerName
- name of the trigger to drop.- Throws:
SqlJetException
-
alterTable
Alters table.- Parameters:
sql
- ALTER TABLE ... sentence.- Returns:
- altered table schema definition.
- Throws:
SqlJetException
-
createVirtualTable
Creates virtual table from SQL clause.- Parameters:
sql
- CREATE VIRTUAL TABLE ... sentence.- Returns:
- definition of create virtual table.
- Throws:
SqlJetException
-
createView
Creates view from SQL clause.- Parameters:
sql
- CREATE VIEW X AS SELECT ... sentence.- Returns:
- definition of the view being created.
- Throws:
SqlJetException
-
createTrigger
Creates trigger from SQL clause.- Parameters:
sql
- CREATE TRIGGER ... sentence.- Returns:
- definition of the trigger being created.
- Throws:
SqlJetException
-
getTemporaryDatabase
- Returns:
- SqlJetDb object for temporary database
- Throws:
SqlJetException
- See Also:
-
getTemporaryDatabase
Opens temporary on-disk database which life span is less or equal to that of this object. Temporary database is closed and deleted as soon as this database connection is closed. Temporary file is used to store temporary database. Subsequent calls to this method will return the same temporary database In case previously create temporary database is closed by the user, then another one is created by this method.- Parameters:
inMemory
- when true open temporary database in memory.- Returns:
- temporary database being created or existing temporary database.
- Throws:
SqlJetException
-
closeResources
- Overrides:
closeResources
in classSqlJetEngine
- Throws:
SqlJetException
-