Example #1
0
        public void OpenSecHashDBWithinTxn(string className,
                                           string funName, string home, string dbFileName,
                                           string dbSecFileName, bool ifDbName)
        {
            XmlElement xmlElem = Configuration.TestSetUp(
                className, funName);

            // Open an environment.
            DatabaseEnvironmentConfig envConfig =
                new DatabaseEnvironmentConfig();

            envConfig.Create     = true;
            envConfig.UseTxns    = true;
            envConfig.UseMPool   = true;
            envConfig.UseLogging = true;
            DatabaseEnvironment env = DatabaseEnvironment.Open(
                home, envConfig);

            // Open a primary hash database.
            Transaction        openDBTxn = env.BeginTransaction();
            HashDatabaseConfig dbConfig  =
                new HashDatabaseConfig();

            dbConfig.Creation = CreatePolicy.IF_NEEDED;
            dbConfig.Env      = env;
            HashDatabase db = HashDatabase.Open(
                dbFileName, dbConfig, openDBTxn);

            openDBTxn.Commit();

            // Open a secondary hash database.
            Transaction openSecTxn = env.BeginTransaction();
            SecondaryHashDatabaseConfig secDBConfig =
                new SecondaryHashDatabaseConfig(db,
                                                new SecondaryKeyGenDelegate(SecondaryKeyGen));

            SecondaryHashDatabaseConfigTest.Config(xmlElem,
                                                   ref secDBConfig, false);
            secDBConfig.HashFunction = null;
            secDBConfig.Env          = env;
            SecondaryHashDatabase secDB;

            if (ifDbName == false)
            {
                secDB = SecondaryHashDatabase.Open(
                    dbSecFileName, secDBConfig, openSecTxn);
            }
            else
            {
                secDB = SecondaryHashDatabase.Open(
                    dbSecFileName, "secondary", secDBConfig,
                    openSecTxn);
            }
            openSecTxn.Commit();

            // Confirm its flags configured in secDBConfig.
            Confirm(xmlElem, secDB, true);
            secDB.Close();

            // Open the existing secondary database.
            Transaction             secTxn    = env.BeginTransaction();
            SecondaryDatabaseConfig secConfig =
                new SecondaryDatabaseConfig(db,
                                            new SecondaryKeyGenDelegate(SecondaryKeyGen));

            secConfig.Env = env;

            SecondaryDatabase secExDB;

            if (ifDbName == false)
            {
                secExDB = SecondaryHashDatabase.Open(
                    dbSecFileName, secConfig, secTxn);
            }
            else
            {
                secExDB = SecondaryHashDatabase.Open(
                    dbSecFileName, "secondary", secConfig,
                    secTxn);
            }
            secExDB.Close();
            secTxn.Commit();

            db.Close();
            env.Close();
        }
Example #2
0
        public void OpenSecHashDB(string className,
                                  string funName, string dbFileName, string dbSecFileName,
                                  bool ifDBName)
        {
            XmlElement xmlElem = Configuration.TestSetUp(
                className, funName);

            // Open a primary recno database.
            HashDatabaseConfig primaryDBConfig =
                new HashDatabaseConfig();

            primaryDBConfig.Creation = CreatePolicy.IF_NEEDED;
            HashDatabase primaryDB;

            /*
             * If secondary database name is given, the primary
             * database is also opened with database name.
             */
            if (ifDBName == false)
            {
                primaryDB = HashDatabase.Open(dbFileName,
                                              primaryDBConfig);
            }
            else
            {
                primaryDB = HashDatabase.Open(dbFileName,
                                              "primary", primaryDBConfig);
            }

            try
            {
                // Open a new secondary database.
                SecondaryHashDatabaseConfig secHashDBConfig =
                    new SecondaryHashDatabaseConfig(
                        primaryDB, null);
                SecondaryHashDatabaseConfigTest.Config(
                    xmlElem, ref secHashDBConfig, false);
                secHashDBConfig.Creation =
                    CreatePolicy.IF_NEEDED;

                SecondaryHashDatabase secHashDB;
                if (ifDBName == false)
                {
                    secHashDB = SecondaryHashDatabase.Open(
                        dbSecFileName, secHashDBConfig);
                }
                else
                {
                    secHashDB = SecondaryHashDatabase.Open(
                        dbSecFileName, "secondary",
                        secHashDBConfig);
                }

                // Close the secondary database.
                secHashDB.Close();

                // Open the existing secondary database.
                SecondaryDatabaseConfig secDBConfig =
                    new SecondaryDatabaseConfig(
                        primaryDB, null);

                SecondaryDatabase secDB;
                if (ifDBName == false)
                {
                    secDB = SecondaryHashDatabase.Open(
                        dbSecFileName, secDBConfig);
                }
                else
                {
                    secDB = SecondaryHashDatabase.Open(
                        dbSecFileName, "secondary", secDBConfig);
                }

                // Close secondary database.
                secDB.Close();
            }
            catch (DatabaseException)
            {
                throw new TestException();
            }
            finally
            {
                // Close primary database.
                primaryDB.Close();
            }
        }