#include <database.h>
Inheritance diagram for dbDatabase:
Public Types | |
typedef void(* | dbErrorHandler )(int error, char const *msg, int msgarg, void *context) |
enum | dbAccessType { dbReadOnly = 0, dbAllAccess = 1 } |
enum | DetachFlags { COMMIT = 1, DESTROY_CONTEXT = 2 } |
enum | dbErrorClass { NoError, QueryError, ArithmeticError, IndexOutOfRangeError, DatabaseOpenError, FileError, OutOfMemoryError, Deadlock, NullReferenceError, FileLimitExeeded, DatabaseReadOnly } |
Public Member Functions | |
bool | open (char_t const *databaseName, time_t transactionCommitDelay=0, int openAttr=dbFile::no_buffering) |
bool | open (dbFile *file, time_t transactionCommitDelay=0, bool deleteFileOnClose=false) |
bool | open (OpenParameters ¶ms) |
virtual void | close () |
void | commit () |
void | executeBatch () |
void | precommit () |
void | rollback () |
void | attach () |
void | detach (int flags=COMMIT|DESTROY_CONTEXT) |
void | lock (dbLockType type=dbExclusiveLock) |
bool | backup (char_t const *backupFileName, bool compactify) |
bool | backup (dbOSFile *file, bool compactify) |
bool | restore (char_t const *backupFileName, char_t const *databaseFileName) |
int | getVersion () |
void | assign (dbTableDescriptor &desc) |
dbTableDescriptor * | lookupTable (dbTableDescriptor *desc) |
void | setConcurrency (unsigned nThreads) |
offs_t | getAllocatedSize () |
void | allowColumnsDeletion (bool enabled=true) |
bool | prepareQuery (dbAnyCursor *cursor, dbQuery &query) |
dbErrorHandler | setErrorHandler (dbErrorHandler newHandler, void *errorHandlerContext=NULL) |
virtual void | scheduleBackup (char_t const *fileName, time_t periodSec) |
virtual void | handleError (dbErrorClass error, char const *msg=NULL, int arg=0) |
void | insertRecord (dbTableDescriptor *table, dbAnyReference *ref, void const *record, bool batch) |
offs_t | used () |
bool | isOpen () const |
offs_t | getDatabaseSize () |
void | setFileExtensionQuantum (offs_t quantum) |
void | setFileSizeLimit (offs_t limit) |
template<class T> dbReference< T > | insert (T const &record) |
template<class T> dbReference< T > | batchInsert (T const &record) |
dbDatabase (dbAccessType type=dbAllAccess, size_t poolSize=0, size_t dbExtensionQuantum=dbDefaultExtensionQuantum, size_t dbInitIndexSize=dbDefaultInitIndexSize, int nThreads=1) | |
virtual | ~dbDatabase () |
Public Attributes | |
dbAccessType | accessType |
size_t | extensionQuantum |
size_t | initIndexSize |
Static Public Attributes | |
unsigned | dbParallelScanThreshold |
Protected Member Functions | |
dbTableDescriptor * | loadMetaTable () |
void | releaseFile () |
virtual void | replicatePage (offs_t pageOffs, void *pageData) |
void | delayedCommit () |
void | backupScheduler () |
void | commit (dbDatabaseThreadContext *ctx) |
offs_t | getPos (oid_t oid) |
void | setPos (oid_t oid, offs_t pos) |
dbRecord * | getRow (dbGetTie &tie, oid_t oid) |
void | getHeader (dbRecord &rec, oid_t oid) |
byte * | put (oid_t oid) |
byte * | get (oid_t oid) |
dbRecord * | putRow (dbPutTie &tie, oid_t oid, size_t newSize) |
dbRecord * | putRow (dbPutTie &tie, oid_t oid) |
byte * | put (dbPutTie &tie, oid_t oid) |
void | restoreTablesConsistency () |
void | applyIndex (dbFieldDescriptor *field, dbSearchContext &sc) |
bool | isIndexApplicable (dbAnyCursor *cursor, dbExprNode *expr, dbQuery &query, dbFieldDescriptor *&indexedField, bool &truncate, bool ascent, bool forAll) |
bool | isIndexApplicableToExpr (dbSearchContext &sc, dbExprNode *expr) |
bool | followInverseReference (dbExprNode *expr, dbExprNode *andExpr, dbAnyCursor *cursor, oid_t iref) |
bool | existsInverseReference (dbExprNode *expr, int nExistsClauses) |
bool | evaluateBoolean (dbExprNode *expr, oid_t oid, dbTableDescriptor *table, dbAnyCursor *cursor) |
size_t | evaluateString (dbExprNode *expr, oid_t oid, dbTableDescriptor *table, char_t *buf, size_t bufSize) |
void | evaluate (dbExprNode *expr, oid_t oid, dbTableDescriptor *table, dbSynthesizedAttribute &result) |
void | select (dbAnyCursor *cursor) |
void | select (dbAnyCursor *cursor, dbQuery &query) |
void | traverse (dbAnyCursor *cursor, dbQuery &query) |
void | update (oid_t oid, dbTableDescriptor *table, void const *record) |
void | remove (dbTableDescriptor *table, oid_t oid) |
offs_t | allocate (offs_t size, oid_t oid=0) |
void | free (offs_t pos, offs_t size) |
void | extend (offs_t size) |
void | cloneBitmap (offs_t pos, offs_t size) |
oid_t | allocateId () |
void | freeId (oid_t oid) |
void | updateCursors (oid_t oid, bool removed=false) |
oid_t | allocatePage () |
void | freePage (oid_t oid) |
oid_t | allocateRow (oid_t tableId, size_t size, dbTableDescriptor *desc=NULL) |
void | allocateRow (oid_t tableId, oid_t oid, size_t size, dbTableDescriptor *desc) |
void | freeRow (oid_t tableId, oid_t oid, dbTableDescriptor *desc=NULL) |
void | beginTransaction (dbLockType type) |
void | endTransaction (dbDatabaseThreadContext *ctx) |
void | initializeMetaTable () |
bool | loadScheme () |
bool | completeDescriptorsInitialization () |
void | reformatTable (oid_t tableId, dbTableDescriptor *desc) |
void | addIndices (dbTableDescriptor *desc) |
oid_t | addNewTable (dbTableDescriptor *desc) |
void | updateTableDescriptor (dbTableDescriptor *desc, oid_t tableId, dbTable *table) |
void | removeInverseReferences (dbTableDescriptor *desc, oid_t oid) |
void | insertInverseReference (dbFieldDescriptor *desc, oid_t reverseId, oid_t targetId) |
void | removeInverseReference (dbFieldDescriptor *desc, oid_t reverseId, oid_t targetId) |
void | deleteTable (dbTableDescriptor *desc) |
void | dropTable (dbTableDescriptor *desc) |
void | createIndex (dbFieldDescriptor *fd) |
void | createHashTable (dbFieldDescriptor *fd) |
void | dropIndex (dbFieldDescriptor *fd) |
void | dropHashTable (dbFieldDescriptor *fd) |
void | linkTable (dbTableDescriptor *table, oid_t tableId) |
void | unlinkTable (dbTableDescriptor *table) |
bool | wasReserved (offs_t pos, offs_t size) |
void | reserveLocation (dbLocation &location, offs_t pos, offs_t size) |
void | commitLocation () |
dbTableDescriptor * | findTable (char_t const *name) |
dbTableDescriptor * | findTableByName (char_t const *name) |
dbTableDescriptor * | getTables () |
void | cleanupOnOpenError () |
void | setDirty () |
Static Protected Member Functions | |
void thread_proc | delayedCommitProc (void *arg) |
void thread_proc | backupSchedulerProc (void *arg) |
void _fastcall | execute (dbExprNode *expr, dbInheritedAttribute &iattr, dbSynthesizedAttribute &sattr) |
void | deleteCompiledQuery (dbExprNode *tree) |
Protected Attributes | |
dbThreadContext< dbDatabaseThreadContext > | threadContext |
dbThreadPool | threadPool |
dbHeader * | header |
int4 * | dirtyPagesMap |
unsigned | parThreads |
bool | modified |
int | curr |
bool | uncommittedChanges |
offs_t | dbFileExtensionQuantum |
offs_t | dbFileSizeLimit |
volatile int | commitInProgress |
volatile int | concurrentTransId |
size_t | currRBitmapPage |
size_t | currRBitmapOffs |
size_t | currPBitmapPage |
size_t | currPBitmapOffs |
dbLocation * | reservedChain |
size_t | committedIndexSize |
size_t | currIndexSize |
oid_t | updatedRecordId |
dbFile * | file |
dbMutex | mutex |
dbSemaphore | writeSem |
dbSemaphore | readSem |
dbSemaphore | upgradeSem |
dbEvent | backupCompletedEvent |
dbMonitor | monitor |
dbPagePool | pool |
dbTableDescriptor * | tables |
int * | bitmapPageAvailableSpace |
bool | opened |
offs_t | allocatedSize |
int | forceCommitCount |
time_t | commitDelay |
time_t | commitTimeout |
time_t | commitTimerStarted |
dbMutex | commitThreadSyncMutex |
dbMutex | delayedCommitStartTimerMutex |
dbMutex | delayedCommitStopTimerMutex |
dbEvent | commitThreadSyncEvent |
dbEvent | delayedCommitStartTimerEvent |
dbEvent | delayedCommitStopTimerEvent |
dbDatabaseThreadContext * | delayedCommitContext |
dbMutex | backupMutex |
dbEvent | backupInitEvent |
char_t * | backupFileName |
time_t | backupPeriod |
dbThread | backupThread |
dbThread | commitThread |
dbTableDescriptor * | batchList |
int | accessCount |
dbL2List | threadContextList |
dbMutex | threadContextListMutex |
dbErrorHandler | errorHandler |
void * | errorHandlerContext |
bool | confirmDeleteColumns |
int | schemeVersion |
dbVisitedObject * | visitedChain |
bool | deleteFile |
Friends | |
class | dbSelection |
class | dbAnyCursor |
class | dbHashTable |
class | dbQuery |
class | dbRtree |
class | dbRtreePage |
class | dbBtree |
class | dbBtreePage |
class | dbThickBtreePage |
class | dbInheritedAttribute |
class | dbParallelQueryContext |
class | dbServer |
class | dbPagePool |
class | dbBlob |
class | dbBlobIterator |
class | dbBlobReadIterator |
class | dbBlobWriteIterator |
class | dbAnyContainer |
class | dbGetTie |
class | dbPutTie |
class | dbUserFunctionArgument |
class | dbCLI |
class | GiSTdb |
class | dbBtreeIterator |
class | dbRtreeIterator |
class | dbTableIterator |
|
Error codes |
|
Database constructor
|
|
Database destructor |
|
Add new indices to the table.
|
|
Add new table to the database
|
|
Allocate object
|
|
Allocate object identifier
|
|
Allocate page object
|
|
Allocate record with specified OID
|
|
Allocate record
|
|
Enable deletion of columns from the table when correspondent fields are renamed from class descriptor. By default it is switched of and database allows to delete fields only from empty table (to prevent unindented loose of data).
|
|
Execute table search using index
|
|
Assign table to the database
|
|
Attach current thread to the database. This method should be executed for all threads except one which opened the database. |
|
Perform backup to the specified file
|
|
Perform backup to the specified file
|
|
backup scheduler thread |
|
Batch insert record in the database. Field of the records will be added to the index at transaction commit time.
|
|
Start transaction (set trtansaction lock)
|
|
Release objects created during open(). This method is used when an error occurs during open. |
|
Clone bitmap page(s). Thisd method is used to clonepages of the bitmap (if them were not already cloned within this transaction) which will ber affected by free method at the end of transaction.
|
|
Close database Reimplemented in dbReplicatedDatabase. |
|
Commit transaction
|
|
Commit transaction |
|
Remove location from list of reserved locations. It is done after location is marked as occupied in bitmap. |
|
Complete descriptors initialization. This method checks all relations between records and assigned pointers to referenced tables and inverse fields
|
|
Create hash table for the field
|
|
Create T-Tree index for the field
|
|
Deltayed commit thread |
|
Destroy compiled query
|
|
Delete table from the database
|
|
Detach thread from the database.
|
|
Drop hash table for the field
|
|
Drop T-Tree index for the field
|
|
Delete all table records
|
|
End transaction (release transaction locks)
|
|
Evaluate expression of arbitrary type.
|
|
Evaluate boolean expression
|
|
Evaluate string expression
|
|
Execute expression. This method is recursively called to calculate value of compund expression.
|
|
Complete all batch inserts |
|
Check whether inverse reference exists for reference or array of reference field
|
|
Check that allocated object fits in the database file and extend database file if it is not true
|
|
Find table using symbol name
|
|
Find table by name. This method get symbol for specified name and call
|
|
Free object
|
|
Release obejct identifier
|
|
Deallocate page object
|
|
Deallocate record
|
|
Get readonly pointer to the body of page object
|
|
Get size allocated in the database since open
|
|
Return current size of the database. It can be larger than actual size fo database file (because it includes space reserved for uncommitted data)
|
|
Get object header
|
|
Get position of the object in the database file
|
|
Get table row
|
|
Get list of tables attached to the database
|
|
Get database version |
|
Error handler. It can be redifined by application to implement application specific error handling.
|
|
Create meta table descriptor |
|
Insert record in the database
|
|
Insert inverse reference. When reference or array of reference which is part of relation is updated then reference to the updated record is inserted in inverse reference field of all new referenced records (which were not referenced by this field before update).
|
|
Insert record in the database
|
|
Try to execute query using indices. This recursive functions tries to split execution of request in one or more index search operations.
|
|
Checks whether expression can be calculated using indicies.
|
|
Check if database is opened |
|
Link table to the database table list
|
|
Loads all class descriptors. This method should be used SubSQL and any other apllication which is should work with ANY database file.
|
|
Load database schema. This method loads table decriptors from database, compare them with application classes, do necessary reformatting and save update andnew table decriptor in database
|
|
Lock database in specified mode
|
|
Find cloned table desciptor assigned to this database
|
|
Open database with parameters defined in OpenParameters structure
|
|
Open database with user specific implementation of file
|
|
Open database
|
|
Release all locks hold by transaction allowing other clients to proceed but do not flush changes to the disk |
|
Prepare query. This method can be used for explicit compilation of query and it's validation
|
|
Get pointer to the page object which can be used to uodate this object
|
|
Get pointer to the body of page object which can be used to update this object
|
|
Get pointer to the record which can be used to uodate this record. Record length is not changed.
|
|
Get pointer to the record which can be used to uodate this record
|
|
Reformat table according to new format
|
|
Remove record
|
|
Remove inverse reference. When reference or array of reference which is part of relation is updated then reference to the updated record is removed from inverse reference field of all referenced records which are not reference any more from by this field.
|
|
Remove inverse references to the removed record
|
|
Page replicator Reimplemented in dbReplicatedDatabase. |
|
Mark location as reserved. This method is used by allocator to protect hole located in memory allocation bitmap, from been used by recursuve call of allocator (needed to clone bitmap pages).
|
|
Restore database from the backup. Database should not be opened.
|
|
Restore consistency of table list of rows (last record should contain null reference in next field). This method is used during recovery after crash and during rollback. |
|
Rollback transaction |
|
Schedule backup
|
|
Select all records matching the query
|
|
Select all records in the table defined by cursor
|
|
Set concurrency level for sequential search and sort operations. By default, FastDB tries to detect number of CPUs in system and create the same number of threads.
|
|
Mark database as been modified |
|
Set error handler. Handler should be no-return function which perform stack unwind.
|
|
Set database file extension quantum. When new record as appended to the file, OS ussually has to perform two writes: one to write data itself and one to update files metadata. But specifyig file extension quentums we reduce number of cases when fiel metadata has to be updated and os increase performance
|
|
Specify database file size limit. Attempt to exeed this limit cause database error.
|
|
Set position of the object
|
|
Traverse the table using iterato specified in query (START FROM .. FOLLOW BY...)
|
|
Unlink table from the database tables list
|
|
Update record
|
|
Update current records in all openned cursors. Check if specified record is selected by some of cursors and perform update in this case
|
|
Update database table descriptor
|
|
Calcualte total size of all memory used in ther database
|
|
Check if location is reserved
|