#include <database.h>

Public Types | |
| enum | dbAccessType { dbReadOnly, dbAllAccess, dbConcurrentRead, dbConcurrentUpdate } |
| enum | DetachFlags { COMMIT = 1, DESTROY_CONTEXT = 2 } |
| enum | dbLockType { dbSharedLock, dbExclusiveLock, dbCommitLock } |
| enum | dbErrorClass { NoError, QueryError, ArithmeticError, IndexOutOfRangeError, DatabaseOpenError, FileError, OutOfMemoryError, Deadlock, NullReferenceError, LockRevoked, FileLimitExeeded, InconsistentInverseReference, DatabaseReadOnly } |
| enum | dbThreadMode { dbNotUsePthreads, dbUsePthreads } |
| enum | dbReplicationMode { dbReplicated, dbStandalone } |
| typedef void(* | dbErrorHandler )(int error, char const *msg, int msgarg, void *context) |
Public Member Functions | |
| bool | open (char const *databaseName, char const *fileName=NULL, time_t waitLockTimeoutMsec=INFINITE, time_t commitDelaySec=0) |
| Open database. | |
| bool | open (OpenParameters ¶ms) |
| Open database with parameters defined in OpenParameters structure. | |
| void | close () |
| Close database. | |
| void | commit () |
| Commit transaction. | |
| void | precommit () |
| Release all locks hold by transaction allowing other clients to proceed but do not flush changes to the disk. | |
| void | rollback () |
| Rollback transaction. | |
| void | scheduleBackup (char const *fileName, time_t periodSec) |
| Schedule backup. | |
| void | attach () |
| Attach current thread to the database. | |
| void | attach (dbDatabaseThreadContext *ctx) |
| Set transaction context for the current thread. | |
| void | detach (int flags=COMMIT|DESTROY_CONTEXT) |
| Detach thread from the database. | |
| void | lock (dbLockType lock=dbExclusiveLock) |
| Exclusivly lock the database. | |
| bool | backup (char const *file, bool compactify) |
| Perform backup to the file with specified name. | |
| bool | backup (dbFile *file, bool compactify) |
| Perform backup to the specified file. | |
| void | assign (dbTableDescriptor &desc) |
| Assign table to the database. | |
| void | setConcurrency (unsigned nThreads) |
| Set concurrency level for sequential search and sort operations. | |
| long | getAllocatedSize () |
| Get size allocated in the database since open. | |
| long | getDatabaseSize () |
| Get size of the database file. | |
| int | getNumberOfReaders () |
| Get number of threads accessing database in shared mode (readonly). | |
| int | getNumberOfWriters () |
| Get number of threads accessing database in exclusiveh mode (for update). | |
| int | getNumberOfBlockedReaders () |
| Get number of threads blocked while starting read-only transaction. | |
| int | getNumberOfBlockedWriters () |
| Get number of threads blocked while starting update transaction. | |
| int | getNumberOfUsers () |
| Get number of processes attached to the database. | |
| void | allowColumnsDeletion (bool enabled=true) |
| Enable deletion of columns from the table when correspondent fields are renamed from class descriptor. | |
| bool | prepareQuery (dbAnyCursor *cursor, dbQuery &query) |
| Prepare query. | |
| dbErrorHandler | setErrorHandler (dbErrorHandler newHandler, void *errorHandlerContext=NULL) |
| Set error handler. | |
| virtual void | handleError (dbErrorClass error, char const *msg=NULL, int arg=0) |
| Error handler. | |
| void | insertRecord (dbTableDescriptor *table, dbAnyReference *ref, void const *record) |
| Insert record in the database. | |
| bool | isOpen () const |
| Check if database is opened. | |
| bool | isCommitted () |
| Check if current transaction is committed. | |
| bool | isAttached () |
| Check if thread was attached to the database. | |
| bool | isUpdateTransaction () |
| Check if current transaction is updating database. | |
| int | getVersion () |
| Get database version. | |
| void | setFileSizeLimit (size_t limit) |
| Specify database file size limit. | |
| template<class T> | |
| dbReference< T > | insert (T const &record) |
| Insert record in the database. | |
| dbTableDescriptor * | lookupTable (dbTableDescriptor *desc) |
| Find cloned table desciptor assigned to this database. | |
| void | getMemoryStatistic (dbMemoryStatistic &stat) |
| Get information about state of database memory. | |
| void | setFixedSizeAllocator (size_t minSize, size_t maxSize, size_t quantum, size_t bufSize) |
| Initialize fixed size allocator. | |
| dbDatabase (dbAccessType type=dbAllAccess, size_t dbInitSize=dbDefaultInitDatabaseSize, size_t dbExtensionQuantum=dbDefaultExtensionQuantum, size_t dbInitIndexSize=dbDefaultInitIndexSize, int nThreads=1) | |
| Database constructor. | |
| virtual | ~dbDatabase () |
| Database detructor. | |
Public Attributes | |
| dbAccessType | accessType |
| size_t | initSize |
| size_t | extensionQuantum |
| size_t | initIndexSize |
| offs_t | freeSpaceReuseThreshold |
Static Public Attributes | |
| static char const *const | errorMessage [] |
Protected Member Functions | |
| dbTableDescriptor * | loadMetaTable () |
| Loads all class descriptors. | |
| void | cleanup (dbInitializationMutex::initializationStatus status, int step) |
| void | delayedCommit () |
| void | backupScheduler () |
| virtual bool | isReplicated () |
| void | commit (dbDatabaseThreadContext *ctx) |
| Commit transaction. | |
| void | restoreTablesConsistency () |
| Restore consistency of table list of rows (last record should contain null reference in next field). | |
| bool | isValidOid (oid_t oid) |
| Check if OID corresponds to the valid object. | |
| dbRecord * | getRow (oid_t oid) |
| Get table row. | |
| dbRecord * | putRow (oid_t oid, size_t newSize) |
| Prepare for row insertion or update. | |
| dbRecord * | putRow (oid_t oid) |
| Prepare for object update ithout changing its size. | |
| byte * | get (oid_t oid) |
| Get record by OID. | |
| byte * | put (oid_t oid) |
| Prepare for update of internal object. | |
| bool | isPrefixSearch (dbAnyCursor *cursor, dbExprNode *expr, dbExprNode *andExpr, dbFieldDescriptor *&indexedField) |
| Check whether query is prefix search: "'key' like field+'%'". | |
| bool | isIndexApplicable (dbAnyCursor *cursor, dbExprNode *expr, dbExprNode *andExpr, dbFieldDescriptor *&indexedField) |
| Check whether search can be performed using indices. | |
| bool | isIndexApplicable (dbAnyCursor *cursor, dbExprNode *expr, dbExprNode *andExpr) |
| Check whether expression can be evaluated unsing index. | |
| bool | followInverseReference (dbExprNode *expr, dbExprNode *andExpr, dbAnyCursor *cursor, oid_t iref) |
| If query predicate contains operands from other tables (accessed by references) and inverse references exists, then FastDB performs indexed search in referenced table and then go back using inverse referenced to query table. | |
| bool | existsInverseReference (dbExprNode *expr, int nExistsClauses) |
| Check if there is inverse reference in the table rerefrenced from search predicate. | |
| bool | evaluate (dbExprNode *expr, oid_t oid, dbTable *table, dbAnyCursor *cursor) |
| Evaluate epression. | |
| void | select (dbAnyCursor *cursor) |
| Select all records from the table. | |
| void | select (dbAnyCursor *cursor, dbQuery &query) |
| Execute select query. | |
| void | traverse (dbAnyCursor *cursor, dbQuery &query) |
| Perform table traverse: execute queries with "start from (follow by)" clause. | |
| void | update (oid_t oid, dbTableDescriptor *table, void const *record) |
| Update record. | |
| void | remove (dbTableDescriptor *table, oid_t oid) |
| Remove record from the database. | |
| offs_t | allocate (size_t size, oid_t oid=0) |
| Allocate object in the database e. | |
| void | deallocate (offs_t pos, size_t size) |
| Deallocate region. | |
| void | extend (offs_t size) |
| Checks whther allocated size is greater than size of databae file and recreate memory mapping object with larger size n the last case. | |
| void | cloneBitmap (offs_t pos, size_t size) |
| Clone memory allocation bitmap for region [pos, pos+size). | |
| oid_t | allocateId (int n=1) |
| Allocate object identifier(s). | |
| void | freeId (oid_t oid, int n=1) |
| Free object identifier(s). | |
| void | updateCursors (oid_t oid, bool removed=false) |
| Update record in in all active cursors if it this record is checnged in the database. | |
| void | recovery () |
| Perform database recovery after fault. | |
| bool | checkVersion () |
| Check if program works with correct version of memory mapped object (if memory mapped object is reallocated by some client, its version number is incremented, so all other client will be able to notice it and also reallocate their memory mapping objects. | |
| oid_t | allocateObject (dbInternalObject marker) |
| Allocate internal object. | |
| oid_t | allocateRow (oid_t tableId, size_t size) |
| Allocate record. | |
| void | allocateRow (oid_t tableId, oid_t oid, size_t size) |
| Allocate record with specified OID. | |
| void | freeRow (oid_t tableId, oid_t oid) |
| Delete row from the table. | |
| void | freeObject (oid_t oid) |
| Free internal object. | |
| bool | beginTransaction (dbLockType) |
| Start database transaction. | |
| void | endTransaction () |
| End transaction. | |
| void | endTransaction (dbDatabaseThreadContext *ctx) |
| End transaction with specified thread context. | |
| virtual void | waitTransactionAcknowledgement () |
| void | initializeMetaTable () |
| Initialize database metatable (table containning information about all other tables included metatable itself). | |
| bool | loadScheme (bool alter) |
| Load database scheme. | |
| bool | completeDescriptorsInitialization () |
| This method is invoked by SubSQL to complete table descriptors initialization after loading of all table descriptoes from thr database. | |
| void | reformatTable (oid_t tableId, dbTableDescriptor *desc) |
| Reformat table according to new format. | |
| bool | addIndices (bool alter, dbTableDescriptor *desc) |
| Add new indices to the table. | |
| oid_t | addNewTable (dbTableDescriptor *desc) |
| Add new table to the database. | |
| void | updateTableDescriptor (dbTableDescriptor *desc, oid_t tableId) |
| Update database table descriptor. | |
| void | insertInverseReference (dbFieldDescriptor *fd, oid_t reverseId, oid_t targetId) |
| Insert inverse reference. | |
| void | removeInverseReferences (dbTableDescriptor *desc, oid_t oid) |
| Remove inverse references to the removed record. | |
| void | removeInverseReference (dbFieldDescriptor *fd, oid_t reverseId, oid_t targetId) |
| Remove inverse reference. | |
| void | deleteTable (dbTableDescriptor *desc) |
| Delete table from the database. | |
| void | dropTable (dbTableDescriptor *desc) |
| Delete all table records. | |
| void | createIndex (dbFieldDescriptor *fd) |
| Create T-Tree index for the field. | |
| void | createHashTable (dbFieldDescriptor *fd) |
| Create hash table for the field. | |
| void | dropIndex (dbFieldDescriptor *fd) |
| Drop T-Tree index for the field. | |
| void | dropHashTable (dbFieldDescriptor *fd) |
| Drop hash table for the field. | |
| void | linkTable (dbTableDescriptor *table, oid_t tableId) |
| Link table to the database table list. | |
| void | unlinkTable (dbTableDescriptor *table) |
| Unlink table from the database tables list. | |
| bool | wasReserved (offs_t pos, size_t size) |
| Check if location is reserved. | |
| void | reserveLocation (dbLocation &location, offs_t pos, size_t size) |
| Mark location as reserved. | |
| void | commitLocation () |
| Remove location from list of reserved locations. | |
| dbTableDescriptor * | findTable (char const *name) |
| Find table using symbol name. | |
| dbTableDescriptor * | findTableByName (char const *name) |
| Find table by name. | |
| dbTableDescriptor * | getTables () |
| Get list of tables attached to the database. | |
| void | setDirty () |
| Mark database as been modified. | |
| bool | isFree (offs_t pos, int objBitSize) |
| Check if given location is free. | |
| void | markAsAllocated (offs_t pos, int objBitSize) |
| Set in memory allocation bitmap bits corresponding to the object. | |
Static Protected Member Functions | |
| static void thread_proc | delayedCommitProc (void *arg) |
| static void thread_proc | backupSchedulerProc (void *arg) |
| static void _fastcall | execute (dbExprNode *expr, dbInheritedAttribute &iattr, dbSynthesizedAttribute &sattr) |
| Execute expression. | |
| static void | deleteCompiledQuery (dbExprNode *tree) |
| Cleanup compiled query. | |
Protected Attributes | |
| dbThreadPool | threadPool |
| FixedSizeAllocator | fixedSizeAllocator |
| dbThreadContext < dbDatabaseThreadContext > | threadContext |
| byte * | baseAddr |
| dbHeader * | header |
| offs_t * | currIndex |
| offs_t * | index [2] |
| unsigned | parThreads |
| bool | modified |
| size_t | currRBitmapPage |
| size_t | currRBitmapOffs |
| size_t | currPBitmapPage |
| size_t | currPBitmapOffs |
| dbLocation * | reservedChain |
| char * | databaseName |
| int | databaseNameLen |
| char * | fileName |
| int | version |
| size_t | committedIndexSize |
| size_t | currIndexSize |
| oid_t | updatedRecordId |
| unsigned | waitLockTimeout |
| size_t | fileSizeLimit |
| bool | uncommittedChanges |
| dbHashFunction | hashFunction |
| dbFile | file |
| dbSharedObject< dbMonitor > | shm |
| dbGlobalCriticalSection | cs |
| dbGlobalCriticalSection | mutatorCS |
| dbInitializationMutex | initMutex |
| dbSemaphore | writeSem |
| dbSemaphore | readSem |
| dbSemaphore | upgradeSem |
| dbEvent | backupCompletedEvent |
| dbMonitor * | monitor |
| dbTableDescriptor * | tables |
| int * | bitmapPageAvailableSpace |
| bool | opened |
| offs_t | allocatedSize |
| offs_t | deallocatedSize |
| time_t | commitDelay |
| time_t | commitTimeout |
| time_t | commitTimerStarted |
| dbMutex | delayedCommitStartTimerMutex |
| dbMutex | delayedCommitStopTimerMutex |
| dbLocalEvent | delayedCommitStartTimerEvent |
| dbEvent | delayedCommitStopTimerEvent |
| dbLocalEvent | commitThreadSyncEvent |
| bool | delayedCommitEventsOpened |
| dbMutex | backupMutex |
| dbLocalEvent | backupInitEvent |
| char * | backupFileName |
| time_t | backupPeriod |
| bool | stopDelayedCommitThread |
| dbThread | backupThread |
| dbThread | commitThread |
| int | accessCount |
| dbL2List | threadContextList |
| dbMutex | threadContextListMutex |
| dbErrorHandler | errorHandler |
| void * | errorHandlerContext |
| int | schemeVersion |
| dbVisitedObject * | visitedChain |
| bool | confirmDeleteColumns |
| int | maxClientId |
| int | selfId |
| unsigned | parallelScanThreshold |
Static Protected Attributes | |
| static size_t | internalObjectSize [] |
Friends | |
| class | dbSelection |
| class | dbAnyCursor |
| class | dbHashTable |
| class | dbQuery |
| class | dbTtree |
| class | dbTtreeNode |
| class | dbRtree |
| class | dbRtreePage |
| class | dbParallelQueryContext |
| class | dbServer |
| class | dbColumnBinding |
| class | dbUserFunctionArgument |
| class | dbAnyContainer |
| class | dbFile |
| class | dbCLI |
| class | GiSTdb |
| class | dbHArray |
Classes | |
| struct | dbLocation |
| struct | OpenParameters |
| Structure to specify database open parameters. More... | |
| typedef void(* dbErrorHandler)(int error, char const *msg, int msgarg, void *context) |
| enum dbAccessType |
| enum DetachFlags |
| enum dbLockType |
| enum dbErrorClass |
| enum dbThreadMode |
| enum dbReplicationMode |
| dbDatabase | ( | dbAccessType | type = dbAllAccess, |
|
| size_t | dbInitSize = dbDefaultInitDatabaseSize, |
|||
| size_t | dbExtensionQuantum = dbDefaultExtensionQuantum, |
|||
| size_t | dbInitIndexSize = dbDefaultInitIndexSize, |
|||
| int | nThreads = 1 | |||
| ) |
Database constructor.
| type | access type: dbDatabase::dbReadOnly or dbDatabase::dbAllAcces | |
| dbInitSize | initial size of the database. If FastDB is compiled with DISKLESS_CONFIGURATION option, then in this parameter MAXIMAL size of the database should be specified (in this mode database can not be reallocated) | |
| dbExtensionQuantum | quantum for extending memory allocation bitmap | |
| dbInitIndexSize | initial index size (objects) | |
| nThreads | concurrency level for sequential search and sort operations |
| ~dbDatabase | ( | ) | [virtual] |
Database detructor.
| bool open | ( | char const * | databaseName, | |
| char const * | fileName = NULL, |
|||
| time_t | waitLockTimeoutMsec = INFINITE, |
|||
| time_t | commitDelaySec = 0 | |||
| ) |
Open database.
| databaseName | database name | |
| fielName | path to the database file (if null, then file name daatbaseName + ".fdb" will be used) | |
| waitLockTimeoutMsec | timeout for waiting locks, by default disabled | |
| commitDelaySec | delayed commit timeout, by default disabled |
true if database was successfully opened | bool open | ( | OpenParameters & | params | ) |
Open database with parameters defined in OpenParameters structure.
| params | parameters for openning database |
true if database was successfully opened | void close | ( | ) |
Close database.
| void commit | ( | ) |
Commit transaction.
| void precommit | ( | ) |
Release all locks hold by transaction allowing other clients to proceed but do not flush changes to the disk.
| void rollback | ( | ) |
Rollback transaction.
| void scheduleBackup | ( | char const * | fileName, | |
| time_t | periodSec | |||
| ) |
Schedule backup.
| fileName | path to backup file. If name ends with '?', then each backup willbe placed in seprate file with '?' replaced with current timestamp | |
| periodSec | preiod of performing backups in seconds |
| void attach | ( | ) |
Attach current thread to the database.
This method should be executed for all threads except one which opened the database.
| void attach | ( | dbDatabaseThreadContext * | ctx | ) |
Set transaction context for the current thread.
Using this method allows to share the same transaction between different threads
| ctx | transaction context which will be associated with the current thread |
| void detach | ( | int | flags = COMMIT|DESTROY_CONTEXT |
) |
Detach thread from the database.
| flags | mask of DetachFlags COMMIT and DESTROY_CONTEXT |
| void lock | ( | dbLockType | lock = dbExclusiveLock |
) | [inline] |
Exclusivly lock the database.
| bool backup | ( | char const * | file, | |
| bool | compactify | |||
| ) |
Perform backup to the file with specified name.
| file | path to the backup file | |
| comactify | if true then databae will be compactificated during backup - i.e. all used objects will be placed together without holes; if false then backup is performed by just writting memory mapped object to the backup file. |
| bool backup | ( | dbFile * | file, | |
| bool | compactify | |||
| ) |
Perform backup to the specified file.
| file | opened file to path to the backup file. This file will not be closed after backup completion. | |
| comactify | if true then databae will be compactificated during backup - i.e. all used objects will be placed together without holes; if false then backup is performed by just writting memory mapped object to the backup file. |
| void assign | ( | dbTableDescriptor & | desc | ) | [inline] |
Assign table to the database.
| desc | table descriptor |
| void setConcurrency | ( | unsigned | nThreads | ) |
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.
| nThreads | maximal number of threads to be created for perfroming cincurrent sequential search and sorting. |
| long getAllocatedSize | ( | ) | [inline] |
Get size allocated in the database since open.
| long getDatabaseSize | ( | ) | [inline] |
Get size of the database file.
| int getNumberOfReaders | ( | ) | [inline] |
Get number of threads accessing database in shared mode (readonly).
| int getNumberOfWriters | ( | ) | [inline] |
Get number of threads accessing database in exclusiveh mode (for update).
| int getNumberOfBlockedReaders | ( | ) | [inline] |
Get number of threads blocked while starting read-only transaction.
| int getNumberOfBlockedWriters | ( | ) | [inline] |
Get number of threads blocked while starting update transaction.
| int getNumberOfUsers | ( | ) | [inline] |
Get number of processes attached to the database.
| void allowColumnsDeletion | ( | bool | enabled = true |
) | [inline] |
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).
| enabled | true to enable column deletion in non empty tables |
| bool prepareQuery | ( | dbAnyCursor * | cursor, | |
| dbQuery & | query | |||
| ) |
Prepare query.
This method can be used for explicit compilation of query and it's validation
| cursor | result set | |
| query | query expression |
true if query is successfully compiled, false othgerwise | dbDatabase::dbErrorHandler setErrorHandler | ( | dbDatabase::dbErrorHandler | newHandler, | |
| void * | errorHandlerContext = NULL | |||
| ) |
Set error handler.
Handler should be no-return function which perform stack unwind.
| newHandler | new error handler |
| void handleError | ( | dbErrorClass | error, | |
| char const * | msg = NULL, |
|||
| int | arg = 0 | |||
| ) | [virtual] |
Error handler.
It can be redifined by application to implement application specific error handling.
| error | class of the error | |
| msg | error message | |
| arg | optional argument |
Reimplemented in dbSubSql.
| void insertRecord | ( | dbTableDescriptor * | table, | |
| dbAnyReference * | ref, | |||
| void const * | record | |||
| ) |
Insert record in the database.
| table | table descriptor | |
| ref | [out] pointer to the references where ID of created object will be stored | |
| record | pointer to the transient object to be inserted in the table |
| bool isOpen | ( | ) | const [inline] |
Check if database is opened.
| bool isCommitted | ( | ) |
Check if current transaction is committed.
Used mostly for debugging purposes.
| bool isAttached | ( | ) |
Check if thread was attached to the database.
Used mostly for debugging purposes.
| bool isUpdateTransaction | ( | ) |
Check if current transaction is updating database.
| int getVersion | ( | ) |
Get database version.
| void setFileSizeLimit | ( | size_t | limit | ) | [inline] |
Specify database file size limit.
Attempt to exeed this limit cause database error.
| limit | maximal file size in bytes |
| dbReference<T> insert | ( | T const & | record | ) | [inline] |
Insert record in the database.
| record | transient object to be insrted in the database |
| dbTableDescriptor * lookupTable | ( | dbTableDescriptor * | desc | ) |
Find cloned table desciptor assigned to this database.
| des | static unassigned table descriptor |
| void getMemoryStatistic | ( | dbMemoryStatistic & | stat | ) |
Get information about state of database memory.
| stat | placeholder for memory statistic |
| void setFixedSizeAllocator | ( | size_t | minSize, | |
| size_t | maxSize, | |||
| size_t | quantum, | |||
| size_t | bufSize | |||
| ) | [inline] |
Initialize fixed size allocator.
| minSize | minial object size allocated by this allocator | |
| maxSize | maximal object size allocated by this allocator | |
| quantum | difference in size between fixed size allocator chains | |
| bufSize | maximal number of free elements hold by this allocator |
| dbTableDescriptor * loadMetaTable | ( | ) | [protected] |
Loads all class descriptors.
This method should be used SubSQL and any other apllication which is should work with ANY database file.
| void cleanup | ( | dbInitializationMutex::initializationStatus | status, | |
| int | step | |||
| ) | [protected] |
| void delayedCommit | ( | ) | [protected] |
| void backupScheduler | ( | ) | [protected] |
| static void thread_proc delayedCommitProc | ( | void * | arg | ) | [inline, static, protected] |
| static void thread_proc backupSchedulerProc | ( | void * | arg | ) | [inline, static, protected] |
| bool isReplicated | ( | ) | [protected, virtual] |
| void commit | ( | dbDatabaseThreadContext * | ctx | ) | [protected] |
Commit transaction.
| ctx | thread context |
| void restoreTablesConsistency | ( | ) | [protected] |
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.
| bool isValidOid | ( | oid_t | oid | ) | [inline, protected] |
Check if OID corresponds to the valid object.
| oid | inspected OID |
Reimplemented in dbSubSql.
Get table row.
| oid | object indentifier |
Prepare for row insertion or update.
If record with such OID not exists or it is first time when it was changed during this transaction or size of recrod is changed, than new record is alocated in the database. Otherwisepointer to existed recordis returned.
| oid | object indetifier | |
| newSize | size of new object |
Prepare for object update ithout changing its size.
| oid | object indetifier |
Get record by OID.
| oid | object identifier |
Prepare for update of internal object.
| oid | internal object identifier |
| bool isPrefixSearch | ( | dbAnyCursor * | cursor, | |
| dbExprNode * | expr, | |||
| dbExprNode * | andExpr, | |||
| dbFieldDescriptor *& | indexedField | |||
| ) | [protected] |
Check whether query is prefix search: "'key' like field+'%'".
| cursor | result set | |
| expr | evaluated expression | |
| andExpr | if not null, then it is used as filter to all records selected by index search | |
| indexedFile | [out] used to return information about which field was used to perfrom index search and so order in which selected records are sorted. If this order is the same as requested by "order by" clause, then no extra sorting is needed. |
| bool isIndexApplicable | ( | dbAnyCursor * | cursor, | |
| dbExprNode * | expr, | |||
| dbExprNode * | andExpr, | |||
| dbFieldDescriptor *& | indexedField | |||
| ) | [protected] |
Check whether search can be performed using indices.
| cursor | result set | |
| expr | evaluated expression | |
| andExpr | if not null, then it is used as filter to all records selected by index search | |
| indexedFile | [out] used to return information about which field was used to perfrom index search and so order in which selected records are sorted. If this order is the same as requested by "order by" clause, then no extra sorting is needed. |
| bool isIndexApplicable | ( | dbAnyCursor * | cursor, | |
| dbExprNode * | expr, | |||
| dbExprNode * | andExpr | |||
| ) | [protected] |
Check whether expression can be evaluated unsing index.
If index is applicable, than index search is performed and result is stored in the cursor.
| cursor | result set | |
| expr | evaluated expression | |
| andExpr | if not null, then it is used as filter to all records selected by index search |
| bool followInverseReference | ( | dbExprNode * | expr, | |
| dbExprNode * | andExpr, | |||
| dbAnyCursor * | cursor, | |||
| oid_t | iref | |||
| ) | [protected] |
If query predicate contains operands from other tables (accessed by references) and inverse references exists, then FastDB performs indexed search in referenced table and then go back using inverse referenced to query table.
followInverseReference method performs this backward traversal of inverse references.
| expr | evaluated expression | |
| andExpr | if not null, then it is used as filter to all records selected by index search | |
| cursor | cursor to collect selected records | |
| iref | OID of the selected records in referenced table |
| bool existsInverseReference | ( | dbExprNode * | expr, | |
| int | nExistsClauses | |||
| ) | [protected] |
Check if there is inverse reference in the table rerefrenced from search predicate.
| expr | evaluated expression | |
| nExistsClause | number of exists clauses in search wrapping this expression |
| void _fastcall execute | ( | dbExprNode * | expr, | |
| dbInheritedAttribute & | iattr, | |||
| dbSynthesizedAttribute & | sattr | |||
| ) | [static, protected] |
Execute expression.
This method is most frequently recursivly called during evaluation of search predicate.
| expr | expression to be executed | |
| iattr | inherited attributes - attributes passed top-down (information like cursor, current record, ...) | |
| sattr | synthesized attribute - sttributes passed down-top (value of expression) |
| bool evaluate | ( | dbExprNode * | expr, | |
| oid_t | oid, | |||
| dbTable * | table, | |||
| dbAnyCursor * | cursor | |||
| ) | [protected] |
Evaluate epression.
This method initialie initiainherited attributes and invoke execute method
| expr | expression to be evaluated | |
| oid | OID of the inspected record | |
| seaqched | table | |
| cursor | result set |
| void select | ( | dbAnyCursor * | cursor | ) | [protected] |
Select all records from the table.
| cursor | result set |
| void select | ( | dbAnyCursor * | cursor, | |
| dbQuery & | query | |||
| ) | [protected] |
Execute select query.
| cursor | result set | |
| query | query expression |
| void traverse | ( | dbAnyCursor * | cursor, | |
| dbQuery & | query | |||
| ) | [protected] |
Perform table traverse: execute queries with "start from (follow by)" clause.
| cursor | result set | |
| query | query expression |
| void update | ( | oid_t | oid, | |
| dbTableDescriptor * | table, | |||
| void const * | record | |||
| ) | [protected] |
Update record.
| oid | record identifier | |
| table | descriptor of the table to which record belongs | |
| record | updated image of the record |
| void remove | ( | dbTableDescriptor * | table, | |
| oid_t | oid | |||
| ) | [protected] |
Remove record from the database.
| table | descriptor of the table to which record belongs | |
| oid | record identifier |
Allocate object in the database e.
| size | size of alocated object | |
| oid | if oid is not 0, then allocated region position is stored in correcpondent cell of object index (needed for allocation of bitmap pages) |
| void deallocate | ( | offs_t | pos, | |
| size_t | size | |||
| ) | [protected] |
Deallocate region.
| pos | start position of region | |
| size | of region |
| void extend | ( | offs_t | size | ) | [inline, protected] |
Checks whther allocated size is greater than size of databae file and recreate memory mapping object with larger size n the last case.
| size | allocated size |
| void cloneBitmap | ( | offs_t | pos, | |
| size_t | size | |||
| ) | [protected] |
Clone memory allocation bitmap for region [pos, pos+size).
| pos | start of region | |
| size | size of region |
| oid_t allocateId | ( | int | n = 1 |
) | [protected] |
Allocate object identifier(s).
| number | of allocated object indentifiers |
| void freeId | ( | oid_t | oid, | |
| int | n = 1 | |||
| ) | [protected] |
Free object identifier(s).
| oid | deallocated object identifer (or first of n deallocated subsequent identifiers if n greater than 1) | |
| number | of allocated object indentifiers |
| void updateCursors | ( | oid_t | oid, | |
| bool | removed = false | |||
| ) | [protected] |
Update record in in all active cursors if it this record is checnged in the database.
| oid | object indentifier of checnged record | |
| removed | true if record was removed |
| void recovery | ( | ) | [protected] |
| bool checkVersion | ( | ) | [protected] |
Check if program works with correct version of memory mapped object (if memory mapped object is reallocated by some client, its version number is incremented, so all other client will be able to notice it and also reallocate their memory mapping objects.
| oid_t allocateObject | ( | dbInternalObject | marker | ) | [inline, protected] |
Allocate internal object.
| market | internal object tag |
Allocate record.
| tableId | object identifier of the table | |
| size | size of the created record as table descriptor in the database |
Allocate record with specified OID.
| tableId | object identifier of the table | |
| oid | record OID | |
| size | size of the created record as table descriptor in the database |
Delete row from the table.
| tableId | OID of record with table descriptor | |
| oid | identifier of deleted record |
| void freeObject | ( | oid_t | oid | ) | [protected] |
Free internal object.
| static void deleteCompiledQuery | ( | dbExprNode * | tree | ) | [static, protected] |
Cleanup compiled query.
| bool beginTransaction | ( | dbLockType | lockType | ) | [protected] |
Start database transaction.
| modify | if it is update or read-only rtansaction |
| void endTransaction | ( | ) | [inline, protected] |
End transaction.
| void endTransaction | ( | dbDatabaseThreadContext * | ctx | ) | [protected] |
End transaction with specified thread context.
| ctx | thread context |
| void waitTransactionAcknowledgement | ( | ) | [protected, virtual] |
| void initializeMetaTable | ( | ) | [protected] |
Initialize database metatable (table containning information about all other tables included metatable itself).
This method is invoked during database initialzation.
| bool loadScheme | ( | bool | alter | ) | [protected] |
Load database scheme.
This method loads table decriptors from database, compare them with application classes, do necessary reformatting and save update andnew table decriptor in database
| alter | if true then schema can be altered, otherwise there are some other active clients working with this database so schema can not be altered |
| bool completeDescriptorsInitialization | ( | ) | [protected] |
This method is invoked by SubSQL to complete table descriptors initialization after loading of all table descriptoes from thr database.
| void reformatTable | ( | oid_t | tableId, | |
| dbTableDescriptor * | desc | |||
| ) | [protected] |
Reformat table according to new format.
| tableId | OID of changed tables | |
| nw | table descriptor |
| bool addIndices | ( | bool | alter, | |
| dbTableDescriptor * | desc | |||
| ) | [protected] |
Add new indices to the table.
| alter | if true than indices can be added, otherwise there are some other active clients and adding new indices about which they will not know can lead to inconsistncy | |
| desc | new table descriptor |
| oid_t addNewTable | ( | dbTableDescriptor * | desc | ) | [protected] |
Add new table to the database.
| desc | - descriptor of new table |
| void updateTableDescriptor | ( | dbTableDescriptor * | desc, | |
| oid_t | tableId | |||
| ) | [protected] |
Update database table descriptor.
| desc | application table descriptor | |
| tableId | OID of recrods with database table descriptor |
| void insertInverseReference | ( | dbFieldDescriptor * | fd, | |
| oid_t | reverseId, | |||
| oid_t | targetId | |||
| ) | [protected] |
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).
| fd | descriptor of updated field (inverse reference should exist for this field) | |
| reverseId | OID of updated record | |
| targetId | OID of record referenced by this field |
| void removeInverseReferences | ( | dbTableDescriptor * | desc, | |
| oid_t | oid | |||
| ) | [protected] |
Remove inverse references to the removed record.
| desc | descriptor of table from which record is removed | |
| oid | OID of removed record |
| void removeInverseReference | ( | dbFieldDescriptor * | fd, | |
| oid_t | reverseId, | |||
| oid_t | targetId | |||
| ) | [protected] |
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.
| fd | descriptor of updated field (inverse reference should exist for this field) | |
| reverseId | OID of updated record | |
| targetId | OID of record referenced by this field |
| void deleteTable | ( | dbTableDescriptor * | desc | ) | [protected] |
Delete table from the database.
| desc | table descriptor |
| void dropTable | ( | dbTableDescriptor * | desc | ) | [protected] |
Delete all table records.
| desc | table descriptor |
| void createIndex | ( | dbFieldDescriptor * | fd | ) | [protected] |
Create T-Tree index for the field.
| fd | field descriptor |
| void createHashTable | ( | dbFieldDescriptor * | fd | ) | [protected] |
Create hash table for the field.
| fd | field descriptor |
| void dropIndex | ( | dbFieldDescriptor * | fd | ) | [protected] |
Drop T-Tree index for the field.
| fd | field descriptor |
| void dropHashTable | ( | dbFieldDescriptor * | fd | ) | [protected] |
Drop hash table for the field.
| fd | field descriptor |
| void linkTable | ( | dbTableDescriptor * | table, | |
| oid_t | tableId | |||
| ) | [protected] |
Link table to the database table list.
| table | table descriptor | |
| tableId | OID of record containing database table descriptor |
| void unlinkTable | ( | dbTableDescriptor * | table | ) | [protected] |
Unlink table from the database tables list.
| table | table descriptor |
| bool wasReserved | ( | offs_t | pos, | |
| size_t | size | |||
| ) | [inline, protected] |
Check if location is reserved.
| pos | start position of the location | |
| size | location size |
| void reserveLocation | ( | dbLocation & | location, | |
| offs_t | pos, | |||
| size_t | size | |||
| ) | [inline, protected] |
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).
| location | [out] local structure describing location. | |
| pos | start position of the location | |
| size | location size |
| void commitLocation | ( | ) | [inline, protected] |
Remove location from list of reserved locations.
It is done after location is marked as occupied in bitmap.
| dbTableDescriptor * findTable | ( | char const * | name | ) | [protected] |
Find table using symbol name.
| name | symbol table entry (returned by dbSymbolTable::add method) |
NULL if not found | dbTableDescriptor * findTableByName | ( | char const * | name | ) | [protected] |
Find table by name.
This method get symbol for specified name and call findTable method.
| name | name of table |
NULL if not found | dbTableDescriptor* getTables | ( | ) | [inline, protected] |
Get list of tables attached to the database.
| void setDirty | ( | ) | [protected] |
Mark database as been modified.
| bool isFree | ( | offs_t | pos, | |
| int | objBitSize | |||
| ) | [protected] |
Check if given location is free.
| pos | object offset | |
| objBitSize | object size i quantums |
| void markAsAllocated | ( | offs_t | pos, | |
| int | objBitSize | |||
| ) | [protected] |
Set in memory allocation bitmap bits corresponding to the object.
| pos | object offset | |
| objBitSize | object size i quantums |
friend class dbSelection [friend] |
friend class dbAnyCursor [friend] |
friend class dbHashTable [friend] |
friend class dbQuery [friend] |
friend class dbTtree [friend] |
friend class dbTtreeNode [friend] |
friend class dbRtree [friend] |
friend class dbRtreePage [friend] |
friend class dbParallelQueryContext [friend] |
friend class dbServer [friend] |
friend class dbColumnBinding [friend] |
friend class dbUserFunctionArgument [friend] |
friend class dbAnyContainer [friend] |
friend class dbFile [friend] |
friend class dbCLI [friend] |
friend class GiSTdb [friend] |
friend class dbHArray [friend] |
char const *const errorMessage [static] |
Initial value:
{
"No error",
"Query syntax error",
"Arithmetic exception",
"Index out of range",
"Database open error",
"File access error",
"Out of memory",
"Deadlock",
"Null reference",
"Lock revoked",
"File limit exeeded",
"Inconsistent inverse reference",
"Attempt to modify read-only database"
}
| size_t initSize |
| size_t extensionQuantum |
| size_t initIndexSize |
size_t internalObjectSize [static, protected] |
Initial value:
{
0,
dbPageSize,
sizeof(dbTtree),
sizeof(dbTtreeNode),
sizeof(dbHashTable),
sizeof(dbHashTableItem),
sizeof(dbRtree),
sizeof(dbRtreePage)
}
dbThreadPool threadPool [protected] |
FixedSizeAllocator fixedSizeAllocator [protected] |
dbThreadContext<dbDatabaseThreadContext> threadContext [protected] |
unsigned parThreads [protected] |
bool modified [protected] |
size_t currRBitmapPage [protected] |
size_t currRBitmapOffs [protected] |
size_t currPBitmapPage [protected] |
size_t currPBitmapOffs [protected] |
dbLocation* reservedChain [protected] |
char* databaseName [protected] |
int databaseNameLen [protected] |
char* fileName [protected] |
int version [protected] |
size_t committedIndexSize [protected] |
size_t currIndexSize [protected] |
oid_t updatedRecordId [protected] |
unsigned waitLockTimeout [protected] |
size_t fileSizeLimit [protected] |
bool uncommittedChanges [protected] |
dbHashFunction hashFunction [protected] |
dbSharedObject<dbMonitor> shm [protected] |
dbGlobalCriticalSection cs [protected] |
dbGlobalCriticalSection mutatorCS [protected] |
dbInitializationMutex initMutex [protected] |
dbSemaphore writeSem [protected] |
dbSemaphore readSem [protected] |
dbSemaphore upgradeSem [protected] |
dbEvent backupCompletedEvent [protected] |
dbTableDescriptor* tables [protected] |
int* bitmapPageAvailableSpace [protected] |
offs_t allocatedSize [protected] |
offs_t deallocatedSize [protected] |
time_t commitDelay [protected] |
time_t commitTimeout [protected] |
time_t commitTimerStarted [protected] |
dbMutex delayedCommitStartTimerMutex [protected] |
dbMutex delayedCommitStopTimerMutex [protected] |
dbLocalEvent delayedCommitStartTimerEvent [protected] |
dbEvent delayedCommitStopTimerEvent [protected] |
dbLocalEvent commitThreadSyncEvent [protected] |
bool delayedCommitEventsOpened [protected] |
dbMutex backupMutex [protected] |
dbLocalEvent backupInitEvent [protected] |
char* backupFileName [protected] |
time_t backupPeriod [protected] |
bool stopDelayedCommitThread [protected] |
dbThread backupThread [protected] |
dbThread commitThread [protected] |
int accessCount [protected] |
dbL2List threadContextList [protected] |
dbMutex threadContextListMutex [protected] |
dbErrorHandler errorHandler [protected] |
void* errorHandlerContext [protected] |
int schemeVersion [protected] |
dbVisitedObject* visitedChain [protected] |
bool confirmDeleteColumns [protected] |
int maxClientId [protected] |
int selfId [protected] |
unsigned parallelScanThreshold [protected] |