|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
java.lang.Objectorg.tmatesoft.sqljet.core.internal.pager.SqlJetPager
public class SqlJetPager
A open page cache is an instance of the following structure. Pager.errCode may be set to SQLITE_IOERR, SQLITE_CORRUPT, or or SQLITE_FULL. Once one of the first three errors occurs, it persists and is returned as the result of every major pager API call. The SQLITE_FULL return code is slightly different. It persists only until the next successful rollback is performed on the pager cache. Also, SQLITE_FULL does not affect the sqlite3PagerGet() and sqlite3PagerLookup() APIs, they may still be used successfully. Managing the size of the database file in pages is a little complicated. The variable Pager.dbSize contains the number of pages that the database image currently contains. As the database image grows or shrinks this variable is updated. The variable Pager.dbFileSize contains the number of pages in the database file. This may be different from Pager.dbSize if some pages have been appended to the database image but not yet written out from the cache to the actual file on disk. Or if the image has been truncated by an incremental-vacuum operation. The Pager.dbOrigSize variable contains the number of pages in the database image when the current transaction was opened. The contents of all three of these variables is only guaranteed to be correct if the boolean Pager.dbSizeValid is true.
| Field Summary |
|---|
| Fields inherited from interface org.tmatesoft.sqljet.core.internal.ISqlJetPager |
|---|
aJournalMagic, JOURNAL, MEMORY_DB, PAGER_MAX_PGNO, SQLJET_DEFAULT_JOURNAL_SIZE_LIMIT, SQLJET_MIN_SECTOR_SIZE |
| Constructor Summary | |
|---|---|
SqlJetPager()
|
|
| Method Summary | |
|---|---|
ISqlJetPage |
acquirePage(int pageNumber,
boolean read)
Acquire a page. |
void |
begin(boolean exclusive)
Acquire a write-lock on the database. |
void |
close()
Shutdown the page cache. |
void |
commitPhaseOne(java.lang.String master,
boolean noSync)
Sync the database file for the pager pPager. |
void |
commitPhaseTwo()
Commit all changes to the database and release the write lock. |
int |
getCacheSize()
|
java.io.File |
getDirectoryName()
Return the directory of the database file. |
ISqlJetFile |
getFile()
Return the file handle for the database file associated with the pager. |
java.io.File |
getFileName()
Return the path of the database file. |
ISqlJetFileSystem |
getFileSystem()
Return the file system for the pager. |
SqlJetPagerJournalMode |
getJournalMode()
Get the journal-mode for this pager. |
java.io.File |
getJournalName()
Return the path of the journal file. |
long |
getJournalSizeLimit()
Get the size-limit used for persistent journal files. |
SqlJetPagerLockingMode |
getLockingMode()
Get the locking-mode for this pager. |
int |
getMaxPageCount()
Return the current maximum page count. |
ISqlJetPage |
getPage(int pageNumber)
Just call acquire( pageNumber, true); |
int |
getPageCount()
Return the total number of pages in the disk file associated with pager. |
int |
getPageSize()
Get the page size. |
int |
getRefCount()
Return the number of references to the pager. |
SqlJetSafetyLevel |
getSafetyLevel()
Get safety level |
ISqlJetMemoryPointer |
getTempSpace()
Return a pointer to the "temporary page" buffer held internally by the pager. |
int |
imageSize()
Return the current size of the database file image in pages. |
boolean |
isNoSync()
Return true if fsync() calls are disabled for this pager. |
boolean |
isReadOnly()
Return TRUE if the database file is opened read-only. |
ISqlJetPage |
lookupPage(int pageNumber)
Acquire a page if it is already in the in-memory cache. |
void |
open(ISqlJetFileSystem fileSystem,
java.io.File fileName,
java.util.Set<SqlJetPagerFlags> flags,
SqlJetFileType type,
java.util.Set<SqlJetFileOpenPermission> permissions)
Open a new page cache. |
void |
openSavepoint(int nSavepoint)
Ensure that there are at least nSavepoint savepoints open. |
void |
pageCallback(ISqlJetPage page)
|
void |
readFileHeader(int count,
ISqlJetMemoryPointer buffer)
Read the first N bytes from the beginning of the file into memory that buffer points to. |
void |
rollback()
Rollback all changes. |
void |
savepoint(SqlJetSavepointOperation op,
int iSavepoint)
Parameter op is always either SAVEPOINT_ROLLBACK or SAVEPOINT_RELEASE. |
void |
setBusyhandler(ISqlJetBusyHandler busyHandler)
Set the busy handler function. |
void |
setCacheSize(int cacheSize)
Change the maximum number of in-memory pages that are allowed. |
void |
setJournalMode(SqlJetPagerJournalMode journalMode)
Set the journal-mode for this pager. |
void |
setJournalSizeLimit(long limit)
Set the size-limit used for persistent journal files. |
void |
setLockingMode(SqlJetPagerLockingMode lockingMode)
Set the locking-mode for this pager. |
void |
setMaxPageCount(int maxPageCount)
Attempt to set the maximum database page count if mxPage is positive. |
int |
setPageSize(int pageSize)
Set the page size to pageSize. |
void |
setReiniter(ISqlJetPageCallback reinitier)
Set the reinitializer for this pager. |
void |
setSafetyLevel(SqlJetSafetyLevel safetyLevel)
Set safety level |
void |
sync()
Sync the pager file to disk. |
void |
truncateImage(int pagesNumber)
Truncate the in-memory database file image to nPage pages. |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Constructor Detail |
|---|
public SqlJetPager()
| Method Detail |
|---|
public void open(ISqlJetFileSystem fileSystem,
java.io.File fileName,
java.util.Set<SqlJetPagerFlags> flags,
SqlJetFileType type,
java.util.Set<SqlJetFileOpenPermission> permissions)
throws SqlJetException
ISqlJetPagerISqlJetPager.getPage(int) and is only held open until the last
page is released using #unref(ISqlJetPage).
If fileName is null then a randomly-named temporary file is created and
used as the file to be cached. The file will be deleted automatically
when it is closed.
If fileName is ISqlJetPager.MEMORY_DB then all information is held in cache.
It is never written to disk. This can be used to implement an in-memory
database.
open in interface ISqlJetPagerfileSystem - The file system to usefileName - Name of the database file to openflags - flags controlling this filetype - file type passed through to
ISqlJetFileSystem.open(java.io.File, SqlJetFileType, Set)permissions - permissions passed through to
ISqlJetFileSystem.open(java.io.File, SqlJetFileType, Set)
SqlJetExceptionpublic java.io.File getDirectoryName()
ISqlJetPager
getDirectoryName in interface ISqlJetPagerpublic java.io.File getFileName()
ISqlJetPager
getFileName in interface ISqlJetPagerpublic ISqlJetFileSystem getFileSystem()
ISqlJetPager
getFileSystem in interface ISqlJetPagerpublic ISqlJetFile getFile()
ISqlJetPager
getFile in interface ISqlJetPagerpublic java.io.File getJournalName()
ISqlJetPager
getJournalName in interface ISqlJetPagerpublic boolean isNoSync()
ISqlJetPager
isNoSync in interface ISqlJetPagerpublic boolean isReadOnly()
ISqlJetPager
isReadOnly in interface ISqlJetPagerpublic SqlJetPagerLockingMode getLockingMode()
ISqlJetPager
getLockingMode in interface ISqlJetPagerpublic void setLockingMode(SqlJetPagerLockingMode lockingMode)
ISqlJetPager
setLockingMode in interface ISqlJetPagerpublic SqlJetPagerJournalMode getJournalMode()
ISqlJetPager
getJournalMode in interface ISqlJetPagerpublic void setJournalMode(SqlJetPagerJournalMode journalMode)
ISqlJetPager
setJournalMode in interface ISqlJetPagerpublic long getJournalSizeLimit()
ISqlJetPager
getJournalSizeLimit in interface ISqlJetPagerpublic void setJournalSizeLimit(long limit)
ISqlJetPager
setJournalSizeLimit in interface ISqlJetPagerpublic SqlJetSafetyLevel getSafetyLevel()
ISqlJetPager
getSafetyLevel in interface ISqlJetPagerpublic void setSafetyLevel(SqlJetSafetyLevel safetyLevel)
ISqlJetPager
setSafetyLevel in interface ISqlJetPagerpublic ISqlJetMemoryPointer getTempSpace()
ISqlJetPager
getTempSpace in interface ISqlJetPagerpublic void setBusyhandler(ISqlJetBusyHandler busyHandler)
ISqlJetPager
setBusyhandler in interface ISqlJetPagerpublic void setReiniter(ISqlJetPageCallback reinitier)
ISqlJetPager
setReiniter in interface ISqlJetPager
public int setPageSize(int pageSize)
throws SqlJetException
ISqlJetPager
setPageSize in interface ISqlJetPagerSqlJetExceptionpublic int getPageSize()
ISqlJetPager
getPageSize in interface ISqlJetPager
public void setMaxPageCount(int maxPageCount)
throws SqlJetException
ISqlJetPager
setMaxPageCount in interface ISqlJetPagerSqlJetExceptionpublic int getMaxPageCount()
ISqlJetPager
getMaxPageCount in interface ISqlJetPagerpublic void setCacheSize(int cacheSize)
ISqlJetPager
setCacheSize in interface ISqlJetPagerpublic int getCacheSize()
getCacheSize in interface ISqlJetPager
public void readFileHeader(int count,
ISqlJetMemoryPointer buffer)
throws SqlJetIOException
ISqlJetPager
readFileHeader in interface ISqlJetPagerSqlJetIOException
public int getPageCount()
throws SqlJetException
ISqlJetPager
getPageCount in interface ISqlJetPagerSqlJetException - if pager is in error state.
public void close()
throws SqlJetException
ISqlJetPager
close in interface ISqlJetPagerSqlJetException
public ISqlJetPage acquirePage(int pageNumber,
boolean read)
throws SqlJetException
ISqlJetPagerISqlJetPager.lookupPage(int). Both this routine and
ISqlJetPager.lookupPage(int) attempt to find a page in the in-memory cache
first. If the page is not already in memory, this routine goes to disk to
read it in whereas ISqlJetPager.lookupPage(int) just returns 0. This routine
acquires a read-lock the first time it has to go to disk, and could also
playback an old journal if necessary. Since ISqlJetPager.lookupPage(int)
never goes to disk, it never has to deal with locks or journal files.
If noContent is false, the page contents are actually read from disk. If
noContent is true, it means that we do not care about the contents of the
page at this time, so do not do a disk read. Just fill in the page
content with zeros. But mark the fact that we have not read the content
by setting the PgHdr.needRead flag. Later on, if sqlite3PagerWrite() is
called on this page or if this routine is called again with noContent==0,
that means that the content is needed and the disk read should occur at
that point.
acquirePage in interface ISqlJetPagerpageNumber - Page number to fetchread - Do not bother reading content from disk if false
SqlJetException
public ISqlJetPage getPage(int pageNumber)
throws SqlJetException
ISqlJetPager
getPage in interface ISqlJetPagerpageNumber - Page number to fetch
SqlJetException
public ISqlJetPage lookupPage(int pageNumber)
throws SqlJetException
ISqlJetPagerISqlJetPager.getPage(int). The difference between this routine and
ISqlJetPager.getPage(int) is that ISqlJetPager.getPage(int) will go to the disk
and read in the page if the page is not already in cache. This routine
returns null if the page is not in cache or if a disk I/O error has ever
happened.
lookupPage in interface ISqlJetPagerpageNumber - Page number to lookup
SqlJetExceptionpublic void truncateImage(int pagesNumber)
ISqlJetPager
truncateImage in interface ISqlJetPagerpublic int imageSize()
ISqlJetPager
imageSize in interface ISqlJetPager
public void begin(boolean exclusive)
throws SqlJetException
ISqlJetPager
begin in interface ISqlJetPagerSqlJetException
public void commitPhaseOne(java.lang.String master,
boolean noSync)
throws SqlJetException
ISqlJetPager
commitPhaseOne in interface ISqlJetPagerSqlJetException
public void commitPhaseTwo()
throws SqlJetException
ISqlJetPager
commitPhaseTwo in interface ISqlJetPagerSqlJetException
public void rollback()
throws SqlJetException
ISqlJetPager
rollback in interface ISqlJetPagerSqlJetException
public void sync()
throws SqlJetIOException
ISqlJetPager
sync in interface ISqlJetPagerSqlJetIOExceptionpublic int getRefCount()
ISqlJetPager
getRefCount in interface ISqlJetPagerpublic void pageCallback(ISqlJetPage page)
pageCallback in interface ISqlJetPageCallback
public void openSavepoint(int nSavepoint)
throws SqlJetException
openSavepoint in interface ISqlJetPagerSqlJetException
public void savepoint(SqlJetSavepointOperation op,
int iSavepoint)
throws SqlJetException
savepoint in interface ISqlJetPagerSqlJetException
|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||