Class SqlJetFile
- java.lang.Object
-
- org.tmatesoft.sqljet.core.internal.fs.SqlJetFile
-
- All Implemented Interfaces:
ISqlJetFile
public class SqlJetFile extends java.lang.Object implements ISqlJetFile
-
-
Field Summary
Fields Modifier and Type Field Description static intSQLJET_DEFAULT_SECTOR_SIZE-
Fields inherited from interface org.tmatesoft.sqljet.core.internal.ISqlJetFile
PENDING_BYTE, RESERVED_BYTE, SHARED_FIRST, SHARED_SIZE
-
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description booleancheckReservedLock()This routine checks if there is a RESERVED lock held on the specified file by this or any other process.voidclose()Close a file.java.util.Set<SqlJetDeviceCharacteristics>deviceCharacteristics()Return the device characteristics for the file.longfileSize()Determine the current size of a file in bytesSqlJetFileTypegetFileType()Returns file type.SqlJetLockTypegetLockType()Returns lock type of file.java.util.Set<SqlJetFileOpenPermission>getPermissions()Returns assiciated permissions.booleanisMemJournal()Return true if the file-handle passed as an argument is an in-memory journalbooleanlock(SqlJetLockType lockType)Lock the file with the lock specified by parameter locktype - one of the following: (1) SHARED (2) RESERVED (3) PENDING (4) EXCLUSIVE Sometimes when requesting one lock state, additional lock states are inserted in between.intread(ISqlJetMemoryPointer buffer, int amount, long offset)Read data from a file into a buffer.intsectorSize()Return the sector size in bytes of the underlying block device for the specified file.voidsync(java.util.Set<SqlJetSyncFlags> syncFlags)Make sure all writes to a particular file are committed to disk.voidtruncate(long size)Truncate an open file to a specified sizebooleanunlock(SqlJetLockType lockType)Lower the locking level on file descriptor pFile to locktype.voidwrite(ISqlJetMemoryPointer buffer, int amount, long offset)Write data from a buffer into a file.
-
-
-
Field Detail
-
SQLJET_DEFAULT_SECTOR_SIZE
public static final int SQLJET_DEFAULT_SECTOR_SIZE
- See Also:
- Constant Field Values
-
-
Method Detail
-
getFileType
public SqlJetFileType getFileType()
Description copied from interface:ISqlJetFileReturns file type.- Specified by:
getFileTypein interfaceISqlJetFile- Returns:
SqlJetFileType
-
getPermissions
public java.util.Set<SqlJetFileOpenPermission> getPermissions()
Description copied from interface:ISqlJetFileReturns assiciated permissions.- Specified by:
getPermissionsin interfaceISqlJetFile- Returns:
SqlJetFileOpenPermission
-
close
public void close() throws SqlJetExceptionDescription copied from interface:ISqlJetFileClose a file.- Specified by:
closein interfaceISqlJetFile- Throws:
SqlJetException
-
read
public int read(ISqlJetMemoryPointer buffer, int amount, long offset) throws SqlJetIOException
Description copied from interface:ISqlJetFileRead data from a file into a buffer.- Specified by:
readin interfaceISqlJetFile- Returns:
- Throws:
SqlJetIOException
-
write
public void write(ISqlJetMemoryPointer buffer, int amount, long offset) throws SqlJetIOException
Description copied from interface:ISqlJetFileWrite data from a buffer into a file.- Specified by:
writein interfaceISqlJetFile- Throws:
SqlJetIOException
-
truncate
public void truncate(long size) throws SqlJetIOExceptionDescription copied from interface:ISqlJetFileTruncate an open file to a specified size- Specified by:
truncatein interfaceISqlJetFile- Throws:
SqlJetIOException
-
sync
public void sync(java.util.Set<SqlJetSyncFlags> syncFlags) throws SqlJetIOException
Description copied from interface:ISqlJetFileMake sure all writes to a particular file are committed to disk. If dataOnly==false then both the file itself and its metadata (file size, access time, etc) are synced. If dataOnly==true then only the file data is synced. Also make sure that the directory entry for the file has been created by fsync-ing the directory that contains the file. If we do not do this and we encounter a power failure, the directory entry for the journal might not exist after we reboot. The next SqlJet to access the file will not know that the journal exists (because the directory entry for the journal was never created) and the transaction will not roll back - possibly leading to database corruption.- Specified by:
syncin interfaceISqlJetFile- Throws:
SqlJetIOException
-
fileSize
public long fileSize() throws SqlJetExceptionDescription copied from interface:ISqlJetFileDetermine the current size of a file in bytes- Specified by:
fileSizein interfaceISqlJetFile- Returns:
- Throws:
SqlJetException
-
getLockType
public SqlJetLockType getLockType()
Description copied from interface:ISqlJetFileReturns lock type of file.- Specified by:
getLockTypein interfaceISqlJetFile- Returns:
-
lock
public boolean lock(SqlJetLockType lockType) throws SqlJetIOException
Description copied from interface:ISqlJetFileLock the file with the lock specified by parameter locktype - one of the following: (1) SHARED (2) RESERVED (3) PENDING (4) EXCLUSIVE Sometimes when requesting one lock state, additional lock states are inserted in between. The locking might fail on one of the later transitions leaving the lock state different from what it started but still short of its goal. The following chart shows the allowed transitions and the inserted intermediate states: UNLOCKED -> SHARED SHARED -> RESERVED SHARED -> (PENDING) -> EXCLUSIVE RESERVED -> (PENDING) -> EXCLUSIVE PENDING -> EXCLUSIVE This routine will only increase a lock.- Specified by:
lockin interfaceISqlJetFile- Returns:
- Throws:
SqlJetIOException
-
unlock
public boolean unlock(SqlJetLockType lockType) throws SqlJetIOException
Description copied from interface:ISqlJetFileLower the locking level on file descriptor pFile to locktype. locktype must be either NONE or SHARED. If the locking level of the file descriptor is already at or below the requested locking level, this routine is a no-op.- Specified by:
unlockin interfaceISqlJetFile- Returns:
- Throws:
SqlJetIOException
-
checkReservedLock
public boolean checkReservedLock()
Description copied from interface:ISqlJetFileThis routine checks if there is a RESERVED lock held on the specified file by this or any other process. The return value is set unless an I/O error occurs during lock checking.- Specified by:
checkReservedLockin interfaceISqlJetFile- Returns:
-
sectorSize
public int sectorSize()
Description copied from interface:ISqlJetFileReturn the sector size in bytes of the underlying block device for the specified file. This is almost always 512 bytes, but may be larger for some devices. SqlJet code assumes this function cannot fail. It also assumes that if two files are created in the same file-system directory (i.e. a database and its journal file) that the sector size will be the same for both.- Specified by:
sectorSizein interfaceISqlJetFile- Returns:
-
deviceCharacteristics
public java.util.Set<SqlJetDeviceCharacteristics> deviceCharacteristics()
Description copied from interface:ISqlJetFileReturn the device characteristics for the file.- Specified by:
deviceCharacteristicsin interfaceISqlJetFile- Returns:
-
isMemJournal
public boolean isMemJournal()
Description copied from interface:ISqlJetFileReturn true if the file-handle passed as an argument is an in-memory journal- Specified by:
isMemJournalin interfaceISqlJetFile
-
-