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 ISqlJetBtreebtreeprotected ISqlJetDbHandledbHandleprotected java.io.Filefileprotected static ISqlJetFileSystemsManagerFILE_SYSTEM_MANAGERprotected ISqlJetFileSystemfileSystemprotected booleanopenprotected booleanwritable
-
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 voidbeginTransaction(SqlJetTransactionMode mode)Begin transaction.protected voidcheckOpen()voidclose()Close connection to database.protected voidcloseResources()voidcommit()Commits transaction.protected voidfinalize()ISqlJetBusyHandlergetBusyHandler()Get busy handler.intgetCacheSize()Get cache size (in count of pages).java.io.FilegetFile()ISqlJetFileSystemgetFileSystem()SqlJetPagerJournalModegetJournalMode()Get jounrnal modeISqlJetMutexgetMutex()Retruns threading synchronization mutex.ISqlJetOptionsgetOptions()Returns database options.SqlJetSafetyLevelgetSafetyLevel()Get safety levelprotected SqlJetSchemagetSchemaInternal()SqlJetTransactionModegetTransactionMode()booleanisInTransaction()Returns true if a transaction is active.booleanisOpen()Checks is database open.booleanisWritable()Check write access to data base.voidopen()Opens connection to database.protected voidreadSchema()Reads database schema and options.voidrefreshSchema()Refreshes database schema.voidregisterFileSystem(ISqlJetFileSystem fs, boolean isDefault)voidrollback()Rolls back transaction.protected java.lang.ObjectrunEngineTransaction(ISqlJetEngineTransaction op, SqlJetTransactionMode mode)Runs transaction.java.lang.ObjectrunSynchronized(ISqlJetEngineSynchronized op)voidsetBusyHandler(ISqlJetBusyHandler busyHandler)Set busy handler.voidsetCacheSize(int cacheSize)Set cache size (in count of pages).voidsetJournalMode(SqlJetPagerJournalMode journalMode)Set journal modevoidsetSafetyLevel(SqlJetSafetyLevel safetyLevel)Set safety levelvoidunregisterFileSystem(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 SqlJetExceptionCheck 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 SqlJetExceptionOpens 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 SqlJetExceptionClose 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:
finalizein classjava.lang.Object- Throws:
java.lang.Throwable
-
readSchema
protected void readSchema() throws SqlJetExceptionReads 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 SqlJetExceptionRefreshes 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 SqlJetExceptionSet cache size (in count of pages).- Parameters:
cacheSize- the count of pages which can hold cache.- Throws:
SqlJetException
-
getCacheSize
public int getCacheSize() throws SqlJetExceptionGet 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 SqlJetExceptionCommits transaction.- Throws:
SqlJetException
-
rollback
public void rollback() throws SqlJetExceptionRolls 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
-
-