summaryrefslogtreecommitdiff
path: root/lang/csharp/src/HashCursor.cs
blob: 60334c5522e2b0ba488053f3e977c67442dd4c0f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
/*-
 * See the file LICENSE for redistribution information.
 *
 * Copyright (c) 2009, 2015 Oracle and/or its affiliates.  All rights reserved.
 *
 */
using System;
using System.Collections.Generic;
using System.Text;
using BerkeleyDB.Internal;

namespace BerkeleyDB {
    /// <summary>
    /// A class for traversing the records of a <see cref="HashDatabase"/>
    /// </summary>
    public class HashCursor : Cursor {
        internal HashCursor(DBC dbc, uint pagesize)
            : base(dbc, DatabaseType.HASH, pagesize) { }
        internal HashCursor(DBC dbc, uint pagesize, CachePriority p)
            : base(dbc, DatabaseType.HASH, pagesize, p) { }

        /// <summary>
        /// Create a database stream pointing to a key/value pair where the
        /// data item is a blob.
        /// </summary>
        /// <returns>A newly created database stream</returns>
        /// <exception cref="DatabaseException">
        /// Thrown if the data item is not a blob.
        /// </exception>
        public DatabaseStream DbStream() {
            return DbStream(new DatabaseStreamConfig());
        }

        /// <summary>
        /// Create a database stream pointing to a key/value pair where the
        /// data item is a blob with the given configuration.
        /// </summary>
        /// <param name="cfg">
        /// The configuration properties for the database stream.
        /// </param>
        /// <returns>A newly created database stream</returns>
        /// <exception cref="DatabaseException">
        /// Thrown if the data of the key/value pair it is pointing to is not
        /// a blob.
        /// </exception>
        public DatabaseStream DbStream(DatabaseStreamConfig cfg) {
            return new DatabaseStream(dbc.db_stream(cfg.flags), cfg);
        }

        /// <summary>
        /// Create a new cursor that uses the same transaction and locker ID as
        /// the original cursor.
        /// </summary>
        /// <remarks>
        /// This is useful when an application is using locking and requires two
        /// or more cursors in the same thread of control.
        /// </remarks>
        /// <param name="keepPosition">
        /// If true, the newly created cursor is initialized to refer to the
        /// same position in the database as the original cursor (if any) and
        /// hold the same locks (if any). If false, or if the original cursor does
        /// not hold a database position and locks, the created cursor is
        /// uninitialized and behaves like a cursor newly created by
        /// <see cref="HashDatabase.Cursor"/>.</param>
        /// <returns>A newly created cursor</returns>
        public new HashCursor Duplicate(bool keepPosition) {
            return new HashCursor(
                dbc.dup(keepPosition ? DbConstants.DB_POSITION : 0), pgsz);
        }
        /// <summary>
        /// Insert the data element as a duplicate element of the key to which
        /// the cursor refers.
        /// </summary>
        /// <param name="data">The data element to insert</param>
        /// <param name="loc">
        /// Specify whether to insert the data item immediately before or
        /// immediately after the cursor's current position.
        /// </param>
        public new void Insert(DatabaseEntry data, InsertLocation loc) {
            base.Insert(data, loc);
        }
        /// <summary>
        /// Insert the specified key/data pair into the database, unless a
        /// key/data pair comparing equally to it already exists in the
        /// database.
        /// </summary>
        /// <param name="pair">The key/data pair to be inserted</param>
        /// <exception cref="KeyExistException">
        /// Thrown if a matching key/data pair already exists in the database.
        /// </exception>
        public new void AddUnique(
            KeyValuePair<DatabaseEntry, DatabaseEntry> pair) {
            base.AddUnique(pair);
        }
        /// <summary>
        /// Insert the specified key/data pair into the database.
        /// </summary>
        /// <param name="pair">The key/data pair to be inserted</param>
        /// <param name="loc">
        /// If the key already exists in the database and no duplicate sort
        /// function has been specified, specify whether the inserted data item
        /// is added as the first or the last of the data items for that key. 
        /// </param>
        public new void Add(KeyValuePair<DatabaseEntry, DatabaseEntry> pair,
            InsertLocation loc) {
            base.Add(pair, loc);
        }
    }
}