dbDatabase Class Reference

#include <database.h>

Inheritance diagram for dbDatabase:

dbSubSql

List of all members.


Detailed Description

Database class.

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 &params)
 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.
dbTableDescriptorlookupTable (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

dbTableDescriptorloadMetaTable ()
 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.
dbRecordgetRow (oid_t oid)
 Get table row.
dbRecordputRow (oid_t oid, size_t newSize)
 Prepare for row insertion or update.
dbRecordputRow (oid_t oid)
 Prepare for object update ithout changing its size.
byteget (oid_t oid)
 Get record by OID.
byteput (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.
dbTableDescriptorfindTable (char const *name)
 Find table using symbol name.
dbTableDescriptorfindTableByName (char const *name)
 Find table by name.
dbTableDescriptorgetTables ()
 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
bytebaseAddr
dbHeaderheader
offs_tcurrIndex
offs_tindex [2]
unsigned parThreads
bool modified
size_t currRBitmapPage
size_t currRBitmapOffs
size_t currPBitmapPage
size_t currPBitmapOffs
dbLocationreservedChain
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< dbMonitorshm
dbGlobalCriticalSection cs
dbGlobalCriticalSection mutatorCS
dbInitializationMutex initMutex
dbSemaphore writeSem
dbSemaphore readSem
dbSemaphore upgradeSem
dbEvent backupCompletedEvent
dbMonitormonitor
dbTableDescriptortables
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
dbVisitedObjectvisitedChain
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...

Member Typedef Documentation

typedef void(* dbErrorHandler)(int error, char const *msg, int msgarg, void *context)


Member Enumeration Documentation

Enumerator:
dbReadOnly 
dbAllAccess 
dbConcurrentRead 
dbConcurrentUpdate 

Enumerator:
COMMIT 
DESTROY_CONTEXT 

enum dbLockType

Enumerator:
dbSharedLock 
dbExclusiveLock 
dbCommitLock 

Enumerator:
NoError 
QueryError 
ArithmeticError 
IndexOutOfRangeError 
DatabaseOpenError 
FileError 
OutOfMemoryError 
Deadlock 
NullReferenceError 
LockRevoked 
FileLimitExeeded 
InconsistentInverseReference 
DatabaseReadOnly 

Enumerator:
dbNotUsePthreads 
dbUsePthreads 

Enumerator:
dbReplicated 
dbStandalone 


Constructor & Destructor Documentation

dbDatabase ( dbAccessType  type = dbAllAccess,
size_t  dbInitSize = dbDefaultInitDatabaseSize,
size_t  dbExtensionQuantum = dbDefaultExtensionQuantum,
size_t  dbInitIndexSize = dbDefaultInitIndexSize,
int  nThreads = 1 
)

Database constructor.

Parameters:
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
See also:
setConcurrency(unsigned nThreads)

~dbDatabase (  )  [virtual]

Database detructor.


Member Function Documentation

bool open ( char const *  databaseName,
char const *  fileName = NULL,
time_t  waitLockTimeoutMsec = INFINITE,
time_t  commitDelaySec = 0 
)

Open database.

Parameters:
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
Returns:
true if database was successfully opened

bool open ( OpenParameters params  ) 

Open database with parameters defined in OpenParameters structure.

Parameters:
params parameters for openning database
Returns:
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.

Parameters:
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

Parameters:
ctx transaction context which will be associated with the current thread

void detach ( int  flags = COMMIT|DESTROY_CONTEXT  ) 

Detach thread from the database.

Parameters:
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.

Parameters:
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.
Returns:
whether backup was succeseful or not

bool backup ( dbFile file,
bool  compactify 
)

Perform backup to the specified file.

Parameters:
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.
Returns:
whether backup was succeseful or not

void assign ( dbTableDescriptor desc  )  [inline]

Assign table to the database.

Parameters:
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.

Parameters:
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.

Returns:
delta between size of allocated and deallocated data

long getDatabaseSize (  )  [inline]

Get size of the database file.

Returns:
database file size

int getNumberOfReaders (  )  [inline]

Get number of threads accessing database in shared mode (readonly).

Returns:
number of granted shared locks

int getNumberOfWriters (  )  [inline]

Get number of threads accessing database in exclusiveh mode (for update).

Returns:
number of granted exclusive locks (can be either 0 either 1)

int getNumberOfBlockedReaders (  )  [inline]

Get number of threads blocked while starting read-only transaction.

Returns:
number of threads which shared lock request was blocked

int getNumberOfBlockedWriters (  )  [inline]

Get number of threads blocked while starting update transaction.

Returns:
number of threads which exclusive lock request was blocked

int getNumberOfUsers (  )  [inline]

Get number of processes attached to the database.

Returns:
number of processes openned 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).

Parameters:
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

Parameters:
cursor result set
query query expression
Returns:
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.

Parameters:
newHandler new error handler
Returns:
previous 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.

Parameters:
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.

Parameters:
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.

Parameters:
limit maximal file size in bytes

dbReference<T> insert ( T const &  record  )  [inline]

Insert record in the database.

Parameters:
record transient object to be insrted in the database
Returns:
reference to the created object

dbTableDescriptor * lookupTable ( dbTableDescriptor desc  ) 

Find cloned table desciptor assigned to this database.

Parameters:
des static unassigned table descriptor
Returns:
clone of this table descriptor assigned to this databae or NULL if not found.

void getMemoryStatistic ( dbMemoryStatistic stat  ) 

Get information about state of database memory.

Parameters:
stat placeholder for memory statistic

void setFixedSizeAllocator ( size_t  minSize,
size_t  maxSize,
size_t  quantum,
size_t  bufSize 
) [inline]

Initialize fixed size allocator.

Parameters:
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.

Returns:
metatable descriptor

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.

Parameters:
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.

Parameters:
oid inspected OID
Returns:
whether OID is valid or not

Reimplemented in dbSubSql.

dbRecord* getRow ( oid_t  oid  )  [inline, protected]

Get table row.

Parameters:
oid object indentifier
Returns:
object with this oid

dbRecord * putRow ( oid_t  oid,
size_t  newSize 
) [protected]

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.

Parameters:
oid object indetifier
newSize size of new object
Returns:
pointer inside database where object should should be stored

dbRecord* putRow ( oid_t  oid  )  [inline, protected]

Prepare for object update ithout changing its size.

Parameters:
oid object indetifier
Returns:
pointer inside database where object should should be stored

byte* get ( oid_t  oid  )  [inline, protected]

Get record by OID.

Parameters:
oid object identifier
Returns:
pointer to the record inside database

byte* put ( oid_t  oid  )  [inline, protected]

Prepare for update of internal object.

Parameters:
oid internal object identifier
Returns:
pointer to the record inside database

bool isPrefixSearch ( dbAnyCursor cursor,
dbExprNode expr,
dbExprNode andExpr,
dbFieldDescriptor *&  indexedField 
) [protected]

Check whether query is prefix search: "'key' like field+'%'".

Parameters:
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.
Returns:
true if search was performed using indeices, false if index is not applicable and sequential search is required

bool isIndexApplicable ( dbAnyCursor cursor,
dbExprNode expr,
dbExprNode andExpr,
dbFieldDescriptor *&  indexedField 
) [protected]

Check whether search can be performed using indices.

Parameters:
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.
Returns:
true if search was performed using indeices, false if index is not applicable and sequential search is required

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.

Parameters:
cursor result set
expr evaluated expression
andExpr if not null, then it is used as filter to all records selected by index search
Returns:
true if expression was evaluated using index, false if index is not applicable and sequential search is required

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.

Parameters:
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.

Parameters:
expr evaluated expression
nExistsClause number of exists clauses in search wrapping this expression
Returns:
true if inverse reference(s) exists and it is possible to perform backward traversal

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.

Parameters:
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

Parameters:
expr expression to be evaluated
oid OID of the inspected record
seaqched table
cursor result set
Returns:
true if this record match search condition, false otherwise

void select ( dbAnyCursor cursor  )  [protected]

Select all records from the table.

Parameters:
cursor result set

void select ( dbAnyCursor cursor,
dbQuery query 
) [protected]

Execute select query.

Parameters:
cursor result set
query query expression

void traverse ( dbAnyCursor cursor,
dbQuery query 
) [protected]

Perform table traverse: execute queries with "start from (follow by)" clause.

Parameters:
cursor result set
query query expression

void update ( oid_t  oid,
dbTableDescriptor table,
void const *  record 
) [protected]

Update record.

Parameters:
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.

Parameters:
table descriptor of the table to which record belongs
oid record identifier

offs_t allocate ( size_t  size,
oid_t  oid = 0 
) [protected]

Allocate object in the database e.

Parameters:
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)
Returns:
position of allcoated region

void deallocate ( offs_t  pos,
size_t  size 
) [protected]

Deallocate region.

Parameters:
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.

Parameters:
size allocated size

void cloneBitmap ( offs_t  pos,
size_t  size 
) [protected]

Clone memory allocation bitmap for region [pos, pos+size).

Parameters:
pos start of region
size size of region

oid_t allocateId ( int  n = 1  )  [protected]

Allocate object identifier(s).

Parameters:
number of allocated object indentifiers
Returns:
object idenitifer (in case if n greater than 1, all n subsequent OIDs are allocated and first one is returned

void freeId ( oid_t  oid,
int  n = 1 
) [protected]

Free object identifier(s).

Parameters:
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.

Parameters:
oid object indentifier of checnged record
removed true if record was removed

void recovery (  )  [protected]

Perform database recovery after fault.

Reimplemented in dbSubSql.

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.

Returns:
true if memory mapping object was successfully reallocated or no reallocation is needed at all

oid_t allocateObject ( dbInternalObject  marker  )  [inline, protected]

Allocate internal object.

Parameters:
market internal object tag
Returns:
oid of allocated object

oid_t allocateRow ( oid_t  tableId,
size_t  size 
) [inline, protected]

Allocate record.

Parameters:
tableId object identifier of the table
size size of the created record as table descriptor in the database

void allocateRow ( oid_t  tableId,
oid_t  oid,
size_t  size 
) [protected]

Allocate record with specified OID.

Parameters:
tableId object identifier of the table
oid record OID
size size of the created record as table descriptor in the database

void freeRow ( oid_t  tableId,
oid_t  oid 
) [protected]

Delete row from the table.

Parameters:
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.

Parameters:
modify if it is update or read-only rtansaction
Returns:
true if version of memory mapping object is not obsolete and reallocation is not possible

void endTransaction (  )  [inline, protected]

End transaction.

void endTransaction ( dbDatabaseThreadContext ctx  )  [protected]

End transaction with specified thread context.

Parameters:
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

Parameters:
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.

Returns:
true if intertable relation consuistency is rpeservedm false otherwise

void reformatTable ( oid_t  tableId,
dbTableDescriptor desc 
) [protected]

Reformat table according to new format.

Parameters:
tableId OID of changed tables
nw table descriptor

bool addIndices ( bool  alter,
dbTableDescriptor desc 
) [protected]

Add new indices to the table.

Parameters:
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
Returns:
true if indices were succesfully added

oid_t addNewTable ( dbTableDescriptor desc  )  [protected]

Add new table to the database.

Parameters:
desc - descriptor of new table
Returns:
oid of created table descriptor record

void updateTableDescriptor ( dbTableDescriptor desc,
oid_t  tableId 
) [protected]

Update database table descriptor.

Parameters:
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).

Parameters:
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.

Parameters:
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.

Parameters:
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.

Parameters:
desc table descriptor

void dropTable ( dbTableDescriptor desc  )  [protected]

Delete all table records.

Parameters:
desc table descriptor

void createIndex ( dbFieldDescriptor fd  )  [protected]

Create T-Tree index for the field.

Parameters:
fd field descriptor

void createHashTable ( dbFieldDescriptor fd  )  [protected]

Create hash table for the field.

Parameters:
fd field descriptor

void dropIndex ( dbFieldDescriptor fd  )  [protected]

Drop T-Tree index for the field.

Parameters:
fd field descriptor

void dropHashTable ( dbFieldDescriptor fd  )  [protected]

Drop hash table for the field.

Parameters:
fd field descriptor

void linkTable ( dbTableDescriptor table,
oid_t  tableId 
) [protected]

Link table to the database table list.

Parameters:
table table descriptor
tableId OID of record containing database table descriptor

void unlinkTable ( dbTableDescriptor table  )  [protected]

Unlink table from the database tables list.

Parameters:
table table descriptor

bool wasReserved ( offs_t  pos,
size_t  size 
) [inline, protected]

Check if location is reserved.

Parameters:
pos start position of the location
size location size
Returns:
true id location was reserved

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).

Parameters:
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.

Parameters:
name symbol table entry (returned by dbSymbolTable::add method)
Returns:
table descriptor or 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.

Parameters:
name name of table
Returns:
table descriptor or NULL if not found

dbTableDescriptor* getTables (  )  [inline, protected]

Get list of tables attached to the database.

Returns:
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.

Parameters:
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.

Parameters:
pos object offset
objBitSize object size i quantums


Friends And Related Function Documentation

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]


Member Data Documentation

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 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]

byte* baseAddr [protected]

dbHeader* header [protected]

offs_t* currIndex [protected]

offs_t* index[2] [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]

dbFile file [protected]

dbSemaphore writeSem [protected]

dbSemaphore readSem [protected]

dbSemaphore upgradeSem [protected]

dbMonitor* monitor [protected]

dbTableDescriptor* tables [protected]

int* bitmapPageAvailableSpace [protected]

bool opened [protected]

Reimplemented in dbSubSql.

offs_t allocatedSize [protected]

offs_t deallocatedSize [protected]

time_t commitDelay [protected]

time_t commitTimeout [protected]

time_t commitTimerStarted [protected]

bool delayedCommitEventsOpened [protected]

dbMutex backupMutex [protected]

char* backupFileName [protected]

time_t backupPeriod [protected]

bool stopDelayedCommitThread [protected]

dbThread backupThread [protected]

dbThread commitThread [protected]

int accessCount [protected]

void* errorHandlerContext [protected]

int schemeVersion [protected]

bool confirmDeleteColumns [protected]

int maxClientId [protected]

int selfId [protected]

unsigned parallelScanThreshold [protected]


Online Library Docs

sipXecs home page

Version 4.2.1-018930 2010-07-31T01:13:23 build16 abuild