Class SqlJetEngine
- java.lang.Object
-
- org.tmatesoft.sqljet.core.table.engine.SqlJetEngine
-
- Direct Known Subclasses:
SqlJetDb
,SqlJetMapDb
public class SqlJetEngine extends java.lang.Object
-
-
Field Summary
Fields Modifier and Type Field Description protected ISqlJetBtree
btree
protected ISqlJetDbHandle
dbHandle
protected java.io.File
file
protected static ISqlJetFileSystemsManager
FILE_SYSTEM_MANAGER
protected ISqlJetFileSystem
fileSystem
protected boolean
open
protected boolean
writable
-
Constructor Summary
Constructors Constructor Description SqlJetEngine(java.io.File file, boolean writable)
SqlJetEngine(java.io.File file, boolean writable, java.lang.String fsName)
SqlJetEngine(java.io.File file, boolean writable, ISqlJetFileSystem fs)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
beginTransaction(SqlJetTransactionMode mode)
Begin transaction.protected void
checkOpen()
void
close()
Close connection to database.protected void
closeResources()
void
commit()
Commits transaction.protected void
finalize()
ISqlJetBusyHandler
getBusyHandler()
Get busy handler.int
getCacheSize()
Get cache size (in count of pages).java.io.File
getFile()
ISqlJetFileSystem
getFileSystem()
SqlJetPagerJournalMode
getJournalMode()
Get jounrnal modeISqlJetMutex
getMutex()
Retruns threading synchronization mutex.ISqlJetOptions
getOptions()
Returns database options.SqlJetSafetyLevel
getSafetyLevel()
Get safety levelprotected SqlJetSchema
getSchemaInternal()
SqlJetTransactionMode
getTransactionMode()
boolean
isInTransaction()
Returns true if a transaction is active.boolean
isOpen()
Checks is database open.boolean
isWritable()
Check write access to data base.void
open()
Opens connection to database.protected void
readSchema()
Reads database schema and options.void
refreshSchema()
Refreshes database schema.void
registerFileSystem(ISqlJetFileSystem fs, boolean isDefault)
void
rollback()
Rolls back transaction.protected java.lang.Object
runEngineTransaction(ISqlJetEngineTransaction op, SqlJetTransactionMode mode)
Runs transaction.java.lang.Object
runSynchronized(ISqlJetEngineSynchronized op)
void
setBusyHandler(ISqlJetBusyHandler busyHandler)
Set busy handler.void
setCacheSize(int cacheSize)
Set cache size (in count of pages).void
setJournalMode(SqlJetPagerJournalMode journalMode)
Set journal modevoid
setSafetyLevel(SqlJetSafetyLevel safetyLevel)
Set safety levelvoid
unregisterFileSystem(ISqlJetFileSystem fs)
-
-
-
Field Detail
-
FILE_SYSTEM_MANAGER
protected static final ISqlJetFileSystemsManager FILE_SYSTEM_MANAGER
-
fileSystem
protected ISqlJetFileSystem fileSystem
-
writable
protected boolean writable
-
dbHandle
protected ISqlJetDbHandle dbHandle
-
btree
protected ISqlJetBtree btree
-
open
protected boolean open
-
file
protected java.io.File file
-
-
Constructor Detail
-
SqlJetEngine
public SqlJetEngine(java.io.File file, boolean writable)
-
SqlJetEngine
public SqlJetEngine(java.io.File file, boolean writable, ISqlJetFileSystem fs)
- Parameters:
file
-writable
-fs
-
-
SqlJetEngine
public SqlJetEngine(java.io.File file, boolean writable, java.lang.String fsName) throws SqlJetException
- Parameters:
file
-writable
-fsName
-- Throws:
SqlJetException
-
-
Method Detail
-
registerFileSystem
public void registerFileSystem(ISqlJetFileSystem fs, boolean isDefault) throws SqlJetException
- Parameters:
fs
-isDefault
-- Throws:
SqlJetException
-
unregisterFileSystem
public void unregisterFileSystem(ISqlJetFileSystem fs) throws SqlJetException
- Parameters:
fs
-- Throws:
SqlJetException
-
getFile
public java.io.File getFile()
- Returns:
- database file this engine is created for.
-
isWritable
public boolean isWritable() throws SqlJetException
Check write access to data base.- Returns:
- true if modification is allowed
- Throws:
SqlJetException
-
getFileSystem
public ISqlJetFileSystem getFileSystem()
-
isOpen
public boolean isOpen()
Checks is database open.- Returns:
- true if database is open.
-
checkOpen
protected void checkOpen() throws SqlJetException
- Throws:
SqlJetException
-
open
public void open() throws SqlJetException
Opens connection to database. 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.
- Throws:
SqlJetException
- if any trouble with access to file or database format.
-
runSynchronized
public java.lang.Object runSynchronized(ISqlJetEngineSynchronized op) throws SqlJetException
- Throws:
SqlJetException
-
close
public void close() throws SqlJetException
Close connection to database. It is safe to call this method if database connections is closed already.- Throws:
SqlJetException
- it is possible to get exception if there is actvie transaction and rollback did not success.
-
closeResources
protected void closeResources() throws SqlJetException
- Throws:
SqlJetException
-
finalize
protected void finalize() throws java.lang.Throwable
- Overrides:
finalize
in classjava.lang.Object
- Throws:
java.lang.Throwable
-
readSchema
protected void readSchema() throws SqlJetException
Reads database schema and options.- Throws:
SqlJetException
-
getOptions
public ISqlJetOptions getOptions() throws SqlJetException
Returns database options.- Returns:
- options of this database.
- Throws:
SqlJetException
-
refreshSchema
public void refreshSchema() throws SqlJetException
Refreshes database schema.- Throws:
SqlJetException
-
getSchemaInternal
protected SqlJetSchema getSchemaInternal() throws SqlJetException
- Throws:
SqlJetException
-
getBusyHandler
public ISqlJetBusyHandler getBusyHandler()
Get busy handler.- Returns:
- the busy handler.
-
setBusyHandler
public void setBusyHandler(ISqlJetBusyHandler busyHandler)
Set busy handler. Busy handler treats situation when database is locked by other process or thread.- Parameters:
busyHandler
- the busy handler.
-
getMutex
public ISqlJetMutex getMutex()
Retruns threading synchronization mutex.- Returns:
- Semaphore instance used to synchronize database access from multiple threads within the same process.
-
setCacheSize
public void setCacheSize(int cacheSize) throws SqlJetException
Set cache size (in count of pages).- Parameters:
cacheSize
- the count of pages which can hold cache.- Throws:
SqlJetException
-
getCacheSize
public int getCacheSize() throws SqlJetException
Get cache size (in count of pages).- Returns:
- the count of pages which can hold cache.
- Throws:
SqlJetException
-
setSafetyLevel
public void setSafetyLevel(SqlJetSafetyLevel safetyLevel) throws SqlJetException
Set safety level- Parameters:
safetyLevel
-- Throws:
SqlJetException
-
setJournalMode
public void setJournalMode(SqlJetPagerJournalMode journalMode) throws SqlJetException
Set journal mode- Parameters:
journalMode
-- Throws:
SqlJetException
-
getSafetyLevel
public SqlJetSafetyLevel getSafetyLevel() throws SqlJetException
Get safety level- Returns:
- the safety level set.
- Throws:
SqlJetException
-
getJournalMode
public SqlJetPagerJournalMode getJournalMode() throws SqlJetException
Get jounrnal mode- Returns:
- the safety level set.
- Throws:
SqlJetException
-
isInTransaction
public boolean isInTransaction()
Returns true if a transaction is active.- Returns:
- true if there is an active running transaction.
-
getTransactionMode
public SqlJetTransactionMode getTransactionMode()
-
beginTransaction
public void beginTransaction(SqlJetTransactionMode mode) throws SqlJetException
Begin transaction.- Parameters:
mode
- transaction's mode.- Throws:
SqlJetException
-
commit
public void commit() throws SqlJetException
Commits transaction.- Throws:
SqlJetException
-
rollback
public void rollback() throws SqlJetException
Rolls back transaction.- Throws:
SqlJetException
-
runEngineTransaction
protected java.lang.Object runEngineTransaction(ISqlJetEngineTransaction op, SqlJetTransactionMode mode) throws SqlJetException
Runs transaction.- Parameters:
op
- transaction's body (closure).mode
- transaction's mode.- Returns:
- result of
ISqlJetTransaction.run(org.tmatesoft.sqljet.core.table.SqlJetDb)
call. - Throws:
SqlJetException
-
-