2 * See the file LICENSE for redistribution information.
4 * Copyright (c) 2009, 2012 Oracle and/or its affiliates. All rights reserved.
8 using System.Collections.Generic;
10 using BerkeleyDB.Internal;
12 namespace BerkeleyDB {
14 /// A class for traversing the records of a <see cref="HashDatabase"/>
16 public class HashCursor : Cursor {
17 internal HashCursor(DBC dbc, uint pagesize)
18 : base(dbc, DatabaseType.HASH, pagesize) { }
19 internal HashCursor(DBC dbc, uint pagesize, CachePriority p)
20 : base(dbc, DatabaseType.HASH, pagesize, p) { }
23 /// Create a new cursor that uses the same transaction and locker ID as
24 /// the original cursor.
27 /// This is useful when an application is using locking and requires two
28 /// or more cursors in the same thread of control.
30 /// <param name="keepPosition">
31 /// If true, the newly created cursor is initialized to refer to the
32 /// same position in the database as the original cursor (if any) and
33 /// hold the same locks (if any). If false, or the original cursor does
34 /// not hold a database position and locks, the created cursor is
35 /// uninitialized and will behave like a cursor newly created by
36 /// <see cref="HashDatabase.Cursor"/>.</param>
37 /// <returns>A newly created cursor</returns>
38 public new HashCursor Duplicate(bool keepPosition) {
39 return new HashCursor(
40 dbc.dup(keepPosition ? DbConstants.DB_POSITION : 0), pgsz);
43 /// Insert the data element as a duplicate element of the key to which
44 /// the cursor refers.
46 /// <param name="data">The data element to insert</param>
47 /// <param name="loc">
48 /// Specify whether to insert the data item immediately before or
49 /// immediately after the cursor's current position.
51 public new void Insert(DatabaseEntry data, InsertLocation loc) {
52 base.Insert(data, loc);
55 /// Insert the specified key/data pair into the database, unless a
56 /// key/data pair comparing equally to it already exists in the
59 /// <param name="pair">The key/data pair to be inserted</param>
60 /// <exception cref="KeyExistException">
61 /// Thrown if a matching key/data pair already exists in the database.
63 public new void AddUnique(
64 KeyValuePair<DatabaseEntry, DatabaseEntry> pair) {
68 /// Insert the specified key/data pair into the database.
70 /// <param name="pair">The key/data pair to be inserted</param>
71 /// <param name="loc">
72 /// If the key already exists in the database and no duplicate sort
73 /// function has been specified, specify whether the inserted data item
74 /// is added as the first or the last of the data items for that key.
76 public new void Add(KeyValuePair<DatabaseEntry, DatabaseEntry> pair,