/*
         * Open environment, database and write data into database.
         * Generated log files are put under testHome.
         */
        public void Logging(string home, string dbName,
		    out DatabaseEnvironment env, out RecnoDatabase recnoDB)
        {
            string dbFileName = dbName + ".db";

            Configuration.ClearDir(home);

            // Open environment with logging subsystem.
            DatabaseEnvironmentConfig envConfig =
                new DatabaseEnvironmentConfig();
            envConfig.Create = true;
            envConfig.UseLogging = true;
            envConfig.LogSystemCfg = new LogConfig();
            envConfig.LogSystemCfg.FileMode = 755;
            envConfig.LogSystemCfg.ZeroOnCreate = true;
            envConfig.UseMPool = true;
            env = DatabaseEnvironment.Open(home, envConfig);

            /*
             * Open recno database, write 100000 records into
             * the database and close it.
             */
            RecnoDatabaseConfig recnoConfig =
                new RecnoDatabaseConfig();
            recnoConfig.Creation = CreatePolicy.IF_NEEDED;
            recnoConfig.Env = env;
            // The db needs mpool to open.
            recnoConfig.NoMMap = false;
            recnoDB = RecnoDatabase.Open(dbFileName,
                recnoConfig);
            for (int i = 0; i < 1000; i++)
                recnoDB.Append(new DatabaseEntry(
                    ASCIIEncoding.ASCII.GetBytes("key")));
        }
        public static void Confirm(XmlElement xmlElem,
		    RecnoDatabase recnoDB, bool compulsory)
        {
            DatabaseTest.Confirm(xmlElem, recnoDB, compulsory);

            // Confirm recno database specific field/property
            Configuration.ConfirmInt(xmlElem, "Delimiter",
                recnoDB.RecordDelimiter, compulsory);
            Configuration.ConfirmUint(xmlElem, "Length",
                recnoDB.RecordLength, compulsory);
            Configuration.ConfirmInt(xmlElem, "PadByte",
                recnoDB.RecordPad, compulsory);
            Configuration.ConfirmBool(xmlElem, "Renumber",
                recnoDB.Renumber, compulsory);
            Configuration.ConfirmBool(xmlElem, "Snapshot",
                recnoDB.Snapshot, compulsory);
            Assert.AreEqual(DatabaseType.RECNO, recnoDB.Type);
            string type = recnoDB.Type.ToString();
            Assert.IsNotNull(type);
        }
Exemple #3
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;
 }
Exemple #4
0
 /// <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;
 }
 public void PutRecordCase1(RecnoDatabase db, Transaction txn)
 {
     for (int i = 1; i <= 1000; i++)
     {
         if (txn == null)
             db.Put(new DatabaseEntry(
                 BitConverter.GetBytes(i)),
                 new DatabaseEntry(BitConverter.GetBytes(i)));
         else
             db.Put(new DatabaseEntry(
                 BitConverter.GetBytes(i)),
                 new DatabaseEntry(
                 BitConverter.GetBytes(i)), txn);
     }
 }
        public void ModifyRecordsInDB(RecnoDatabase db, 
		    Transaction txn)
        {
            uint[] recnos = new uint[100];

            if (txn == null)
            {
                // Add a lot of records into database.
                for (int i = 0; i < 100; i++)
                    recnos[i] = db.Append(new DatabaseEntry(
                        new byte[10240]));

                // Remove some records from database.
                for (int i = 30; i < 100; i++)
                    db.Delete(new DatabaseEntry(
                        BitConverter.GetBytes(recnos[i])));
            }
            else
            {
                // Add a lot of records into database in txn.
                for (int i = 0; i < 100; i++)
                    recnos[i] = db.Append(new DatabaseEntry(
                        new byte[10240]), txn);

                // Remove some records from database in txn.
                for (int i = 30; i < 100; i++)
                    db.Delete(new DatabaseEntry(
                        BitConverter.GetBytes(recnos[i])), txn);
            }
        }