Click or drag to resize

SessionBase Class

Transaction control, database creation and special persistent object api. Each session can use 4,294,967,295 Databases. Each Database may have up to 65,535 Pages and a page can be up to 2 GB in size (.Net restriction of a byte array). The maximum data size a single session can manage is: 4,294,967,295 * 65,535 * 2147483648 = 604453686294542391705600 bytes or about half a Yottabyte http://en.wikipedia.org/wiki/Yottabyte
Inheritance Hierarchy

Namespace:  VelocityDb.Session
Assembly:  VelocityDb (in VelocityDb.dll) Version: 11.1.0.0 (11.1)
Syntax
public abstract class SessionBase : IEnumerable<Database>, 
	IEnumerable, IDisposable, IEnlistmentNotification

The SessionBase type exposes the following members.

Properties
  NameDescription
Public propertyAddToIndexInSeperateThread
Allow adding objects to indices to be done in a worker thread instead of in main thread.
Public propertyAssumeLocalHost
SessionNoServer ignores DatabaseLocation host value, it assumes localhost, ServerSessionClient does not assume local host, it follows the DatabaseLocation HostName value.
Public propertyStatic memberBaseDatabasePath
If specified boot path (system database path) in session constructor isn't an absolute path then this base path is prefixed to make an absolute path.
Public propertyStatic memberBTreeAddFastTransientBatchSize
Default batch size for BTree AddFast api, initially set to 100
Public propertyStatic memberClearAllCachedObjectsWhenDetectingUpdatedDatabase
By default we clear all cached object when at the beginning of a transaction we detect an updated Database within our cached databases. Same logic is applied when calling ForceDatabaseCacheValidation. We do so because most of the time an object in one database have (strong) references to objects in other databases. If Database A is NOT updated but database B is and an object in database A is cached with a strong reference to an object in database B then our cached object in database A may contain a stale/incorrect reference to object in database B. This is why we, by default, invalidate all cached objects when we detect a modified database within our cached databases. However, if you design your database schema without strong references between databases then you do not need to invalidate cached objects for other databases, only the ones that have changed. By consistently using WeakIOptimizedPersistableReferenceT, BTreeSetKey and BTreeMapKey, Value, you can keep references weak between databases. In such cases, set this property to false.
Public propertyClientCache
Gets the client page cache object
Public propertyDatabaseLocations
Gets the DatabaseLocationsDatabaseLocations for the session.
Public propertyDatabases
Gets a list of the currently opened databases
Public propertyStatic memberDefaultCompressPages
By default false, set to true if you want to change the default for newly created DatabaseLocation.
Public propertyStatic memberDefaultNumberOfObjectsPerPage
Default number of objects per page is 9999
Public propertyStatic memberDefaultStringComparer
Set the StringComparer to use when no application provided comparator is provided. By default we will then use StringComparer.Ordinal.
Public propertyDeletedOids
Collected Oid for unpersisted objects within an update transaction. Ids are only collected if NotifyBeforeCommit is non null.
Public propertyStatic memberDoWindowsAuthentication
By default do not use windows authentication when talking to VelocitydbServer's on other hosts.
Public propertyStatic memberEmbedISerializableLists
Public propertyEnableAutoPageFlush
Pages may be flushed when memory available is low unless you set tis property to false. You would want it to be enabled unless you are trying to share a non SessionNoServerShared session by working on different databases in multiple threads. As in Wikipedia sample application.
Public propertyEnableSyncByTrackingChanges
Enable database and page change tracking. Turn off within an update transaction so that prior change set can be deleted.
Public propertyStatic memberFileBytesChunkSize
When transferring complete files from a server, we send the file bytes in chunks of this size.
Public propertyFileShareReader
FileShare for reader is ReadWrite with optimistic locking; otherwise Read
Public propertyFileShareUpdater
FileShare for updater is Read with optimistic locking; otherwise None
Public propertyInCommit
Indicates if we are within a transaction commit.
Public propertyInMemoryOnly
Gets information about this session, is it an in-memory only session or a session that persists data
Public propertyInTransaction
Indicates if we are within an active transaction.
Public propertyInUpdateTransaction
Indicates if we are within an active update transaction.
Public propertyIsDisposed
Check if session has been disposed
Public propertyStatic memberLocalHost
Get the host name of your local host (the machine you are using)
Public propertyStatic memberMaxStringLengthToIntern
Get the maximum size a string must have before VelocityDB internals interns, Intern(String), string when read from a Database.
Public propertyStatic memberMaxUpdateTransactionLogHistory
Determines max number of UpdateTransaction objects we maintain in update transaction log in Database 0, initially set to 9990
Public propertyStatic memberMinStringLengthToIntern
Get the minimum size a string must have before VelocityDB internals interns, Intern(String), string when read from a Database.
Public propertyNewDatabases
Get a list of all new databases created within this transaction
Public propertyNewOids
Collected Oid for newly persisted objects within an update transaction. Ids are only collected if NotifyBeforeCommit is non null.
Public propertyNotifyBeforeCommit
Set to an Action of your choice if you want to get notified right before commit of an update transaction.
Public propertyObjectCachingDefaultPolicy
Get/Set default value for Cache
Public propertyOptimisticLocking
Is the active Database and/or Page locking using optimistic locking model or not? See https://en.wikipedia.org/wiki/Optimistic_concurrency_control and https://en.wikipedia.org/wiki/Record_locking
Public propertyStrongReferenceDatabaseCaching
Is current session caching Databases using strong references or just by weak references. Set in session constructor or by calling CrossTransactionCacheAllDatabases(Boolean).
Public propertySystemDirectory
Get the path to the directory of the system Databases (0.odb, 1.odb, 2.odb ...) of this session.
Public propertySystemHostName
Get the host name of the system Databases (0.odb, 1.odb, 2.odb ...) of this session.
Public propertyStatic memberTextEncoding
All text encoding is done with utf8
Public propertyTraceDBActivity
Public propertyTraceIndexUsage
If set to true, each time an index (BTreeSet) is used in a LINQ query expression, we output a line about that to the console output.
Public propertyTransactionNumber
Gets the transaction number of the current session
Public propertyUpdatedOids
Collected Oid for updated objects within an update transaction. Ids are only collected if NotifyBeforeCommit is non null.
Public propertyUseExternalStorageApi
This is specifically for Windows Phone API, set to true when you want to access databases from a memory card.
Public propertyWaitForLockMilliseconds
Get/Set the max time waiting for a lock to clear with pessimistic locking
Public propertyWriteToDiskInSeperateDatabaseThreads
Allow object serialization and page writes to happen in worker threads, one per database, instead of in main session thread. AddToIndexInSeperateThread must also be enabled for this to work.
Top
Methods
  NameDescription
Public methodAbort
Transaction control, abort the current transaction
Public methodAllObjectsT
Gets an object used for enumerating all objects in all Databases
Public methodAnyPageWritten
Find out if any pages have been written for a given database in this update transaction
Public methodBeginRead
Transaction control, begin a read only transaction
Public methodBeginUpdate
Transaction control, begin an update transaction.
Public methodBeginUpdate(Boolean)
Transaction control, begin an update transaction.
Public methodCheckpoint
Public methodClearCache
Clears page cache and closes databases. Avoid using this one for now.
Public methodClearCachedObjects
Clears the cache of cached objects.
Public methodClearCachedObjects(Database)
Clears the cache of cached objects within a Database.
Public methodClearCashedPages
Clear cache of cached pages
Public methodClearPageCache
Clears cached pages from cache including page weak references.
Public methodCloseDatabase
Closes a Database
Public methodCommit
Transaction control, commit the current transaction
Public methodCompact
Reduce size of databases, if possible, by first attempting to relocate pages to free areas towards the beginning of each Database file and then by truncating files where unused space begins. Run Compact() outside the scope of any transaction.
Public methodCompact(Database)
Reduce size of database, if possible, by truncating file where unused space begins
Public methodCompareTo
The defualt compare of two SessionBase is by system (bootup) host name and directory
Public methodContainsDatabase
Check if database file exist in a given DatabaseLocation
Public methodCopyAllDatabasesTo
Copies all databases to a selected directory on the local host.
Public methodCreateDirectory
Creates a directory
Public methodCrossTransactionCache
By default databases are only referenced by a WeakReference across transaction boundaries. This means that such Database may or may not be available as a cached database depending on garbage collection activity and if such database also has a strong reference. This function lets you add a strong reference to a Database so the cached Database may be used if version wasn't changed by a different thread since prior transaction. The strong reference is removed once the Database is reopened.
Public methodCrossTransactionCacheAllDatabases
By default databases are referenced by strong references instead of WeakReference across transaction boundaries. This means that such Database may or may not be available as a cached database depending on garbage collection activity and if such database also has a strong reference. This function lets you add a strong reference to all Databases so the cached Database may be used if version wasn't changed by a different thread since prior transaction. A strong reference is removed for any database that get invalidated due to a transaction abort or if another transaction commits a change to it. Check current session state with StrongReferenceDatabaseCaching
Public methodDatabaseNumberOf
Get the database number associated with a specific type. Your application can store any type of object in any database but if the application exclusively use Persist(IOptimizedPersistable, NullableUInt16) or Persist(Object) then this is the database Id that will be used given a type.
Public methodDatabaseStillExist
Check if Database still exist
Public methodDefaultDatabaseLocation
Gets the default (startup) DatabaseLocation
Public methodDeleteDatabase
Delete a database, actual database file delete happens after a successful transaction commit.
Public methodDeleteFile
Delete a file. For internal use.
Public methodDeleteLocation
Deletes a DatabaseLocation, location must first mot have any Databases in it
Public methodDeleteObject
A way to delete an object without requiring that the object be opened first
Public methodDeletePage
Deletes a page from a database. (part of database Sync beta version - not yet fully designed and tested) Used by SyncWith when syncing databases with another replica of the current databases
Public methodDeployGenerateReaderWriter
Part of code generator, not yet ready for public release
Public methodDeployInternalTypes
For internal use only
Public methodDispose
Closes this session
Public methodFileOpen(Database, FileAccess, String, FileMode, Boolean, Int32, Boolean)
Opens a Databasefile for read/update. Internal use only.
Public methodFileOpen(FileInfo, FileAccess, String, FileShare, FileMode, Int32, Boolean, Boolean)
For internal use.
Public methodFirstFreePage
Gets the page number of the first unallocated page in the specified Database
Public methodFlushPageOf
By calling this you force a persisted (has an Id) object to be written to disk (if updated) and indices (if any) to be updated. Other objects on the same page page will also be written.
Public methodFlushUpdates
Write all updated data. This may free up some memory.
Public methodFlushUpdates(Database)
Write any updated/new pages for a specific Database
Public methodFlushUpdatesServers
Make servers Write all updated data. This may free up some memory on the servers. Only effects sessions using VelocityDbServer(s)
Public methodForceDatabaseCacheValidation
Cached data is set to be validated whenever a new transaction is started. This function is provided as a way to force cache validation within a transaction without requiring a commit followed by a new transaction.
Public methodGetEnumerator
Enumerates all open databases for this session
Public methodGetVersion
Gets the version of Database 0
Public methodGlobalObjWrapperGet
Lookup wrapper object for a non IOptimizedPersistable object
Public methodHighestInUseDatabaseNumber
Figure out what the highest in use database number is and return it.
Public methodHighestInUseLocalDatabaseNumber
Figure out what the highest in use database number is on the local host and return it.
Public methodIdOf
Finds the object id of a persistent object
Public methodIndexT
Gets an index of all objects of a certain type
Public methodIndexT(String)
Gets an index of all objects of a certain type
Public methodIndexT(Database)
Gets an index of all objects of a certain type within a given database (attribute OnePerDatabase must be used). If you have updated objects persisted in a prior transaction that you want part of an index. Call FlushUpdates or call Write/> to add such an object to index before querying using an index./>
Public methodIndexT(String, Database)
Gets an index of all objects of a certain type within a given database (attribute OnePerDatabase must be used)
Public methodInUseNumberOfPages
Gets the number of pages currently in use by a Database
Public methodStatic memberIsSameHost
Determine if two host names represent the same tcp/ip host
Public methodIsWorkerThread
Tell if code is executed by index or page write worker thread
Public methodLoadFields
Loads all field values of an object if they are not already loaded.
Public methodLocateDb
Lookup the DatabaseLocation of a Database with a specified database number.
Public methodNewDatabase
Create a new Database with a given database number
Public methodNewLocation
Creates a new DatabaseLocation or updates existing ones
Public methodObjectsT
Enumerates all the objects of a given type
Public methodOfType
Gets an object used for enumerating all objects in all Databases
Public methodOidOf
Finds the object id of a persistent object
Public methodOidShortOf
Finds the object id of a persistent object
Public methodOpenAllDatabases
Open all databases
Public methodOpenDatabase
Opens a Database
Public methodOpenDatabaseLocations
Open the DatabaseLocations object and store it in the session.
Public methodOpenLocationDatabases
Opens all the databases in a given location
Public methodOpenPage
Opens a page for read, used by DatabaseManager for page browsing
Public methodOpenSchema
Get the session active schema
Public methodStatic memberParseCsvRow
Parses a row in a csv file and returns an iterator of column string values
Public methodPersist(Object)
This is the recommended way of persisting objects, it is simple and efficient. Each type is stored in its own database.
Public methodPersist(IOptimizedPersistable, NullableUInt16)
This is the recommended way of persisting objects, it is simple and efficient. Each type is stored in its own database unless object class overrides PlacementDatabaseNumber and returns something other than DefaultPlacementDatabaseNumber.
Public methodPersist(Placement, IOptimizedPersistable)
Persist an object that is an OptimizedPersistable or a subclass
Public methodPersist(Object, IOptimizedPersistable, Boolean)
Persist an object that may or may not be a subclass of OptimizedPersistable
Public methodPersist(Object, Placement, Boolean)
Persist an object that may or may not be a subclass of OptimizedPersistable
Public methodPersist(Placement, IOptimizedPersistable, Schema, UInt16, Boolean, QueueIOptimizedPersistable)
Persists an object
Public methodPossiblyFlushUpdatedPages
Call this function if you may have updated many pages to possibly free up memory if too much memory is in use.
Public methodRegisterClass
Register a class in the persistent schema. It is a good idea to do this explicitly instead of having it happen the first time an object of an unregistered class is made persistent
Public methodRelocateDatabaseLocationFor
After moving/copying directory containing your Database with id dbId call this before starting a transaction to update host and directory of the associated DatabaseLocation. This function does not move the database files, it only updates the DatabaseLocation.
Public methodRelocateDefaultDatabaseLocation
After moving/copying directory containing your Databases 0.odb, 1.odb ... call this before starting a transaction to update host and directory of the default DatabaseLocation. This function does not move the database files, it only updates the DatabaseLocation.
Public methodReplacePage
Only to be used in VelocityDbExtensions while syncing databases
Public methodReplacePersistedType(String, Type)
Updates the Type assocuiated with a VelocityDbType. This can be used when you want to rename a class or move a class to a different namespace. You will need to have the prior Type loaded as it it is defined in the current Schema for this to work. Once the update has been done, you should no longer need to keep the old Type loaded. Be sure to backup all your data before doing this.
Public methodReplacePersistedType(Type, Type)
Updates the Type assocuiated with a VelocityDbType. This can be used when you want to rename a class or move a class to a different namespace. You will need to have the prior Type loaded as it it is defined in the current Schema for this to work. Once the update has been done, you should no longer need to keep the old Type loaded. Be sure to backup all your data before doing this.
Public methodRestoreFrom(DatabaseLocation, DateTime)
Restores Databases and pages from a backup DatabaseLocation. Existing data will be merged with the restored data unless existing Databases to restore are deleted before the restore.
Public methodRestoreFrom(String, String, UInt32, DateTime)
Restores a DatabaseLocation
Public methodStatic memberSetMinMaxStringIntern
A persistent string read into memory from a Database is interned using Intern(String) to speed up comparisons and conserve memory (when the same string occurs in many places)
Public methodSetTraceAllDbActivity
Enable some Trace output about persistent events related to all databases and pages. Add a Trace listener to get to Console window: Trace.Listeners.Add(new ConsoleTraceListener());
Public methodSetTraceDbActivity
Enable some Trace output about persistent events related to a Database. Add a Trace listener to get to Console window: Trace.Listeners.Add(new ConsoleTraceListener());
Public methodStatic memberStringToType
Gets a Type given a string representation of a type
Public methodSubscribeToChanges
Subscribe to committed database changes of instances of a type when an an optional property evaluates to true.
Public methodTryDatabase
Gets the current database to try
Public methodUnpersist
Use this when you want to delete objects that are not assignable as IOptimizedPersistable
Public methodUnsubscribeToChanges
Unsubscribe to committed database changes of instances of a type when an optional property evaluates to true.
Public methodUpdateClass
Let VelocityDB know that changes have been made to a class so that the schema manager will create a new TypeVersion and use the new version for all new objects of the specified Type.
Public methodUpdateDatabase
Request an update lock on a database
Public methodUpdateObject(Object)
Tag an object as updated so that it will be updated persistently
Public methodUpdateObject(IOptimizedPersistable)
Tag an object as updated so that it will be updated persistently
Public methodUpdateObject(Object, Action)
Provides a way to update an object in a multi thraeded scenario where we must make sure that object page isn't flushed until updates to object are done.
Public methodUpdateObject(IOptimizedPersistable, Action)
Provides a way to update an object in a multi thraeded scenario where we must make sure that object page isn't flushed until updates to object are done.
Public methodUpdateObject(IOptimizedPersistable, Boolean, Boolean)
Updates an object
Public methodUpdatePage
Update a Page. Used by VelocityDBExtensions project
Public methodVerify
Verifies that databases are valid by reading and following references. An exception is thrown if an issue is found.
Public methodWaitForIndexUpdates
Internal Use and in VelocityDBExtensions
Public methodWritePageBytes
Top
Fields
  NameDescription
Public fieldStatic memberAssembly
Public fieldStatic memberIndexDescriptorDatabaseNumber
Database 3 is dedicated to keeping track of index usage
Public fieldStatic members_serverTcpIpPortNumber
By default port number 7031 (7032 if .net core) is used for communication with VelocityDBServer. Change the value here and also in VelocityDbServer.exe.config if you need to use a different port number.
Public fieldStatic members_typeDatabaseIdOffsetFromTypeShortId
Determines database Id to use for a certain VelocityDbType instance
Public fieldStatic members_typeDatabaseIdOverflowIndexCollisionOffset
If additional databases are required for storing instances of some index, start by attempting creating database at this offset from original
Public fieldStatic members_typeDatabaseIdOverflowOffset
If additional databases are required for storing instances of some type, start by attempting creating database at this offset from original
Top
Extension Methods
  NameDescription
Public Extension MethodExportToCSV
Export all persistent objects to .csv files, one file for each Type and version of Type. This is preview release, format may change. ImportFromCSV can be used to recreate your data. Note that Microsoft Excel can't handle many of these CSV files due to a field value limitation (at about 33000 chars) Notepad++ is one application that can read these files. Some fields like array data are encoded http://msdn.microsoft.com/en-us/library/dhx0d524(v=vs.110).aspx
(Defined by ImportExportCsv.)
Public Extension MethodExportToJsonT(UInt64)Overloaded. (Defined by JsonImportExport.)
Public Extension MethodExportToJsonT(Oid)Overloaded. (Defined by JsonImportExport.)
Public Extension MethodExportToJsonT(Boolean, Boolean)Overloaded. (Defined by JsonImportExport.)
Public Extension MethodImportFromCSV
Restores database files, pages and objects from a .csv file data created with ExportToCSV
(Defined by ImportExportCsv.)
Public Extension MethodImportJsonT (Defined by JsonImportExport.)
Public Extension MethodMicrosoftSync (Defined by Sync.)
Public Extension MethodSyncWith(SessionBase)Overloaded. (Defined by Sync.)
Public Extension MethodSyncWith(SessionBase, FuncSessionBase, UInt64, Change, Boolean)Overloaded. (Defined by Sync.)
Top
See Also