1/*-
2 * See the file LICENSE for redistribution information.
3 *
4 * Copyright (c) 2009 Oracle.  All rights reserved.
5 *
6 */
7using System;
8using System.Collections.Generic;
9using System.Text;
10using BerkeleyDB.Internal;
11
12namespace BerkeleyDB {
13    /// <summary>
14    /// A class representing configuration parameters for <see cref="Cursor"/>
15    /// </summary>
16    public class CursorConfig {
17        /// <summary>
18        /// The isolation degree the cursor should use.
19        /// </summary>
20        /// <remarks>
21        /// <para>
22        /// <see cref="Isolation.DEGREE_TWO"/> ensures the stability of the
23        /// current data item read by this cursor but permits data read by this
24        /// cursor to be modified or deleted prior to the commit of the
25        /// transaction for this cursor.
26        /// </para>
27		/// <para>
28        /// <see cref="Isolation.DEGREE_ONE"/> allows read operations performed
29        /// by the cursor to return modified but not yet committed data.
30        /// Silently ignored if the <see cref="DatabaseConfig.ReadUncommitted"/>
31        /// was not specified when the underlying database was opened.
32        /// </para>
33        /// </remarks>
34        public Isolation IsolationDegree;
35        /// <summary>
36        /// If true, specify that the cursor will be used to update the
37        /// database. The underlying database environment must have been opened
38        /// with <see cref="DatabaseEnvironmentConfig.UseCDB"/> set.
39        /// </summary>
40        public bool WriteCursor;
41        /// <summary>
42        /// <para>
43        /// Configure a transactional cursor to operate with read-only snapshot
44        /// isolation. For databases with <see cref="DatabaseConfig.UseMVCC"/>
45        /// set, data values will be read as they are when the cursor is opened,
46        /// without taking read locks.
47        /// </para>
48		/// <para>
49        /// This setting implicitly begins a transaction that is committed when
50        /// the cursor is closed.
51        /// </para>
52		/// <para>
53        /// This setting is silently ignored if
54        /// <see cref="DatabaseConfig.UseMVCC"/> is not set on the underlying
55        /// database or if a transaction is supplied to
56        /// <see cref="BaseDatabase.Cursor"/>
57        /// </para>
58        /// </summary>
59        public bool SnapshotIsolation;
60        /// <summary>
61        /// The cache priority for pages referenced by the cursor.
62        /// </summary>
63        /// <remarks>
64        /// The priority of a page biases the replacement algorithm to be more
65        /// or less likely to discard a page when space is needed in the buffer
66        /// pool. The bias is temporary, and pages will eventually be discarded
67        /// if they are not referenced again. The setting is only advisory, and
68        /// does not guarantee pages will be treated in a specific way.
69        /// </remarks>
70        public CachePriority Priority;
71
72        /// <summary>
73        /// Instantiate a new CursorConfig object
74        /// </summary>
75        public CursorConfig() {
76            IsolationDegree = Isolation.DEGREE_THREE;
77        }
78        internal uint flags {
79            get {
80                uint ret = 0;
81                ret |= (IsolationDegree == Isolation.DEGREE_ONE)
82                    ? DbConstants.DB_READ_UNCOMMITTED : 0;
83                ret |= (IsolationDegree == Isolation.DEGREE_TWO)
84                    ? DbConstants.DB_READ_COMMITTED : 0;
85                ret |= (WriteCursor) ? DbConstants.DB_WRITECURSOR : 0;
86                ret |= (SnapshotIsolation) ? DbConstants.DB_TXN_SNAPSHOT : 0;
87
88                return ret;
89            }
90        }
91    }
92}