/*- * 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 { /// /// Configuration properties for a Sequence /// public class SequenceConfig { /// /// The policy for how to handle sequence creation. /// /// /// If the sequence does not already exist and /// is set, the Sequence constructor /// will fail. /// public CreatePolicy Creation; /// /// If true, the object returned by the Sequence constructor will be /// free-threaded; that is, usable by multiple threads within a single /// address space. Note that if multiple threads create multiple /// sequences using the same , that /// database must have also been opened free-threaded. /// public bool FreeThreaded; internal uint openFlags { get { uint flags = 0; flags |= (uint)Creation; flags |= FreeThreaded ? DbConstants.DB_THREAD : 0; return flags; } } /// /// An open database which holds the persistent data for the sequence. /// /// /// /// The database may be of any type, but must not have been configured /// to support duplicate data items. /// /// /// If was opened in a transaction, /// calling Get may result in changes to the sequence object; these /// changes will be automatically committed in a transaction internal to /// the Berkeley DB library. If the thread of control calling Get has an /// active transaction, which holds locks on the same database as the /// one in which the sequence object is stored, it is possible for a /// thread of control calling Get to self-deadlock because the active /// transaction's locks conflict with the internal transaction's locks. /// For this reason, it is often preferable for sequence objects to be /// stored in their own database. /// /// public Database BackingDatabase; private Int64 initVal; internal bool initialValIsSet; /// /// The initial value for a sequence. /// public Int64 InitialValue { get { return initVal; } set { initialValIsSet = true; initVal = value; } } /// /// The record in the database that stores the persistent sequence data. /// public DatabaseEntry key; /// /// If true, the sequence should wrap around when it is incremented /// (decremented) past the specified maximum (minimum) value. /// public bool Wrap; private bool inc = true; /// /// If true, the sequence will be decremented. /// public bool Decrement { get { return !inc; } set { inc = !value; } } /// /// If true, the sequence will be incremented. This is the default. /// public bool Increment { get { return inc; } set { inc = value; } } internal uint flags { get { uint ret = 0; ret |= Wrap ? DbConstants.DB_SEQ_WRAP : 0; ret |= Increment ? DbConstants.DB_SEQ_INC : DbConstants.DB_SEQ_DEC; return ret; } } private int cacheSz; internal bool cacheSzIsSet; /// /// The number of elements cached by a sequence handle. /// public int CacheSize { get { return cacheSz; } set { cacheSz = value; cacheSzIsSet = true; } } private Int64 _min; private Int64 _max; internal bool rangeIsSet; /// /// The minimum value in the sequence. /// public Int64 Min { get { return _min; } } /// /// The maximum value in the sequence. /// public Int64 Max { get { return _max; } } /// /// Set the minimum and maximum values in the sequence. /// /// The maximum value in the sequence. /// The minimum value in the sequence. public void SetRange(Int64 Min, Int64 Max) { _min = Min; _max = Max; rangeIsSet = true; } } }