Class: Rod::Berkeley::Sequence

Inherits:
Object
  • Object
show all
Defined in:
lib/rod/berkeley/sequence.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(database) ⇒ Sequence

Initializes the sequence as stored within the given database.



9
10
11
12
# File 'lib/rod/berkeley/sequence.rb', line 9

def initialize(database)
  @database = database
  @opened = false
end

Instance Attribute Details

#databaseObject (readonly)

The database of the sequence.



5
6
7
# File 'lib/rod/berkeley/sequence.rb', line 5

def database
  @database
end

Instance Method Details

#closeObject

Closes the sequence.



36
37
38
39
# File 'lib/rod/berkeley/sequence.rb', line 36

def close
  _close
  @opened = false
end

#next(transaction = nil, options = {}) ⇒ Object

Get the next value of the sequence. The operation might be protected by the transaction given.

The following options are supported (see the Berkeley DB documentation for full description of the flags):

  • :delta - the delta used to compute the next value of the sequence

  • +:no_sync - do not flush synchronously to the log (ACI without D), BDB: DB_TXN_NOSYNC



54
55
56
57
# File 'lib/rod/berkeley/sequence.rb', line 54

def next(transaction=nil,options={})
  delta = options.delete(:delta) || 1
  _next(transaction,delta,options)
end

#open(key, transaction = nil, options = {}) ⇒ Object

Opens the Berkeley DB sequence for the given key with given transaction.

The following options are supported (see the Berkeley DB documentation for full description of the flags):

  • +:cache_size - the number of cached values (default to 1)

  • +:create - create the sequence if it doesn’t exist, BDB: DB_CREATE

  • +:create_exclusive - check if the sequence exists when creating it, if it exists - raise an error, BDB: DB_EXCL

  • :threads allow multiple threads within one process to use the sequence, BDB: DB_THREAD



24
25
26
27
28
29
30
31
32
33
# File 'lib/rod/berkeley/sequence.rb', line 24

def open(key,transaction=nil,options={})
  if opened?
    raise DatabaseError.new("The seqence associated with the #{@database} is already opened.")
  end
  if String === key
    _open_string(key,transaction,options)
  else
    raise DatabaseError.new("#{key.class} type not supported for sequence keys.")
  end
end

#opened?Boolean

Returns true if the database is opened.

Returns:

  • (Boolean)


42
43
44
# File 'lib/rod/berkeley/sequence.rb', line 42

def opened?
  @opened
end