Class: CaTissue::Annotation::IdGenerator

Inherits:
Object
  • Object
show all
Defined in:
lib/catissue/database/annotation/id_generator.rb

Overview

The IdGenerator delegates to the caTissue entity manager to create a new identifier for an annotation.

Instance Method Summary collapse

Constructor Details

#initializeIdGenerator

Returns a new instance of IdGenerator.



7
8
9
# File 'lib/catissue/database/annotation/id_generator.rb', line 7

def initialize
  @executor = CaTissue::Database.current.executor
end

Instance Method Details

#next_identifier(table) ⇒ Integer

Returns a new identifier for the given annotation object.

Parameters:

  • the (String)

    entity table

Returns:

  • (Integer)

    a new identifier for the given annotation object



41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
# File 'lib/catissue/database/annotation/id_generator.rb', line 41

def next_identifier(table)
  # Commented line is broken - see method doc.
  # The caTissue EntityManagerUtil hands out table record ids in the work-around.
  #identifier = EntityManagerUtil.getNextIdentifier(table)
  
  logger.debug { "Work around caTissue DE EntityManagerUtil bug by fetching the maximum #{table} identifier directly from the database..." }
  sql = TABLE_MAX_ID_SQL_TMPL % table
  result = @executor.query(sql).first
  max = result ? result[0].to_i : 0
  next_id = max + 1
  # End of work-around
  
  logger.debug { "Next #{table} identifier is #{next_id}." }
  next_id
end