/// <summary> /// Instantiate a new BTreeDatabase object and open the database /// represented by <paramref name="Filename"/> and /// <paramref name="DatabaseName"/>. /// </summary> /// <remarks> /// <para> /// If both <paramref name="Filename"/> and /// <paramref name="DatabaseName"/> are null, the database is strictly /// temporary and cannot be opened by any other thread of control, thus /// the database can only be accessed by sharing the single database /// object that created it, in circumstances where doing so is safe. If /// <paramref name="Filename"/> is null and /// <paramref name="DatabaseName"/> is non-null, the database can be /// opened by other threads of control and be replicated to client /// sites in any replication group. /// </para> /// <para> /// If <paramref name="txn"/> is null, but /// <see cref="DatabaseConfig.AutoCommit"/> is set, the operation /// is implicitly transaction protected. Transactionally /// protected operations on a database object requires the object itself /// be transactionally protected during its open. The /// transaction must be committed before the object is closed. /// </para> /// </remarks> /// <param name="Filename"> /// The name of an underlying file used to back the /// database. In-memory databases never intended to be preserved on disk /// may be created by setting this parameter to null. /// </param> /// <param name="DatabaseName"> /// This parameter allows applications to have multiple databases in a /// single file. Although no DatabaseName needs to be specified, it is /// an error to attempt to open a second database in a file that was not /// initially created using a database name. /// </param> /// <param name="cfg">The database's configuration</param> /// <param name="txn"> /// If the operation is part of an application-specified transaction, /// <paramref name="txn"/> is a Transaction object returned from /// <see cref="DatabaseEnvironment.BeginTransaction"/>; if /// the operation is part of a Berkeley DB Concurrent Data Store group, /// <paramref name="txn"/> is a handle returned from /// <see cref="DatabaseEnvironment.BeginCDSGroup"/>; otherwise null. /// </param> /// <returns>A new, open database object</returns> public static BTreeDatabase Open(string Filename, string DatabaseName, BTreeDatabaseConfig cfg, Transaction txn) { BTreeDatabase ret = new BTreeDatabase(cfg.Env, 0); ret.Config(cfg); ret.db.open(Transaction.getDB_TXN(txn), Filename, DatabaseName, DBTYPE.DB_BTREE, cfg.openFlags, 0); ret.isOpen = true; return(ret); }
/// <summary> /// Instantiate a new HeapDatabase object and open the database /// represented by <paramref name="Filename"/>. /// </summary> /// <remarks> /// <para> /// If <paramref name="Filename"/> is null, the database is strictly /// temporary and cannot be opened by any other thread of control, thus /// the database can only be accessed by sharing the single database /// object that created it, in circumstances where doing so is safe. /// </para> /// <para> /// If <paramref name="txn"/> is null, but /// <see cref="DatabaseConfig.AutoCommit"/> is set, the operation /// is implicitly transaction protected. Transactionally /// protected operations on a database object requires the object itself /// be transactionally protected during its open. The /// transaction must be committed before the object is closed. /// </para> /// </remarks> /// <param name="Filename"> /// The name of an underlying file used to back up the /// database. In-memory databases never intended to be preserved on disk /// may be created by setting this parameter to null. /// </param> /// <param name="cfg">The database's configuration</param> /// <param name="txn"> /// If the operation is part of an application-specified transaction, /// <paramref name="txn"/> is a Transaction object returned from /// <see cref="DatabaseEnvironment.BeginTransaction"/>; if /// the operation is part of a Berkeley DB Concurrent Data Store group, /// <paramref name="txn"/> is a handle returned from /// <see cref="DatabaseEnvironment.BeginCDSGroup"/>; otherwise null. /// </param> /// <returns>A new, open database object</returns> public static HeapDatabase Open( string Filename, HeapDatabaseConfig cfg, Transaction txn) { HeapDatabase ret = new HeapDatabase(cfg.Env, 0); ret.Config(cfg); ret.db.open(Transaction.getDB_TXN(txn), Filename, null, DBTYPE.DB_HEAP, cfg.openFlags, 0); ret.isOpen = true; return(ret); }
/// <summary> /// Instantiate a new RecnoDatabase object and open the database /// represented by <paramref name="Filename"/> and /// <paramref name="DatabaseName"/>. /// </summary> /// <remarks> /// <para> /// If both <paramref name="Filename"/> and /// <paramref name="DatabaseName"/> are null, the database is strictly /// temporary and cannot be opened by any other thread of control, thus /// the database can only be accessed by sharing the single database /// object that created it, in circumstances where doing so is safe. If /// <paramref name="Filename"/> is null and /// <paramref name="DatabaseName"/> is non-null, the database can be /// opened by other threads of control and will be replicated to client /// sites in any replication group. /// </para> /// <para> /// If <paramref name="txn"/> is null, but /// <see cref="DatabaseConfig.AutoCommit"/> is set, the operation is /// implicitly transaction protected. Transactionally /// protected operations on a database object requires the object itself /// be transactionally protected during its open. The /// transaction must be committed before the object is closed. /// </para> /// </remarks> /// <param name="Filename"> /// The name of an underlying file used to back the /// database. In-memory databases never intended to be preserved on disk /// may be created by setting this parameter to null. /// </param> /// <param name="DatabaseName"> /// This parameter allows applications to have multiple databases in a /// single file. Although no DatabaseName needs to be specified, it is /// an error to attempt to open a second database in a file that was not /// initially created using a database name. /// </param> /// <param name="cfg">The database's configuration</param> /// <param name="txn"> /// If the operation is part of an application-specified transaction, /// <paramref name="txn"/> is a Transaction object returned from /// <see cref="DatabaseEnvironment.BeginTransaction"/>; if /// the operation is part of a Berkeley DB Concurrent Data Store group, /// <paramref name="txn"/> is a handle returned from /// <see cref="DatabaseEnvironment.BeginCDSGroup"/>; otherwise null. /// </param> /// <returns>A new, open database object</returns> public static RecnoDatabase Open(string Filename, string DatabaseName, RecnoDatabaseConfig cfg, Transaction txn) { RecnoDatabase ret = new RecnoDatabase(cfg.Env, 0); ret.Config(cfg); ret.db.open(Transaction.getDB_TXN(txn), Filename, DatabaseName, DBTYPE.DB_RECNO, cfg.openFlags, 0); ret.isOpen = true; return(ret); }
/// <summary> /// Create a transactionally protected database cursor with the given /// configuration. /// </summary> /// <param name="cfg"> /// The configuration properties for the cursor. /// </param> /// <param name="txn"> /// The transaction context in which the cursor may be used. /// </param> /// <returns>A newly created cursor</returns> public new BTreeCursor Cursor(CursorConfig cfg, Transaction txn) { if (cfg.Priority == CachePriority.DEFAULT) { return(new BTreeCursor(db.cursor( Transaction.getDB_TXN(txn), cfg.flags), Pagesize)); } else { return(new BTreeCursor(db.cursor(Transaction.getDB_TXN(txn), cfg.flags), Pagesize, cfg.Priority)); } }
/// <summary> /// Compact the database, and optionally return unused database pages to /// the underlying filesystem. /// </summary> /// <remarks> /// <para> /// If <paramref name="txn"/> is non-null, then the operation is /// performed using that transaction. In this event, large sections of /// the tree may be locked during the course of the transaction. /// </para> /// <para> /// If <paramref name="txn"/> is null, but the operation occurs in a /// transactional database, the operation is implicitly transaction /// protected using multiple transactions. These transactions are /// periodically committed to avoid locking large sections of the tree. /// Any deadlocks encountered cause the compaction operation to be /// retried from the point of the last transaction commit. /// </para> /// </remarks> /// <param name="cdata">Compact configuration parameters</param> /// <param name="txn"> /// If the operation is part of an application-specified transaction, /// <paramref name="txn"/> is a Transaction object returned from /// <see cref="DatabaseEnvironment.BeginTransaction"/>; if /// the operation is part of a Berkeley DB Concurrent Data Store group, /// <paramref name="txn"/> is a handle returned from /// <see cref="DatabaseEnvironment.BeginCDSGroup"/>; otherwise null. /// </param> /// <returns>Compact operation statistics</returns> public CompactData Compact(CompactConfig cdata, Transaction txn) { DatabaseEntry end = null; if (cdata.returnEnd) { end = new DatabaseEntry(); } db.compact(Transaction.getDB_TXN(txn), cdata.start, cdata.stop, CompactConfig.getDB_COMPACT(cdata), cdata.flags, end); return(new CompactData(CompactConfig.getDB_COMPACT(cdata), end)); }
private QueueStats Stats(Transaction txn, bool fast, Isolation isoDegree) { uint flags = 0; flags |= fast ? DbConstants.DB_FAST_STAT : 0; switch (isoDegree) { case Isolation.DEGREE_ONE: flags |= DbConstants.DB_READ_UNCOMMITTED; break; case Isolation.DEGREE_TWO: flags |= DbConstants.DB_READ_COMMITTED; break; } QueueStatStruct st = db.stat_qam(Transaction.getDB_TXN(txn), flags); return(new QueueStats(st)); }
/// <summary> /// Instantiate a new Sequence object. /// </summary> /// <remarks> /// If <paramref name="txn"/> is null and the operation occurs in a /// transactional database, the operation will be implicitly transaction /// protected. /// </remarks> /// <param name="cfg">Configuration parameters for the Sequence</param> /// <param name="txn"> /// If the operation is part of an application-specified transaction, /// <paramref name="txn"/> is a Transaction object returned from /// <see cref="DatabaseEnvironment.BeginTransaction"/>; if /// the operation is part of a Berkeley DB Concurrent Data Store group, /// <paramref name="txn"/> is a handle returned from /// <see cref="DatabaseEnvironment.BeginCDSGroup"/>; otherwise null. /// </param> public Sequence(SequenceConfig cfg, Transaction txn) { seq = new DB_SEQUENCE(cfg.BackingDatabase.db, 0); if (cfg.initialValIsSet) { seq.initial_value(cfg.InitialValue); } seq.set_flags(cfg.flags); if (cfg.rangeIsSet) { seq.set_range(cfg.Min, cfg.Max); } if (cfg.cacheSzIsSet) { seq.set_cachesize(cfg.CacheSize); } seq.open(Transaction.getDB_TXN(txn), cfg.key, cfg.openFlags); isOpen = true; }
/// <summary> /// Instantiate a new SecondaryDatabase object, open the database /// represented by <paramref name="Filename"/> and associate the /// database with the <see cref="SecondaryDatabaseConfig.Primary"> /// primary index</see>. The file specified by /// <paramref name="Filename"/> must exist. /// </summary> /// <remarks> /// <para> /// If <paramref name="Filename"/> is null and /// <paramref name="DatabaseName"/> is non-null, the database can be /// opened by other threads of control and will be replicated to client /// sites in any replication group. /// </para> /// <para> /// If <see cref="DatabaseConfig.AutoCommit"/> is set, the operation /// is implicitly transaction protected. Transactionally /// protected operations on a database object requires the object itself /// be transactionally protected during its open. /// </para> /// </remarks> /// <param name="Filename"> /// The name of an underlying file used to back the /// database. /// </param> /// <param name="DatabaseName"> /// This parameter allows applications to have multiple databases in a /// single file. Although no DatabaseName needs to be specified, it is /// an error to attempt to open a second database in a file that was not /// initially created using a database name. /// </param> /// <param name="cfg">The database's configuration</param> /// <param name="txn"> /// If the operation is part of an application-specified transaction, /// <paramref name="txn"/> is a Transaction object returned from /// <see cref="DatabaseEnvironment.BeginTransaction"/>; if /// the operation is part of a Berkeley DB Concurrent Data Store group, /// <paramref name="txn"/> is a handle returned from /// <see cref="DatabaseEnvironment.BeginCDSGroup"/>; otherwise null. /// </param> /// <returns>A new, open database object</returns> public static SecondaryDatabase Open(string Filename, string DatabaseName, SecondaryDatabaseConfig cfg, Transaction txn) { if (cfg.DbType == DatabaseType.BTREE) { return(SecondaryBTreeDatabase.Open(Filename, DatabaseName, (SecondaryBTreeDatabaseConfig)cfg, txn)); } else if (cfg.DbType == DatabaseType.HASH) { return(SecondaryHashDatabase.Open(Filename, DatabaseName, (SecondaryHashDatabaseConfig)cfg, txn)); } SecondaryDatabase ret = new SecondaryDatabase(cfg.Env, 0); ret.Config(cfg); ret.db.open(Transaction.getDB_TXN(txn), Filename, DatabaseName, cfg.DbType.getDBTYPE(), cfg.openFlags, 0); ret.doAssocRef = new BDB_AssociateDelegate(doAssociate); cfg.Primary.db.associate(Transaction.getDB_TXN(txn), ret.db, ret.doAssocRef, cfg.assocFlags); if (cfg.ForeignKeyDatabase != null) { if (cfg.OnForeignKeyDelete == ForeignKeyDeleteAction.NULLIFY) { ret.doNullifyRef = new BDB_AssociateForeignDelegate(doNullify); } else { ret.doNullifyRef = null; } cfg.ForeignKeyDatabase.db.associate_foreign(ret.db, ret.doNullifyRef, cfg.foreignFlags); } return(ret); }
/// <summary> /// Create a transactionally protected database cursor with the given /// configuration. /// </summary> /// <param name="cfg"> /// The configuration properties for the cursor. /// </param> /// <param name="txn"> /// The transaction context in which the cursor may be used. /// </param> /// <returns>A newly created cursor</returns> public new RecnoCursor Cursor(CursorConfig cfg, Transaction txn) { return(new RecnoCursor( db.cursor(Transaction.getDB_TXN(txn), cfg.flags), Pagesize)); }
/// <summary> /// Protected wrapper for DB->put. Used by subclasses for access method /// specific operations. /// </summary> /// <param name="key">The key to store in the database</param> /// <param name="data">The data item to store in the database</param> /// <param name="txn">Transaction with which to protect the put</param> /// <param name="flags">Flags to pass to DB->put</param> protected void Put(DatabaseEntry key, DatabaseEntry data, Transaction txn, uint flags) { db.put(Transaction.getDB_TXN(txn), key, data, flags); }
/// <summary> /// Create a transactionally protected secondary database cursor with /// the given configuration. /// </summary> /// <param name="cfg"> /// The configuration properties for the cursor. /// </param> /// <param name="txn"> /// The transaction context in which the cursor may be used. /// </param> /// <returns>A newly created cursor</returns> public SecondaryCursor SecondaryCursor( CursorConfig cfg, Transaction txn) { return(new SecondaryCursor( db.cursor(Transaction.getDB_TXN(txn), cfg.flags))); }