Ejemplo n.º 1
0
        /// <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);
        }
Ejemplo n.º 2
0
        /// <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;
        }