summaryrefslogtreecommitdiff
path: root/lang/csharp/src/BTreeDatabase.cs
diff options
context:
space:
mode:
Diffstat (limited to 'lang/csharp/src/BTreeDatabase.cs')
-rw-r--r--lang/csharp/src/BTreeDatabase.cs181
1 files changed, 146 insertions, 35 deletions
diff --git a/lang/csharp/src/BTreeDatabase.cs b/lang/csharp/src/BTreeDatabase.cs
index 185b3515..7eab8769 100644
--- a/lang/csharp/src/BTreeDatabase.cs
+++ b/lang/csharp/src/BTreeDatabase.cs
@@ -1,7 +1,7 @@
/*-
* See the file LICENSE for redistribution information.
*
- * Copyright (c) 2009, 2012 Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2009, 2015 Oracle and/or its affiliates. All rights reserved.
*
*/
using System;
@@ -19,12 +19,16 @@ namespace BerkeleyDB {
private BTreeCompressDelegate compressHandler;
private BTreeDecompressDelegate decompressHandler;
private EntryComparisonDelegate compareHandler, dupCompareHandler;
- private EntryPrefixComparisonDelegate prefixCompareHandler;
+ private EntryPrefixComparisonDelegate prefixCompareHandler;
+ private PartitionDelegate partitionHandler;
private BDB_CompareDelegate doCompareRef;
private BDB_CompareDelegate doDupCompareRef;
private BDB_PrefixCompareDelegate doPrefixCompareRef;
private BDB_CompressDelegate doCompressRef;
private BDB_DecompressDelegate doDecompressRef;
+ private BDB_PartitionDelegate doPartitionRef;
+ private DatabaseEntry[] partitionKeys;
+ private uint nparts;
#region Constructors
private BTreeDatabase(DatabaseEnvironment env, uint flags)
@@ -34,11 +38,17 @@ namespace BerkeleyDB {
private void Config(BTreeDatabaseConfig cfg) {
base.Config(cfg);
/*
- * Database.Config calls set_flags, but that doesn't get the BTree
+ * Database.Config calls set_flags, but that does not get the BTree
* specific flags. No harm in calling it again.
*/
db.set_flags(cfg.flags);
-
+
+ if (cfg.BlobDir != null && cfg.Env == null)
+ db.set_blob_dir(cfg.BlobDir);
+
+ if (cfg.blobThresholdIsSet)
+ db.set_blob_threshold(cfg.BlobThreshold, 0);
+
if (cfg.BTreeCompare != null)
Compare = cfg.BTreeCompare;
@@ -65,6 +75,25 @@ namespace BerkeleyDB {
doDecompressRef = new BDB_DecompressDelegate(doDecompress);
db.set_bt_compress(doCompressRef, doDecompressRef);
}
+
+ if (cfg.partitionIsSet) {
+ nparts = cfg.NParts;
+ Partition = cfg.Partition;
+ if (Partition == null)
+ doPartitionRef = null;
+ else
+ doPartitionRef = new BDB_PartitionDelegate(doPartition);
+ partitionKeys = cfg.PartitionKeys;
+ IntPtr[] ptrs = null;
+ if (partitionKeys != null) {
+ int size = (int)nparts - 1;
+ ptrs = new IntPtr[size];
+ for (int i = 0; i < size; i++)
+ ptrs[i] = DBT.getCPtr(
+ DatabaseEntry.getDBT(partitionKeys[i])).Handle;
+ }
+ db.set_partition(nparts, ptrs, doPartitionRef);
+ }
}
/// <summary>
@@ -80,13 +109,13 @@ namespace BerkeleyDB {
/// </para>
/// <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
+ /// 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 that will be used to back the
+ /// 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>
@@ -110,18 +139,18 @@ namespace BerkeleyDB {
/// 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
+ /// 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
- /// will be implicitly transaction protected. Note that transactionally
- /// protected operations on a datbase object requires the object itself
+ /// 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 that will be used to back the
+ /// The name of an underlying file that 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>
@@ -150,15 +179,15 @@ namespace BerkeleyDB {
/// </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
+ /// <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 that will be used to back the
+ /// 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>
@@ -190,20 +219,20 @@ namespace BerkeleyDB {
/// 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
+ /// 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 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
+ /// <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 that will be used to back the
+ /// 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>
@@ -235,10 +264,13 @@ namespace BerkeleyDB {
#endregion Constructors
#region Callbacks
- private static int doCompare(IntPtr dbp, IntPtr dbtp1, IntPtr dbtp2) {
+ private static int doCompare(IntPtr dbp,
+ IntPtr dbtp1, IntPtr dbtp2, IntPtr locp) {
DB db = new DB(dbp, false);
DBT dbt1 = new DBT(dbtp1, false);
DBT dbt2 = new DBT(dbtp2, false);
+ if (locp != IntPtr.Zero)
+ locp = IntPtr.Zero;
BTreeDatabase btdb = (BTreeDatabase)(db.api_internal);
return btdb.Compare(
DatabaseEntry.fromDBT(dbt1), DatabaseEntry.fromDBT(dbt2));
@@ -298,15 +330,23 @@ namespace BerkeleyDB {
}
}
private static int doDupCompare(
- IntPtr dbp, IntPtr dbt1p, IntPtr dbt2p) {
+ IntPtr dbp, IntPtr dbt1p, IntPtr dbt2p, IntPtr locp) {
DB db = new DB(dbp, false);
DBT dbt1 = new DBT(dbt1p, false);
DBT dbt2 = new DBT(dbt2p, false);
+ if (locp != IntPtr.Zero)
+ locp = IntPtr.Zero;
BTreeDatabase btdb = (BTreeDatabase)(db.api_internal);
return btdb.DupCompare(
DatabaseEntry.fromDBT(dbt1), DatabaseEntry.fromDBT(dbt2));
}
+ private static uint doPartition(IntPtr dbp, IntPtr dbtp) {
+ DB db = new DB(dbp, false);
+ DatabaseEntry dbt = DatabaseEntry.fromDBT(new DBT(dbtp, false));
+ BTreeDatabase btdb = (BTreeDatabase)(db.api_internal);
+ return btdb.Partition(dbt);
+ }
private static uint doPrefixCompare(
IntPtr dbp, IntPtr dbtp1, IntPtr dbtp2) {
DB db = new DB(dbp, false);
@@ -321,6 +361,44 @@ namespace BerkeleyDB {
#region Properties
// Sorted alpha by property name
/// <summary>
+ /// The path of the directory where blobs are stored.
+ /// </summary>
+ public string BlobDir {
+ get {
+ string dir;
+ db.get_blob_dir(out dir);
+ return dir;
+ }
+ }
+
+ internal string BlobSubDir {
+ get {
+ string dir;
+ db.get_blob_sub_dir(out dir);
+ return dir;
+ }
+ }
+
+ /// <summary>
+ /// The threshold value in bytes beyond which data items are stored as
+ /// blobs.
+ /// <para>
+ /// Any data item that is equal to or larger in size than the
+ /// threshold value is automatically stored as a blob.
+ /// </para>
+ /// <para>
+ /// A value of 0 indicates that blobs are not used by the database.
+ /// </para>
+ /// </summary>
+ public uint BlobThreshold {
+ get {
+ uint ret = 0;
+ db.get_blob_threshold(ref ret);
+ return ret;
+ }
+ }
+
+ /// <summary>
/// The Btree key comparison function. The comparison function is called
/// whenever it is necessary to compare a key specified by the
/// application with a key currently stored in the tree.
@@ -376,7 +454,7 @@ namespace BerkeleyDB {
}
/// <summary>
/// Whether the insertion of duplicate data items in the database is
- /// permitted, and whether duplicates items are sorted.
+ /// permitted, and whether duplicate items are sorted.
/// </summary>
public DuplicatesPolicy Duplicates {
get {
@@ -404,6 +482,39 @@ namespace BerkeleyDB {
}
/// <summary>
+ /// Return the number of partitions created in the database.
+ /// </summary>
+ public uint NParts {
+ get {
+ db.get_partition_parts(ref nparts);
+ return nparts;
+ }
+ private set { nparts = value; }
+ }
+
+ /// <summary>
+ /// Return the application-specified partitioning function.
+ /// </summary>
+ public PartitionDelegate Partition {
+ get { return partitionHandler; }
+ private set { partitionHandler = value; }
+ }
+
+ /// <summary>
+ /// Return an array of type DatabaseEntry where each array entry
+ /// contains the range of keys contained in one of the database's
+ /// partitions. The array contains the information for the entire
+ /// database.
+ /// </summary>
+ public DatabaseEntry[] PartitionKeys {
+ get {
+ partitionKeys = db.get_partition_keys();
+ return partitionKeys;
+ }
+ private set { partitionKeys = value; }
+ }
+
+ /// <summary>
/// The Btree prefix function. The prefix function is used to determine
/// the amount by which keys stored on the Btree internal pages can be
/// safely truncated without losing their uniqueness.
@@ -436,7 +547,7 @@ namespace BerkeleyDB {
}
/// <summary>
- /// If false, empty pages will not be coalesced into higher-level pages.
+ /// If false, empty pages are not coalesced into higher-level pages.
/// </summary>
public bool ReverseSplit {
get {
@@ -457,8 +568,8 @@ namespace BerkeleyDB {
/// </summary>
/// <remarks>
/// If the operation occurs in a transactional database, the operation
- /// will be implicitly transaction protected using multiple
- /// transactions. These transactions will be periodically committed to
+ /// is implicitly transaction protected using multiple
+ /// transactions. These transactions are periodically committed to
/// avoid locking large sections of the tree. Any deadlocks encountered
/// cause the compaction operation to be retried from the point of the
/// last transaction commit.
@@ -480,8 +591,8 @@ namespace BerkeleyDB {
/// </para>
/// <para>
/// If <paramref name="txn"/> is null, but the operation occurs in a
- /// transactional database, the operation will be implicitly transaction
- /// protected using multiple transactions. These transactions will be
+ /// transactional database, the operation is implicitly transaction
+ /// protected using multiple transactions. These transactions are
/// periodically committed to avoid locking large sections of the tree.
/// Any deadlocks encountered cause the compaction operation to be
/// retried from the point of the last transaction commit.
@@ -610,7 +721,7 @@ namespace BerkeleyDB {
/// </param>
/// <param name="isoDegree">
/// The level of isolation for database reads.
- /// <see cref="Isolation.DEGREE_ONE"/> will be silently ignored for
+ /// <see cref="Isolation.DEGREE_ONE"/> is silently ignored for
/// databases which did not specify
/// <see cref="DatabaseConfig.ReadUncommitted"/>.
/// </param>
@@ -714,7 +825,7 @@ namespace BerkeleyDB {
/// </param>
/// <param name="BufferSize">
/// The initial size of the buffer to fill with duplicate data items. If
- /// the buffer is not large enough, it will be automatically resized.
+ /// the buffer is not large enough, it is automatically resized.
/// </param>
/// <exception cref="NotFoundException">
/// A NotFoundException is thrown if <paramref name="recno"/> is not in
@@ -738,7 +849,7 @@ namespace BerkeleyDB {
/// </param>
/// <param name="BufferSize">
/// The initial size of the buffer to fill with duplicate data items. If
- /// the buffer is not large enough, it will be automatically resized.
+ /// the buffer is not large enough, it is automatically resized.
/// </param>
/// <param name="txn">
/// <paramref name="txn"/> is a Transaction object returned from
@@ -769,7 +880,7 @@ namespace BerkeleyDB {
/// </param>
/// <param name="BufferSize">
/// The initial size of the buffer to fill with duplicate data items. If
- /// the buffer is not large enough, it will be automatically resized.
+ /// the buffer is not large enough, it is automatically resized.
/// </param>
/// <param name="txn">
/// <paramref name="txn"/> is a Transaction object returned from
@@ -918,7 +1029,7 @@ namespace BerkeleyDB {
/// </param>
/// <param name="isoDegree">
/// The level of isolation for database reads.
- /// <see cref="Isolation.DEGREE_ONE"/> will be silently ignored for
+ /// <see cref="Isolation.DEGREE_ONE"/> is silently ignored for
/// databases which did not specify
/// <see cref="DatabaseConfig.ReadUncommitted"/>.
/// </param>