RegisterSign In

API Documentation: Class SDBTransaction

Package: com.mckoi.sdb

A transaction class that represents a snapshot view of a Simple Database path instance. This class provides methods for managing the primary data types supported: Files (com.mckoi.sdb.SDBFile) and Tables (com.mckoi.sdb.SDBTable).

THREAD SAFETY NOTICE: Instances of SDBTransaction and instances of all objects created by SDBTransaction are NOT thread safe and may not be interacted with by concurrent threads. Doing so could result in corrupting a path instance state. If you wish to interact with a path instance from multiple threads, an SDBTransaction object must be created for each individual thread.

See the MckoiDDB documentation for examples of using this class to access and modify the contents of a database.

Methods Summary

static void writeForcedTransactionIntroduction(KeyObjectTransaction transaction)
KeyObjectTransaction createBaseTransaction()
SDBRootAddress getBaseRoot()
String getSessionPathName()
long getFileCount()
List<String> fileList()
boolean fileExists(String file_name)
boolean createFile(String file_name)
boolean deleteFile(String file_name)
SDBFile getFile(String file_name)
long getTableCount()
List<String> tableList()
boolean tableExists(String table_name)
boolean createTable(String table_name)
boolean deleteTable(String table_name)
SDBTable getTable(String table_name)
SDBRootAddress commit() throws CommitFaultException
SDBRootAddress publishToSession(SDBSession destination_session)
void finalize() throws Throwable

Method Details

static void writeForcedTransactionIntroduction(KeyObjectTransaction transaction)

Static function used by system functions to write a transaction log that indicates to the commit function that this is an introduced SimpleDatabase transaction with no version checks. This would be used to write out a transaction to be committed where the data has been imported generically (such as a backup recovery procedure).

KeyObjectTransaction createBaseTransaction()

Returns the KeyObjectTransaction object that backs this SDBTransaction. The returned object will not contain the changes made to this SDBTransaction since it was created. The returned KeyObjectTransaction can be changed but the changes will not manifest in the data managed by this SDBTransaction.

It is intended that this object be used for diagnostic and debugging purposes only.

SDBRootAddress getBaseRoot()

Returns the SDBRootAddress that represents the current base root node for this transaction. This can be used by clients to record a snapshot state locally to be recreated into an SDBTransaction without any additional network interaction needed.

String getSessionPathName()

Returns the name of the path of the session of this transaction.

long getFileCount()

Returns the total number of files currently stored in this snapshot.

List<String> fileList()

Provides the list of all file names stored in this snapshot. The contents of the list are fetched dynamically as the list is traversed so can efficiently handle a very large set of files stored.

Note that the returned List object is invalidated if the directory is changed in this transaction (eg, a file is created or deleted). If the directory is changed, a call to 'fileList' must be made to fetch the new updated list.

boolean fileExists(String file_name)

Checks if the file name exists, returning true if it does.

boolean createFile(String file_name)

Creates a new named file of zero length. If returns true, a new file was created in the local transaction. If returns false, the file could not be created because it already exists. Throws an exception if the file name contains an invalid character.

boolean deleteFile(String file_name)

Deletes the given file name from this snapshot. Returns false if the file could not be deleted because it doesn't exist. Returns true if the file exists and was deleted.

SDBFile getFile(String file_name)

Fetches an SDBFile object representing the content of a file in this snapshot. Generates an exception if the file does not exist.

long getTableCount()

Returns the total count of tables currently stored in this snapshot.

List<String> tableList()

Provides the list of all table names stored in this snapshot. The contents of the list are fetched dynamically as the list is traversed so can efficiently handle a very large set of tables stored.

Note that the returned List object is invalidated if the directory is changed in this transaction (eg, a table is created or deleted). If the directory is changed, a call to 'tableList' must be made to fetch the new updated list.

boolean tableExists(String table_name)

Checks if the table exists, and returns true if it does.

boolean createTable(String table_name)

Creates a new named empty table. If returns true, the new table was created in the transaction. If returns false, the table could not be created because it already exists. Throws an exception if the table name contains an invalid character.

boolean deleteTable(String table_name)

Deletes a table with the given name from the local transaction. Returns false if the table could not be deleted because it doesn't exist. Returns true if the table exists and was deleted.

SDBTable getTable(String table_name)

Fetches an SDBTable object representing the content of a table in this snapshot. Generates an exception if the table does not exist.

SDBRootAddress commit()

Commits the current transaction. If no changes have been made then this does nothing. If changes have been made, the proposed changes are passed to the consensus function on the root server managing this path instance. The consensus function may choose to reject a proposed change in which case a commit fault exception is generated.

SDBRootAddress publishToSession(SDBSession destination_session)

Forces the publication of this transaction as the current version of the given SDBSession, causing any data in the database represented by the session to be lost and replaced with the view of the database in this transaction. After this transaction snapshot has been published, any transactions that have snapshot views previous to when this publish operation happened will commit fault if they try and commit.

Use this function with care! This operation bypasses all the commit checks. The operation of publishing a transaction will not fail with a CommitFaultException like committing a transaction can. After this method returns, this transaction will represent the current state of the destination path instance. This does not make a change to this transaction's database instance unless destination_session is this transaction's database instance.

This operation would typically be used if the published state of a database instance needs to be rolled back to a previous version. It can also be used to mount test branches of an active database.

Returns the SDBRootAddress of the transaction created in the destination session.

void finalize()

The GC finalizer method for this object.

The text on this page is licensed under the Creative Commons Attribution 3.0 License. Java is a registered trademark of Oracle and/or its affiliates.
Mckoi is Copyright © 2000 - 2018 Diehl and Associates, Inc. All rights reserved.