Class: JDBCHelper::SequenceWrapper

Inherits:
ObjectWrapper show all
Defined in:
lib/jdbc-helper/wrapper/sequence_wrapper.rb

Overview

conn.sequence(:my_seq).drop!

Instance Attribute Summary

Attributes inherited from ObjectWrapper

#connection, #name

Instance Method Summary collapse

Methods inherited from ObjectWrapper

#initialize

Constructor Details

This class inherits a constructor from JDBCHelper::ObjectWrapper

Instance Method Details

#create!(value = 1, increment_by = 1) ⇒ JDBCHelper::SequenceWrapper

Creates the sequence. Cannot be undone.

Parameters:

  • value (Fixnum) (defaults to: 1)

    Initial value

  • increment_by (Fixnum) (defaults to: 1)

    Increment size for a single nextval call

Returns:



51
52
53
54
55
56
# File 'lib/jdbc-helper/wrapper/sequence_wrapper.rb', line 51

def create! value = 1, increment_by = 1
  create = JDBCHelper::SQL.check(
      "create sequence #{name} start with #{value} increment by #{increment_by}")
  @connection.update(create)
  self
end

#currvalFixnum

Returns the incremented value of the sequence

Returns:

  • (Fixnum)


26
27
28
# File 'lib/jdbc-helper/wrapper/sequence_wrapper.rb', line 26

def currval
  @connection.query("select #{name}.currval from dual")[0][0].to_i
end

#drop!JDBCHelper::SequenceWrapper

Drops the sequence. Cannot be undone.

Returns:



42
43
44
45
# File 'lib/jdbc-helper/wrapper/sequence_wrapper.rb', line 42

def drop!
  @connection.update("drop sequence #{name}")
  self
end

#nextvalFixnum

Increments the sequence and returns the value

Returns:

  • (Fixnum)


20
21
22
# File 'lib/jdbc-helper/wrapper/sequence_wrapper.rb', line 20

def nextval
  @connection.query("select #{name}.nextval from dual")[0][0].to_i
end

#reset!(value = 1, increment_by = 1) ⇒ JDBCHelper::SequenceWrapper

Recreates the sequence. Cannot be undone.

Parameters:

  • value (Fixnum) (defaults to: 1)

    Initial value

  • increment_by (Fixnum) (defaults to: 1)

    Increment size for a single nextval call

Returns:



34
35
36
37
38
# File 'lib/jdbc-helper/wrapper/sequence_wrapper.rb', line 34

def reset! value = 1, increment_by = 1
  drop! rescue nil
  create! value, increment_by
  self
end