Пример #1
0
 public static void Confirm(XmlElement xmlElement,
     DatabaseConfig dbConfig, bool compulsory)
 {
     Configuration.ConfirmBool(xmlElement, "AutoCommit",
         dbConfig.AutoCommit, compulsory);
     Configuration.ConfirmByteOrder(xmlElement, "ByteOrder",
         dbConfig.ByteOrder, compulsory);
     Configuration.ConfirmCacheSize(xmlElement, "CacheSize",
         dbConfig.CacheSize, compulsory);
     Configuration.ConfirmBool(xmlElement, "DoChecksum",
         dbConfig.DoChecksum, compulsory);
     Configuration.ConfirmEncryption(xmlElement, "Encryption",
         dbConfig.EncryptionPassword,
         dbConfig.EncryptAlgorithm, compulsory);
     Configuration.ConfirmString(xmlElement, "ErrorPrefix",
         dbConfig.ErrorPrefix, compulsory);
     Configuration.ConfirmBool(xmlElement, "FreeThreaded",
         dbConfig.FreeThreaded, compulsory);
     Configuration.ConfirmBool(xmlElement, "NoMMap",
         dbConfig.NoMMap, compulsory);
     Configuration.ConfirmBool(xmlElement, "NonDurableTxns",
         dbConfig.NonDurableTxns, compulsory);
     Configuration.ConfirmUint(xmlElement, "PageSize",
         dbConfig.PageSize, compulsory);
     Configuration.ConfirmCachePriority(xmlElement,
         "Priority", dbConfig.Priority, compulsory);
     Configuration.ConfirmBool(xmlElement, "ReadOnly",
         dbConfig.ReadOnly, compulsory);
     Configuration.ConfirmBool(xmlElement, "ReadUncommitted",
         dbConfig.ReadUncommitted, compulsory);
     Configuration.ConfirmBool(xmlElement, "Truncate",
         dbConfig.Truncate, compulsory);
     Configuration.ConfirmBool(xmlElement, "UseMVCC",
         dbConfig.UseMVCC, compulsory);
 }
Пример #2
0
        internal void Config(DatabaseConfig cfg) {
            // The cache size cannot change.
            if (cfg.CacheSize != null)
                db.set_cachesize(cfg.CacheSize.Gigabytes,
                    cfg.CacheSize.Bytes, cfg.CacheSize.NCaches);
            if (cfg.encryptionIsSet)
                db.set_encrypt(
                    cfg.EncryptionPassword, (uint)cfg.EncryptAlgorithm);
            if (cfg.ErrorPrefix != null)
                ErrorPrefix = cfg.ErrorPrefix;
            if (cfg.ErrorFeedback != null)
                ErrorFeedback = cfg.ErrorFeedback;
            if (cfg.Feedback != null)
                Feedback = cfg.Feedback;

            db.set_flags(cfg.flags);
            if (cfg.ByteOrder != ByteOrder.MACHINE)
                db.set_lorder(cfg.ByteOrder.lorder);
            if (cfg.NoWaitDbExclusiveLock == true)
                db.set_lk_exclusive(1);
            else if (cfg.NoWaitDbExclusiveLock == false)
                db.set_lk_exclusive(0);
            if (cfg.pagesizeIsSet)
                db.set_pagesize(cfg.PageSize);
            if (cfg.Priority != CachePriority.DEFAULT)
                db.set_priority(cfg.Priority.priority);
        }
Пример #3
0
        public static void Config(XmlElement xmlElement,
            ref DatabaseConfig dbConfig, bool compulsory)
        {
            uint pageSize = new uint();

            Configuration.ConfigBool(xmlElement, "AutoCommit",
                ref dbConfig.AutoCommit, compulsory);
            Configuration.ConfigByteOrder(xmlElement, "ByteOrder",
                ref dbConfig.ByteOrder, compulsory);
            Configuration.ConfigCacheInfo(xmlElement, "CacheSize",
                ref dbConfig.CacheSize, compulsory);
            Configuration.ConfigBool(xmlElement, "DoChecksum",
                ref dbConfig.DoChecksum, compulsory);
            Configuration.ConfigString(xmlElement, "ErrorPrefix",
                ref dbConfig.ErrorPrefix, compulsory);
            Configuration.ConfigBool(xmlElement, "FreeThreaded",
                ref dbConfig.FreeThreaded, compulsory);
            Configuration.ConfigBool(xmlElement, "NoMMap",
                ref dbConfig.NoMMap, compulsory);
            Configuration.ConfigBool(xmlElement, "NonDurableTxns",
                ref dbConfig.NonDurableTxns, compulsory);
            if (Configuration.ConfigUint(xmlElement, "PageSize",
                ref pageSize, compulsory))
                dbConfig.PageSize = pageSize;
            Configuration.ConfigCachePriority(xmlElement,
                "Priority", ref dbConfig.Priority, compulsory);
            Configuration.ConfigBool(xmlElement, "ReadOnly",
                ref dbConfig.ReadOnly, compulsory);
            Configuration.ConfigBool(xmlElement, "ReadUncommitted",
                ref dbConfig.ReadUncommitted, compulsory);
            Configuration.ConfigEncryption(xmlElement,
                "Encryption", dbConfig, compulsory);
            Configuration.ConfigBool(xmlElement, "Truncate",
                ref dbConfig.Truncate, compulsory);
            Configuration.ConfigBool(xmlElement, "UseMVCC",
                ref dbConfig.UseMVCC, compulsory);
        }
Пример #4
0
 /// <summary>
 /// Write the key/data pairs from all databases in the file to 
 /// <paramref name="OutputStream"/>. Key values are written for Btree,
 /// Hash and Queue databases, but not for Recno databases.
 /// </summary>
 /// <param name="file">
 /// The physical file in which the databases to be salvaged are found.
 /// </param>
 /// <param name="cfg">
 /// Configuration parameters for the databases to be salvaged.
 /// </param>
 /// <param name="Printable">
 /// If true and characters in either the key or data items are printing
 /// characters (as defined by isprint(3)), use printing characters to
 /// represent them. This setting permits users to use standard text
 /// editors and tools to modify the contents of databases or selectively
 /// remove data from salvager output. 
 /// </param>
 /// <param name="Aggressive">
 /// If true, output all the key/data pairs found in the file.
 /// Corruption of these data pairs is assumed, and corrupted or deleted
 /// data pairs may appear in the output (even if the salvaged file is in no
 /// way corrupt). This output almost certainly requires editing before being
 /// loaded into a database.
 /// </param>
 /// <param name="OutputStream">
 /// The TextWriter to which the databases' key/data pairs are written.
 /// If null, <see cref="Console.Out"/> is used.
 /// </param>
 public static void Salvage(string file, DatabaseConfig cfg,
     bool Printable, bool Aggressive, TextWriter OutputStream)
 {
     using (Database db = new Database(cfg.Env, 0)) {
         db.Config(cfg);
         if (OutputStream == null)
             OutputStream = Console.Out;
         uint flags = DbConstants.DB_SALVAGE;
         flags |= Aggressive ? DbConstants.DB_AGGRESSIVE : 0;
         flags |= Printable ? DbConstants.DB_PRINTABLE : 0;
         writeToFileRef = new BDB_FileWriteDelegate(writeToFile);
         db.db.verify(file, null, OutputStream, writeToFileRef, flags);
     }
 }
Пример #5
0
 /// <summary>
 /// Write the key/data pairs from all databases in the file to 
 /// <paramref name="OutputStream"/>. Key values are written for Btree,
 /// Hash and Queue databases, but not for Recno databases.
 /// </summary>
 /// <param name="file">
 /// The physical file in which the databases to be salvaged are found.
 /// </param>
 /// <param name="cfg">
 /// Configuration parameters for the databases to be salvaged.
 /// </param>
 /// <param name="Printable">
 /// If true and characters in either the key or data items are printing
 /// characters (as defined by isprint(3)), use printing characters to
 /// represent them. This setting permits users to use standard text
 /// editors and tools to modify the contents of databases or selectively
 /// remove data from salvager output. 
 /// </param>
 /// <param name="OutputStream">
 /// The TextWriter to which the databases' key/data pairs are written.
 /// If null, <see cref="Console.Out"/> is used.
 /// </param>
 public static void Salvage(string file,
     DatabaseConfig cfg, bool Printable, TextWriter OutputStream)
 {
     Salvage(file, cfg, Printable, false, OutputStream);
 }
Пример #6
0
 /// <summary>
 /// Write the key/data pairs from all databases in the file to 
 /// <see cref="Console.Out"/>. Key values are written for Btree, Hash
 /// and Queue databases, but not for Recno databases.
 /// </summary>
 /// <param name="file">
 /// The physical file in which the databases to be salvaged are found.
 /// </param>
 /// <param name="cfg">
 /// Configuration parameters for the databases to be salvaged.
 /// </param>
 public static void Salvage(string file, DatabaseConfig cfg)
 {
     Salvage(file, cfg, false, false, null);
 }
Пример #7
0
 /// <summary>
 /// Instantiate a new Database object and open the database represented
 /// by <paramref name="Filename"/>. The file specified by
 /// <paramref name="Filename"/> must exist.
 /// </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 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 Database Open(
     string Filename, DatabaseConfig cfg, Transaction txn)
 {
     return Open(Filename, null, cfg, txn);
 }
Пример #8
0
        public void TestOpenExistingHeapDB()
        {
            testName = "TestOpenExistingHeapDB";
            SetUpTest(true);
            string heapDBFileName = testHome + "/" + testName + ".db";

            HeapDatabaseConfig heapConfig = new HeapDatabaseConfig();
            heapConfig.Creation = CreatePolicy.ALWAYS;
            HeapDatabase heapDB = HeapDatabase.Open(
                heapDBFileName, heapConfig);
            heapDB.Close();

            DatabaseConfig dbConfig = new DatabaseConfig();
            Database db = Database.Open(heapDBFileName, dbConfig);
            Assert.AreEqual(db.Type, DatabaseType.HEAP);
            db.Close();
        }
Пример #9
0
        public void TestOpenMulDBInSingleFile()
        {
            testName = "TestOpenMulDBInSingleFile";
            testHome = testFixtureHome + "/" + testName;
            string btreeDBFileName = testHome + "/" +
                testName + ".db";
            string[] btreeDBArr = new string[4];

            for (int i = 0; i < 4; i++)
                btreeDBArr[i] = Path.GetFileNameWithoutExtension(
                    btreeDBFileName) + i;

            Configuration.ClearDir(testHome);

            BTreeDatabaseConfig btreeDBConfig =
                new BTreeDatabaseConfig();
            btreeDBConfig.Creation = CreatePolicy.IF_NEEDED;

            BTreeDatabase btreeDB;
            for (int i = 0; i < 4; i++)
            {
                btreeDB = BTreeDatabase.Open(btreeDBFileName,
                    btreeDBArr[i], btreeDBConfig);
                Assert.AreEqual(CreatePolicy.IF_NEEDED, btreeDB.Creation);
                btreeDB.Close();
            }

            DatabaseConfig dbConfig = new DatabaseConfig();
            Database db;
            for (int i = 0; i < 4; i++)
            {
                using (db = Database.Open(btreeDBFileName,
                    btreeDBArr[i], dbConfig))
                {
                    Assert.AreEqual(btreeDBArr[i],
                        db.DatabaseName);
                    Assert.AreEqual(DatabaseType.BTREE,
                        db.Type);
                }
            }
        }
Пример #10
0
        public virtual void TestConfigWithoutEnv()
        {
            string testName = "TestConfigWithoutEnv";
            string testFixtureName = "DatabaseConfigTest";

            XmlElement xmlElem = Configuration.TestSetUp(
                testFixtureName, testName);
            DatabaseConfig dbConfig = new DatabaseConfig();
            Config(xmlElem, ref dbConfig, true);
            Confirm(xmlElem, dbConfig, true);
        }
Пример #11
0
 /// <summary>
 /// Verify the integrity of all databases in the file specified by
 /// <paramref name="file"/>.
 /// </summary>
 /// <remarks>
 /// <para>
 /// Berkeley DB normally verifies that btree keys and duplicate items
 /// are correctly sorted, and hash keys are correctly hashed. If the
 /// file being verified contains multiple databases using differing
 /// sorting or hashing algorithms, some of them must necessarily fail
 /// database verification because only one sort order or hash function
 /// can be specified in <paramref name="cfg"/>. To verify files with
 /// multiple databases having differing sorting orders or hashing
 /// functions, first perform verification of the file as a whole by
 /// using <see cref="VerifyOperation.NO_ORDER_CHECK"/>, and then
 /// individually verify the sort order and hashing function for each
 /// database in the file using
 /// <see cref="VerifyOperation.ORDER_CHECK_ONLY"/>.
 /// </para>
 /// </remarks>
 /// <param name="file">
 /// The physical file in which the databases to be verified are found.
 /// </param>
 /// <param name="cfg">
 /// Configuration parameters for the databases to be verified.
 /// </param>
 /// <param name="op">The extent of verification</param>
 public static void Verify(
     string file, DatabaseConfig cfg, VerifyOperation op)
 {
     Verify(file, null, cfg, op);
 }
Пример #12
0
        public void TestOpenExistingQueueDB()
        {
            testName = "TestOpenExistingQueueDB";
            SetUpTest(true);
            string queueDBFileName = testHome + "/" + testName + ".db";

            QueueDatabaseConfig queueConfig = new QueueDatabaseConfig();
            queueConfig.Creation = CreatePolicy.ALWAYS;
            QueueDatabase queueDB = QueueDatabase.Open(
                queueDBFileName, queueConfig);
            queueDB.Close();

            DatabaseConfig dbConfig = new DatabaseConfig();
            Database db = Database.Open(queueDBFileName, dbConfig);
            Assert.AreEqual(db.Type, DatabaseType.QUEUE);
            db.Close();
        }
Пример #13
0
        public void TestOpenExistingHashDB()
        {
            testName = "TestOpenExistingHashDB";
            testHome = testFixtureHome + "/" + testName;
            string dbFileName = testHome + "/" + testName + ".db";

            Configuration.ClearDir(testHome);

            HashDatabaseConfig hashConfig =
                new HashDatabaseConfig();
            hashConfig.Creation = CreatePolicy.ALWAYS;
            HashDatabase hashDB = HashDatabase.Open(dbFileName, hashConfig);
            hashDB.Close();

            DatabaseConfig dbConfig = new DatabaseConfig();
            Database db = Database.Open(dbFileName, dbConfig);
            Assert.AreEqual(db.Type, DatabaseType.HASH);
            db.Close();
        }
Пример #14
0
        public static bool ConfigEncryption(XmlElement xmlElem,
		    string name, DatabaseConfig dbConfig, bool compulsory)
        {
            EncryptionAlgorithm alg;
            XmlNode xmlNode;
            string tmp, password;

            xmlNode = XMLReader.GetNode(xmlElem, name);
            if (xmlNode == null && compulsory == false)
                return false;
            else if (xmlNode == null && compulsory == true)
                throw new ConfigNotFoundException(name);

            password = XMLReader.GetNode((XmlElement)xmlNode,
                "password").InnerText;
            tmp = XMLReader.GetNode((XmlElement)xmlNode, "algorithm").InnerText;
            if (tmp == "AES")
                alg = EncryptionAlgorithm.AES;
            else
                alg = EncryptionAlgorithm.DEFAULT;
            dbConfig.SetEncryption(password, alg);
            return true;
        }
Пример #15
0
 /// <summary>
 /// Upgrade all of the databases included in the file
 /// <paramref name="file"/>, if necessary. If no upgrade is necessary,
 /// Upgrade always returns successfully.
 /// </summary>
 /// <overloads>
 /// Database upgrades are done in place and are destructive. For
 /// example, if pages need to be allocated and no disk space is
 /// available, the database may be left corrupted. Backups should be
 /// made before databases are upgraded. See Upgrading databases in the
 /// Programmer's Reference Guide for more information.
 /// </overloads>
 /// <remarks>
 /// <para>
 /// As part of the upgrade from the Berkeley DB 3.0 release to the 3.1
 /// release, the on-disk format of duplicate data items changed. To
 /// correctly upgrade the format requires applications to specify
 /// whether duplicate data items in the database are sorted or not.
 /// Specifying <paramref name="dupSortUpgraded"/> informs Upgrade that
 /// the duplicates are sorted; otherwise they are assumed to be
 /// unsorted. Incorrectly specifying the value of this flag may lead to
 /// database corruption.
 /// </para>
 /// <para>
 /// Further, because this method upgrades a physical file (including all
 /// the databases it contains), it is not possible to use Upgrade to
 /// upgrade files in which some of the databases it includes have sorted
 /// duplicate data items, and some of the databases it includes have
 /// unsorted duplicate data items. If the file does not have more than a
 /// single database, if the databases do not support duplicate data
 /// items, or if all of the databases that support duplicate data items
 /// support the same style of duplicates (either sorted or unsorted), 
 /// Upgrade works correctly as long as
 /// <paramref name="dupSortUpgraded"/> is correctly specified.
 /// Otherwise, the file cannot be upgraded using Upgrade it must be
 /// upgraded manually by dumping and reloading the databases.
 /// </para>
 /// </remarks>
 /// <param name="file">
 /// The physical file containing the databases to be upgraded.
 /// </param>
 /// <param name="cfg">
 /// Configuration parameters for the databases to be upgraded.
 /// </param>
 /// <param name="dupSortUpgraded">
 /// If true, the duplicates in the upgraded database are sorted;
 /// otherwise they are assumed to be unsorted.  This setting is only 
 /// meaningful when upgrading databases from releases before the
 /// Berkeley DB 3.1 release.
 /// </param>
 public static void Upgrade(
     string file, DatabaseConfig cfg, bool dupSortUpgraded)
 {
     Database db = new Database(cfg.Env, 0);
     db.Config(cfg);
     db.db.upgrade(file, dupSortUpgraded ? DbConstants.DB_DUPSORT : 0);
 }
Пример #16
0
 /// <summary>
 /// Verify the integrity of all databases in the file specified by 
 /// <paramref name="file"/>.
 /// </summary>
 /// <remarks>
 /// <para>
 /// Berkeley DB normally verifies that btree keys and duplicate items
 /// are correctly sorted, and hash keys are correctly hashed. If the
 /// file being verified contains multiple databases using differing
 /// sorting or hashing algorithms, some of them must necessarily fail
 /// database verification because only one sort order or hash function
 /// can be specified in <paramref name="cfg"/>. To verify files with
 /// multiple databases having differing sorting orders or hashing
 /// functions, first perform verification of the file as a whole by
 /// using <see cref="VerifyOperation.NO_ORDER_CHECK"/>, and then
 /// individually verify the sort order and hashing function for each
 /// database in the file using
 /// <see cref="VerifyOperation.ORDER_CHECK_ONLY"/>.
 /// </para>
 /// </remarks>
 /// <param name="file">
 /// The physical file in which the databases to be verified are found.
 /// </param>
 /// <param name="cfg">
 /// Configuration parameters for the databases to be verified.
 /// </param>
 /// <param name="op">The extent of verification</param>
 public static void Verify(
     string file, DatabaseConfig cfg, VerifyOperation op)
 {
     Verify(file, null, cfg, op);
 }
Пример #17
0
 /// <summary>
 /// Instantiate a new Database object and open the database represented
 /// by <paramref name="Filename"/>. The file specified by
 /// <paramref name="Filename"/> must exist.
 /// </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 will
 /// be implicitly transaction protected. Note that transactionally
 /// protected operations on a datbase object requires the object itself
 /// be transactionally protected during its open. Also note that the
 /// transaction must be committed before the object is closed.
 /// </para>
 /// </remarks>
 /// <param name="Filename">
 /// The name of an underlying file that will be 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="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 Database Open(
     string Filename, DatabaseConfig cfg, Transaction txn)
 {
     return(Open(Filename, null, cfg, txn));
 }
Пример #18
0
        public void TestOpenExistingBtreeDB()
        {
            testName = "TestOpenExistingBtreeDB";
            testHome = testFixtureHome + "/" + testName;
            string btreeDBFileName = testHome + "/" +
                 testName + ".db";

            Configuration.ClearDir(testHome);

            BTreeDatabaseConfig btreeConfig =
                new BTreeDatabaseConfig();
            btreeConfig.Creation = CreatePolicy.ALWAYS;
            BTreeDatabase btreeDB = BTreeDatabase.Open(
                btreeDBFileName, btreeConfig);
            btreeDB.Close();

            DatabaseConfig dbConfig = new DatabaseConfig();
            Database db = Database.Open(btreeDBFileName,
                dbConfig);
            Assert.AreEqual(db.Type, DatabaseType.BTREE);
            Assert.AreEqual(db.Creation, CreatePolicy.NEVER);
            db.Close();
        }
Пример #19
0
 /// <summary>
 /// Instantiate a new Database object and open the database represented
 /// by <paramref name="Filename"/>. The file specified by
 /// <paramref name="Filename"/> must exist.
 /// </summary>
 /// <remarks>
 /// <para>
 /// If <see cref="DatabaseConfig.AutoCommit"/> is set, the operation
 /// will be implicitly transaction protected. Note that transactionally
 /// protected operations on a datbase object requires the object itself
 /// be transactionally protected during its open.
 /// </para>
 /// </remarks>
 /// <param name="Filename">
 /// The name of an underlying file that will be used to back the
 /// database.
 /// </param>
 /// <param name="cfg">The database's configuration</param>
 /// <returns>A new, open database object</returns>
 public static Database Open(string Filename, DatabaseConfig cfg)
 {
     return(Open(Filename, null, cfg, null));
 }
Пример #20
0
 /// <summary>
 /// Protected factory method to create and open a new database object.
 /// </summary>
 /// <param name="Filename">The database's filename</param>
 /// <param name="DatabaseName">The subdatabase's name</param>
 /// <param name="cfg">The database's configuration</param>
 /// <param name="txn">
 /// The transaction in which to open the database
 /// </param>
 /// <returns>A new, open database object</returns>
 protected static BaseDatabase Open(string Filename,
     string DatabaseName, DatabaseConfig cfg, Transaction txn)
 {
     BaseDatabase ret = new BaseDatabase(cfg.Env, 0);
     ret.Config(cfg);
     ret.db.open(Transaction.getDB_TXN(txn),
         Filename, DatabaseName, DBTYPE.DB_UNKNOWN, cfg.openFlags, 0);
     return ret;
 }
Пример #21
0
 /// <summary>
 /// Write the key/data pairs from all databases in the file to
 /// <see cref="Console.Out"/>. Key values are written for Btree, Hash
 /// and Queue databases, but not for Recno databases.
 /// </summary>
 /// <param name="file">
 /// The physical file in which the databases to be salvaged are found.
 /// </param>
 /// <param name="cfg">
 /// Configuration parameters for the databases to be salvaged.
 /// </param>
 public static void Salvage(string file, DatabaseConfig cfg)
 {
     Salvage(file, cfg, false, false, null);
 }
Пример #22
0
 /// <summary>
 /// Instantiate a new Database object and open the database represented
 /// by <paramref name="Filename"/> and <paramref name="DatabaseName"/>.
 /// 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 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. 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, an error
 /// occurs if you 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>
 /// <returns>A new, open database object</returns>
 public static Database Open(
     string Filename, string DatabaseName, DatabaseConfig cfg)
 {
     return Open(Filename, DatabaseName, cfg, null);
 }
Пример #23
0
 /// <summary>
 /// Write the key/data pairs from all databases in the file to
 /// <see cref="Console.Out"/>. Key values are written for Btree, Hash
 /// and Queue databases, but not for Recno databases.
 /// </summary>
 /// <param name="file">
 /// The physical file in which the databases to be salvaged are found.
 /// </param>
 /// <param name="cfg">
 /// Configuration parameters for the databases to be salvaged.
 /// </param>
 /// <param name="Printable">
 /// If true and characters in either the key or data items are printing
 /// characters (as defined by isprint(3)), use printing characters to
 /// represent them. This setting permits users to use standard text
 /// editors and tools to modify the contents of databases or selectively
 /// remove data from salvager output.
 /// </param>
 public static void Salvage(
     string file, DatabaseConfig cfg, bool Printable)
 {
     Salvage(file, cfg, Printable, false, null);
 }
Пример #24
0
 /// <summary>
 /// Instantiate a new Database object and open the database represented
 /// by <paramref name="Filename"/> and <paramref name="DatabaseName"/>. 
 /// The file specified by <paramref name="Filename"/> must exist.
 /// </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 new Database Open(string Filename,
     string DatabaseName, DatabaseConfig cfg, Transaction txn)
 {
     Database ret;
     BaseDatabase db = BaseDatabase.Open(
         Filename, DatabaseName, cfg, txn);
     switch (db.Type.getDBTYPE()) {
         case DBTYPE.DB_BTREE:
             ret = new BTreeDatabase(db);
             break;
         case DBTYPE.DB_HASH:
             ret = new HashDatabase(db);
             break;
         case DBTYPE.DB_HEAP:
             ret = new HeapDatabase(db);
             break;
         case DBTYPE.DB_QUEUE:
             ret = new QueueDatabase(db);
             break;
         case DBTYPE.DB_RECNO:
             ret = new RecnoDatabase(db);
             break;
         default:
             throw new DatabaseException(0);
     }
     db.Dispose();
     ret.isOpen = true;
     return ret;
 }
Пример #25
0
 /// <summary>
 /// Write the key/data pairs from all databases in the file to
 /// <paramref name="OutputStream"/>. Key values are written for Btree,
 /// Hash and Queue databases, but not for Recno databases.
 /// </summary>
 /// <param name="file">
 /// The physical file in which the databases to be salvaged are found.
 /// </param>
 /// <param name="cfg">
 /// Configuration parameters for the databases to be salvaged.
 /// </param>
 /// <param name="Printable">
 /// If true and characters in either the key or data items are printing
 /// characters (as defined by isprint(3)), use printing characters to
 /// represent them. This setting permits users to use standard text
 /// editors and tools to modify the contents of databases or selectively
 /// remove data from salvager output.
 /// </param>
 /// <param name="OutputStream">
 /// The TextWriter to which the databases' key/data pairs are written.
 /// If null, <see cref="Console.Out"/> will be used.
 /// </param>
 public static void Salvage(string file,
                            DatabaseConfig cfg, bool Printable, TextWriter OutputStream)
 {
     Salvage(file, cfg, Printable, false, OutputStream);
 }
Пример #26
0
 /// <summary>
 /// Write the key/data pairs from all databases in the file to 
 /// <see cref="Console.Out"/>. Key values are written for Btree, Hash
 /// and Queue databases, but not for Recno databases.
 /// </summary>
 /// <param name="file">
 /// The physical file in which the databases to be salvaged are found.
 /// </param>
 /// <param name="cfg">
 /// Configuration parameters for the databases to be salvaged.
 /// </param>
 /// <param name="Printable">
 /// If true and characters in either the key or data items are printing
 /// characters (as defined by isprint(3)), use printing characters to
 /// represent them. This setting permits users to use standard text
 /// editors and tools to modify the contents of databases or selectively
 /// remove data from salvager output. 
 /// </param>
 public static void Salvage(
     string file, DatabaseConfig cfg, bool Printable)
 {
     Salvage(file, cfg, Printable, false, null);
 }
Пример #27
0
 /// <summary>
 /// Write the key/data pairs from all databases in the file to
 /// <see cref="Console.Out"/>. Key values are written for Btree, Hash
 /// and Queue databases, but not for Recno databases.
 /// </summary>
 /// <param name="file">
 /// The physical file in which the databases to be salvaged are found.
 /// </param>
 /// <param name="cfg">
 /// Configuration parameters for the databases to be salvaged.
 /// </param>
 /// <param name="Printable">
 /// If true and characters in either the key or data items are printing
 /// characters (as defined by isprint(3)), use printing characters to
 /// represent them. This setting permits users to use standard text
 /// editors and tools to modify the contents of databases or selectively
 /// remove data from salvager output.
 /// </param>
 /// <param name="Aggressive">
 /// If true, output all the key/data pairs in the file that can be
 /// found.  Corruption will be assumed and key/data pairs that are
 /// corrupted or have been deleted may appear in the output (even if the
 /// file being salvaged is in no way corrupt), and the output will
 /// almost certainly require editing before being loaded into a
 /// database.
 /// </param>
 public static void Salvage(string file,
                            DatabaseConfig cfg, bool Printable, bool Aggressive)
 {
     Salvage(file, cfg, Printable, Aggressive, null);
 }
Пример #28
0
 /// <summary>
 /// Write the key/data pairs from all databases in the file to 
 /// <see cref="Console.Out"/>. Key values are written for Btree, Hash
 /// and Queue databases, but not for Recno databases.
 /// </summary>
 /// <param name="file">
 /// The physical file in which the databases to be salvaged are found.
 /// </param>
 /// <param name="cfg">
 /// Configuration parameters for the databases to be salvaged.
 /// </param>
 /// <param name="Printable">
 /// If true and characters in either the key or data items are printing
 /// characters (as defined by isprint(3)), use printing characters to
 /// represent them. This setting permits users to use standard text
 /// editors and tools to modify the contents of databases or selectively
 /// remove data from salvager output. 
 /// </param>
 /// <param name="Aggressive">
 /// If true, output all the key/data pairs found in the file.
 /// Corruption of these data pairs is assumed, and corrupted or deleted
 /// data pairs may appear in the output (even if the salvaged file is in no
 /// way corrupt). This output almost certainly requires editing before being
 /// loaded into a database.
 /// </param>
 public static void Salvage(string file,
     DatabaseConfig cfg, bool Printable, bool Aggressive)
 {
     Salvage(file, cfg, Printable, Aggressive, null);
 }
Пример #29
0
 /// <summary>
 /// Upgrade all of the databases included in the file
 /// <paramref name="file"/>, if necessary. If no upgrade is necessary,
 /// Upgrade always returns successfully.
 /// </summary>
 /// <param name="file">
 /// The physical file containing the databases to be upgraded.
 /// </param>
 /// <param name="cfg">
 /// Configuration parameters for the databases to be upgraded.
 /// </param>
 public static void Upgrade(string file, DatabaseConfig cfg)
 {
     Upgrade(file, cfg, false);
 }
Пример #30
0
 /// <summary>
 /// Upgrade all of the databases included in the file
 /// <paramref name="file"/>, if necessary. If no upgrade is necessary,
 /// Upgrade always returns successfully.
 /// </summary>
 /// <param name="file">
 /// The physical file containing the databases to be upgraded.
 /// </param>
 /// <param name="cfg">
 /// Configuration parameters for the databases to be upgraded.
 /// </param>
 public static void Upgrade(string file, DatabaseConfig cfg)
 {
     Upgrade(file, cfg, false);
 }
Пример #31
0
 /// <summary>
 /// Verify the integrity of all databases in the file specified by
 /// <paramref name="file"/>.
 /// </summary>
 /// <overloads>
 /// Verify does not perform any locking, even in Berkeley DB
 /// environments that are configured with a locking subsystem. As such,
 /// it should only be used on files that are not being modified by
 /// another thread of control.
 /// </overloads>
 /// <param name="file">
 /// The physical file in which the databases to be verified are found.
 /// </param>
 /// <param name="cfg">
 /// Configuration parameters for the databases to be verified.
 /// </param>
 public static void Verify(string file, DatabaseConfig cfg)
 {
     Verify(file, null, cfg, VerifyOperation.DEFAULT);
 }
Пример #32
0
 /// <summary>
 /// Verify the integrity of all databases in the file specified by 
 /// <paramref name="file"/>.
 /// </summary>
 /// <overloads>
 /// Verify does not perform any locking, even in Berkeley DB
 /// environments that are configured with a locking subsystem. As such,
 /// it should only be used on files that are not being modified by
 /// another thread of control.
 /// </overloads>
 /// <param name="file">
 /// The physical file in which the databases to be verified are found.
 /// </param>
 /// <param name="cfg">
 /// Configuration parameters for the databases to be verified.
 /// </param>
 public static void Verify(string file, DatabaseConfig cfg)
 {
     Verify(file, null, cfg, VerifyOperation.DEFAULT);
 }
        public void TestRemoveDBWithinTxn()
        {
            testName = "TestRemoveDBWithinTxn";
            SetUpTest(true);
            string dbFileName = testName + ".db";
            string dbName1 = testName + "1";
            string dbName2 = testName + "2";

            // Open environment.
            DatabaseEnvironmentConfig envConfig =
                new DatabaseEnvironmentConfig();
            envConfig.Create = true;
            envConfig.UseMPool = true;
            envConfig.UseTxns = true;
            envConfig.UseLogging = true;
            DatabaseEnvironment env = DatabaseEnvironment.Open(
                testHome, envConfig);
            Transaction txn = env.BeginTransaction();

            // Create two databases in the environment.
            BTreeDatabaseConfig dbConfig =
                new BTreeDatabaseConfig();
            dbConfig.Creation = CreatePolicy.IF_NEEDED;
            dbConfig.Env = env;
            BTreeDatabase btreeDB1 = BTreeDatabase.Open(
                dbFileName, dbName1, dbConfig, txn);
            btreeDB1.Close();
            BTreeDatabase btreeDB2 = BTreeDatabase.Open(
                dbFileName, dbName2, dbConfig, txn);
            btreeDB2.Close();

            // Remove one database from the environment.
            env.RemoveDB(dbFileName, dbName2, false, txn);

            // Try to open the existing database.
            DatabaseConfig cfg = new DatabaseConfig();
            cfg.Env = env;
            Database db1 = Database.Open(dbFileName, dbName1, cfg, txn);
            db1.Close();

            /*
             * Attempting to open the removed database should
             * cause error.
             */
            try
            {
                Database db2 = Database.Open(
                    dbFileName, dbName2, cfg, txn);
                db2.Close();
            }
            catch (DatabaseException)
            {
                throw new ExpectedTestException();
            }
            finally
            {
                txn.Commit();
                env.Close();
            }
        }
Пример #34
0
 /// <summary>
 /// Verify the integrity of the database specified by 
 /// <paramref name="file"/> and <paramref name="database"/>.
 /// </summary>
 /// <remarks>
 /// <para>
 /// Berkeley DB normally verifies that btree keys and duplicate items
 /// are correctly sorted, and hash keys are correctly hashed. If the
 /// file being verified contains multiple databases using differing
 /// sorting or hashing algorithms, some of them must necessarily fail
 /// database verification because only one sort order or hash function
 /// can be specified in <paramref name="cfg"/>. To verify files with
 /// multiple databases having differing sorting orders or hashing
 /// functions, first perform verification of the file as a whole by
 /// using <see cref="VerifyOperation.NO_ORDER_CHECK"/>, and then
 /// individually verify the sort order and hashing function for each
 /// database in the file using
 /// <see cref="VerifyOperation.ORDER_CHECK_ONLY"/>.
 /// </para>
 /// </remarks>
 /// <param name="file">
 /// The physical file in which the databases to be verified are found.
 /// </param>
 /// <param name="database">
 /// The database in <paramref name="file"/> on which the database checks
 /// for btree and duplicate sort order and for hashing are to be
 /// performed.  A non-null value for database is only allowed with
 /// <see cref="VerifyOperation.ORDER_CHECK_ONLY"/>.
 /// </param>
 /// <param name="cfg">
 /// Configuration parameters for the databases to be verified.
 /// </param>
 /// <param name="op">The extent of verification</param>
 public static void Verify(string file,
     string database, DatabaseConfig cfg, VerifyOperation op)
 {
     using (Database db = new Database(cfg.Env, 0)) {
         db.Config(cfg);
         uint flags;
         switch (op) {
             case VerifyOperation.NO_ORDER_CHECK:
                 flags = DbConstants.DB_NOORDERCHK;
                 break;
             case VerifyOperation.ORDER_CHECK_ONLY:
                 flags = DbConstants.DB_ORDERCHKONLY;
                 break;
             case VerifyOperation.DEFAULT:
             default:
                 flags = 0;
                 break;
         }
         db.db.verify(file, database, null, null, flags);
     }
 }
        public void RmDBWithoutTxn(string home, string dbName,
		    bool ifAutoCommit)
        {
            string dbFileName = dbName + ".db";
            string dbName1 = dbName + "1";
            string dbName2 = dbName + "2";

            // Open environment.
            DatabaseEnvironmentConfig envConfig =
                new DatabaseEnvironmentConfig();
            envConfig.Create = true;
            envConfig.UseMPool = true;
            if (ifAutoCommit == true)
            {
                envConfig.AutoCommit = true;
                envConfig.UseTxns = true;
            }

            DatabaseEnvironment env = DatabaseEnvironment.Open(
                home, envConfig);

            // Create two databases in the environment.
            BTreeDatabaseConfig dbConfig =
                new BTreeDatabaseConfig();
            dbConfig.Creation = CreatePolicy.IF_NEEDED;
            dbConfig.Env = env;
            BTreeDatabase btreeDB1 = BTreeDatabase.Open(
                dbFileName, dbName1, dbConfig);
            btreeDB1.Close();
            BTreeDatabase btreeDB2 = BTreeDatabase.Open(
                dbFileName, dbName2, dbConfig);
            btreeDB2.Close();

            // Remove one database from the environment.
            env.RemoveDB(dbFileName, dbName2, false);

            // Try to open the existing database.
            DatabaseConfig cfg = new DatabaseConfig();
            cfg.Env = env;
            Database db1 = Database.Open(dbFileName, dbName1, cfg);
            db1.Close();

            /*
             * Attempting to open the removed database should
             * cause error.
             */
            try
            {
                Database db2 = Database.Open(
                    dbFileName, dbName2, cfg);
                db2.Close();
            }
            catch (DatabaseException)
            {
                throw new ExpectedTestException();
            }
            finally
            {
                env.Close();
            }
        }