/*-
* See the file LICENSE for redistribution information.
*
* Copyright (c) 2009 Oracle. All rights reserved.
*
*/
using System;
using System.Collections.Generic;
using System.Text;
using BerkeleyDB.Internal;
namespace BerkeleyDB {
///
/// A class representing a RecnoDatabase. The Recno format supports fixed-
/// or variable-length records, accessed sequentially or by logical record
/// number, and optionally backed by a flat text file.
///
public class SecondaryRecnoDatabase : SecondaryDatabase {
#region Constructors
internal SecondaryRecnoDatabase(DatabaseEnvironment env, uint flags)
: base(env, flags) { }
private void Config(SecondaryRecnoDatabaseConfig cfg) {
base.Config((SecondaryDatabaseConfig)cfg);
db.set_flags(cfg.flags);
if (cfg.delimiterIsSet)
db.set_re_delim(cfg.Delimiter);
if (cfg.lengthIsSet)
db.set_re_len(cfg.Length);
if (cfg.padIsSet)
db.set_re_pad(cfg.PadByte);
if (cfg.BackingFile != null)
db.set_re_source(cfg.BackingFile);
}
///
/// Instantiate a new SecondaryRecnoDatabase object, open the
/// database represented by and associate
/// the database with the
/// primary index.
///
///
///
/// If 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.
///
///
/// If 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.
///
///
///
/// 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.
///
/// The database's configuration
/// A new, open database object
public static SecondaryRecnoDatabase Open(
string Filename, SecondaryRecnoDatabaseConfig cfg) {
return Open(Filename, null, cfg, null);
}
///
/// Instantiate a new SecondaryRecnoDatabase object, open the
/// database represented by and associate
/// the database with the
/// primary index.
///
///
///
/// If both and
/// 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
/// is null and
/// is non-null, the database can be
/// opened by other threads of control and will be replicated to client
/// sites in any replication group.
///
///
/// If 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.
///
///
///
/// 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.
///
///
/// 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.
///
/// The database's configuration
/// A new, open database object
public static SecondaryRecnoDatabase Open(string Filename,
string DatabaseName, SecondaryRecnoDatabaseConfig cfg) {
return Open(Filename, DatabaseName, cfg, null);
}
///
/// Instantiate a new SecondaryRecnoDatabase object, open the
/// database represented by and associate
/// the database with the
/// primary index.
///
///
///
/// If 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.
///
///
/// If is null, but
/// 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.
///
///
///
/// 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.
///
/// The database's configuration
///
/// If the operation is part of an application-specified transaction,
/// is a Transaction object returned from
/// ; if
/// the operation is part of a Berkeley DB Concurrent Data Store group,
/// is a handle returned from
/// ; otherwise null.
///
/// A new, open database object
public static SecondaryRecnoDatabase Open(string Filename,
SecondaryRecnoDatabaseConfig cfg, Transaction txn) {
return Open(Filename, null, cfg, txn);
}
///
/// Instantiate a new SecondaryRecnoDatabase object, open the
/// database represented by and associate
/// the database with the
/// primary index.
///
///
///
/// If both and
/// 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
/// is null and
/// is non-null, the database can be
/// opened by other threads of control and will be replicated to client
/// sites in any replication group.
///
///
/// If is null, but
/// 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.
///
///
///
/// 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.
///
///
/// 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.
///
/// The database's configuration
///
/// If the operation is part of an application-specified transaction,
/// is a Transaction object returned from
/// ; if
/// the operation is part of a Berkeley DB Concurrent Data Store group,
/// is a handle returned from
/// ; otherwise null.
///
/// A new, open database object
public static SecondaryRecnoDatabase Open(string Filename,
string DatabaseName,
SecondaryRecnoDatabaseConfig cfg, Transaction txn) {
SecondaryRecnoDatabase ret = new SecondaryRecnoDatabase(cfg.Env, 0);
ret.Config(cfg);
ret.db.open(Transaction.getDB_TXN(txn), Filename,
DatabaseName, cfg.DbType.getDBTYPE(), cfg.openFlags, 0);
ret.isOpen = true;
ret.doAssocRef =
new BDB_AssociateDelegate(SecondaryDatabase.doAssociate);
cfg.Primary.db.associate(Transaction.getDB_TXN(null),
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;
}
#endregion Constructors
#region Properties
///
/// If true, the logical record numbers are mutable, and change as
/// records are added to and deleted from the database.
///
public bool Renumber {
get {
uint flags = 0;
db.get_flags(ref flags);
return (flags & DbConstants.DB_RENUMBER) != 0;
}
}
///
/// If true, any file will be read in its
/// entirety when is called. If false,
/// may be read lazily.
///
public bool Snapshot {
get {
uint flags = 0;
db.get_flags(ref flags);
return (flags & DbConstants.DB_SNAPSHOT) != 0;
}
}
///
/// The delimiting byte used to mark the end of a record in
/// .
///
public int Delimiter {
get {
int ret = 0;
db.get_re_delim(ref ret);
return ret;
}
}
///
/// If using fixed-length, not byte-delimited records, the length of the
/// records.
///
public uint Length {
get {
uint ret = 0;
db.get_re_len(ref ret);
return ret;
}
}
///
/// The padding character for short, fixed-length records.
///
public int PadByte {
get {
int ret = 0;
db.get_re_pad(ref ret);
return ret;
}
}
///
/// The underlying source file for the Recno access method.
///
public string BackingFile {
get {
string ret = "";
db.get_re_source(ref ret);
return ret;
}
}
#endregion Properties
}
}