org.tmatesoft.sqljet.core.internal
Interface ISqlJetFile

All Known Implementing Classes:
SqlJetFile, SqlJetMemJournal

public interface ISqlJetFile

OS Interface Open File Handle. An ISqlJetFile object represents an open file in the OS interface layer. Individual OS interface implementations will want to subclass this object by appending additional fields for their own use.


Field Summary
static long PENDING_BYTE
           
static long RESERVED_BYTE
           
static long SHARED_FIRST
           
static long SHARED_SIZE
           
 
Method Summary
 boolean checkReservedLock()
          This routine checks if there is a RESERVED lock held on the specified file by this or any other process.
 void close()
          Close a file.
 java.util.Set<SqlJetDeviceCharacteristics> deviceCharacteristics()
          Return the device characteristics for the file.
 long fileSize()
          Determine the current size of a file in bytes
 SqlJetFileType getFileType()
          Returns file type.
 SqlJetLockType getLockType()
          Returns lock type of file.
 java.util.Set<SqlJetFileOpenPermission> getPermissions()
          Returns assiciated permissions.
 boolean isMemJournal()
          Return true if the file-handle passed as an argument is an in-memory journal
 boolean lock(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.
 int read(ISqlJetMemoryPointer buffer, int amount, long offset)
          Read data from a file into a buffer.
 int sectorSize()
          Return the sector size in bytes of the underlying block device for the specified file.
 void sync(java.util.Set<SqlJetSyncFlags> syncFlags)
          Make sure all writes to a particular file are committed to disk.
 void truncate(long size)
          Truncate an open file to a specified size
 boolean unlock(SqlJetLockType lockType)
          Lower the locking level on file descriptor pFile to locktype.
 void write(ISqlJetMemoryPointer buffer, int amount, long offset)
          Write data from a buffer into a file.
 

Field Detail

PENDING_BYTE

static final long PENDING_BYTE
See Also:
Constant Field Values

RESERVED_BYTE

static final long RESERVED_BYTE
See Also:
Constant Field Values

SHARED_FIRST

static final long SHARED_FIRST
See Also:
Constant Field Values

SHARED_SIZE

static final long SHARED_SIZE
See Also:
Constant Field Values
Method Detail

getFileType

SqlJetFileType getFileType()
Returns file type.

Returns:
SqlJetFileType

getPermissions

java.util.Set<SqlJetFileOpenPermission> getPermissions()
Returns assiciated permissions.

Returns:
SqlJetFileOpenPermission

close

void close()
           throws SqlJetException
Close a file.

Throws:
SqlJetException

read

int read(ISqlJetMemoryPointer buffer,
         int amount,
         long offset)
         throws SqlJetIOException
Read data from a file into a buffer.

Parameters:
buffer -
amount -
offset -
Returns:
Throws:
SqlJetIOException

write

void write(ISqlJetMemoryPointer buffer,
           int amount,
           long offset)
           throws SqlJetIOException
Write data from a buffer into a file.

Parameters:
buffer -
amount -
offset -
Throws:
SqlJetIOException

truncate

void truncate(long size)
              throws SqlJetIOException
Truncate an open file to a specified size

Parameters:
size -
Throws:
SqlJetIOException

sync

void sync(java.util.Set<SqlJetSyncFlags> syncFlags)
          throws SqlJetIOException
Make 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.

Parameters:
dataOnly -
full -
Throws:
SqlJetIOException

fileSize

long fileSize()
              throws SqlJetException
Determine the current size of a file in bytes

Returns:
Throws:
SqlJetException

lock

boolean lock(SqlJetLockType lockType)
             throws SqlJetIOException
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. 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.

Parameters:
lockType -
Returns:
Throws:
SqlJetIOException

unlock

boolean unlock(SqlJetLockType lockType)
               throws SqlJetIOException
Lower 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.

Parameters:
lockType -
Returns:
Throws:
SqlJetIOException

checkReservedLock

boolean checkReservedLock()
This 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.

Returns:

getLockType

SqlJetLockType getLockType()
Returns lock type of file.

Returns:

sectorSize

int sectorSize()
Return 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.

Returns:

deviceCharacteristics

java.util.Set<SqlJetDeviceCharacteristics> deviceCharacteristics()
Return the device characteristics for the file.

Returns:

isMemJournal

boolean isMemJournal()
Return true if the file-handle passed as an argument is an in-memory journal