|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectorg.apache.kahadb.page.Transaction
public class Transaction
The class used to read/update a PageFile object. Using a transaction allows you to do multiple update operations in a single unit of work.
Nested Class Summary | |
---|---|
static interface |
Transaction.CallableClosure<R,T extends java.lang.Throwable>
This closure interface is intended for the end user implement callbacks for the Transaction.exectue() method. |
static interface |
Transaction.Closure<T extends java.lang.Throwable>
This closure interface is intended for the end user implement callbacks for the Transaction.exectue() method. |
class |
Transaction.InvalidPageIOException
The InvalidPageIOException is thrown if try to load/store a a page with an invalid page id. |
class |
Transaction.PageOverflowIOException
The PageOverflowIOException occurs when a page write is requested and it's data is larger than what would fit into a single page. |
Method Summary | ||
---|---|---|
|
allocate()
Allocates a free page that you can write data to. |
|
|
allocate(int count)
Allocates a block of free pages that you can write data to. |
|
void |
commit()
Commits the transaction to the PageFile as a single 'Unit of Work'. |
|
|
execute(Transaction.CallableClosure<R,T> closure)
Executes a closure and if it does not throw any exceptions, then it commits the transaction. |
|
|
execute(Transaction.Closure<T> closure)
Executes a closure and if it does not throw any exceptions, then it commits the transaction. |
|
void |
free(long pageId)
Frees up a previously allocated page so that it can be re-allocated again. |
|
void |
free(long pageId,
int count)
Frees up a previously allocated sequence of pages so that it can be re-allocated again. |
|
|
free(Page<T> page)
Frees up a previously allocated page so that it can be re-allocated again. |
|
|
free(Page<T> page,
int count)
Frees up a previously allocated sequence of pages so that it can be re-allocated again. |
|
PageFile |
getPageFile()
|
|
protected java.io.File |
getTempFile()
|
|
boolean |
isReadOnly()
|
|
java.util.Iterator<Page> |
iterator()
Allows you to iterate through all active Pages in this object. |
|
java.util.Iterator<Page> |
iterator(boolean includeFreePages)
Allows you to iterate through all active Pages in this object. |
|
|
load(long pageId,
Marshaller<T> marshaller)
Loads a page from disk. |
|
|
load(Page<T> page,
Marshaller<T> marshaller)
Loads a page from disk. |
|
java.io.InputStream |
openInputStream(Page p)
|
|
java.io.OutputStream |
openOutputStream(Page page,
boolean overflow)
|
|
void |
rollback()
Rolls back the transaction. |
|
|
store(Page<T> page,
Marshaller<T> marshaller,
boolean overflow)
|
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Method Detail |
---|
public PageFile getPageFile()
public <T> Page<T> allocate() throws java.io.IOException
Transaction.PageOverflowIOException
- If an disk error occurred.
java.lang.IllegalStateException
- if the PageFile is not loaded
java.io.IOException
public <T> Page<T> allocate(int count) throws java.io.IOException
count
- the number of sequential pages to allocate
Transaction.PageOverflowIOException
- If an disk error occurred.
java.lang.IllegalStateException
- if the PageFile is not loaded
java.io.IOException
public void free(long pageId) throws java.io.IOException
pageId
- the page to free up
Transaction.PageOverflowIOException
- If an disk error occurred.
java.lang.IllegalStateException
- if the PageFile is not loaded
java.io.IOException
public void free(long pageId, int count) throws java.io.IOException
pageId
- the initial page of the sequence that will be getting freedcount
- the number of pages in the sequence
Transaction.PageOverflowIOException
- If an disk error occurred.
java.lang.IllegalStateException
- if the PageFile is not loaded
java.io.IOException
public <T> void free(Page<T> page, int count) throws java.io.IOException
page
- the initial page of the sequence that will be getting freedcount
- the number of pages in the sequence
Transaction.PageOverflowIOException
- If an disk error occurred.
java.lang.IllegalStateException
- if the PageFile is not loaded
java.io.IOException
public <T> void free(Page<T> page) throws java.io.IOException
page
- the page to free up
Transaction.PageOverflowIOException
- If an disk error occurred.
java.lang.IllegalStateException
- if the PageFile is not loaded
java.io.IOException
public <T> void store(Page<T> page, Marshaller<T> marshaller, boolean overflow) throws java.io.IOException
page
- the page to write. The Page object must be fully populated with a valid pageId, type, and data.marshaller
- the marshaler to use to load the data portion of the Page, may be null if you do not wish to write the data.overflow
- If true, then if the page data marshalls to a bigger size than can fit in one page, then additional
overflow pages are automatically allocated and chained to this page to store all the data. If false,
and the overflow condition would occur, then the PageOverflowIOException is thrown.
Transaction.PageOverflowIOException
- If an disk error occurred.
Transaction.PageOverflowIOException
- If the page data marshalls to size larger than maximum page size and overflow was false.
java.lang.IllegalStateException
- if the PageFile is not loaded
java.io.IOException
public java.io.OutputStream openOutputStream(Page page, boolean overflow) throws java.io.IOException
Transaction.PageOverflowIOException
java.io.IOException
public <T> Page<T> load(long pageId, Marshaller<T> marshaller) throws java.io.IOException
pageId
- the id of the page to loadmarshaller
- the marshaler to use to load the data portion of the Page, may be null if you do not wish to load the data.
Transaction.PageOverflowIOException
- If an disk error occurred.
java.lang.IllegalStateException
- if the PageFile is not loaded
java.io.IOException
public <T> void load(Page<T> page, Marshaller<T> marshaller) throws java.io.IOException
page
- - The pageId field must be properly setmarshaller
- the marshaler to use to load the data portion of the Page, may be null if you do not wish to load the data.
Transaction.PageOverflowIOException
- If an disk error occurred.
Transaction.InvalidPageIOException
- If the page is is not valid.
java.lang.IllegalStateException
- if the PageFile is not loaded
java.io.IOException
public java.io.InputStream openInputStream(Page p) throws java.io.IOException
java.io.IOException
load(org.apache.kahadb.page.Page,
org.apache.kahadb.util.Marshaller)
public java.util.Iterator<Page> iterator()
iterator
in interface java.lang.Iterable<Page>
java.lang.IllegalStateException
- if the PageFile is not loadedpublic java.util.Iterator<Page> iterator(boolean includeFreePages)
includeFreePages
- - if true, free pages are included in the iteration
java.lang.IllegalStateException
- if the PageFile is not loadedpublic void commit() throws java.io.IOException
java.io.IOException
public void rollback() throws java.io.IOException
java.io.IOException
protected java.io.File getTempFile()
public boolean isReadOnly()
public <T extends java.lang.Throwable> void execute(Transaction.Closure<T> closure) throws T extends java.lang.Throwable, java.io.IOException
T
- closure
- - the work to get exectued.
T
- if the closure throws it
Transaction.PageOverflowIOException
- If the commit fails.
T extends java.lang.Throwable
java.io.IOException
public <R,T extends java.lang.Throwable> R execute(Transaction.CallableClosure<R,T> closure) throws T extends java.lang.Throwable, java.io.IOException
T
- closure
- - the work to get exectued.
T
- if the closure throws it
Transaction.PageOverflowIOException
- If the commit fails.
T extends java.lang.Throwable
java.io.IOException
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |