Class: Embulk::ParserPlugin::JavaAdapter

Inherits:
Object
  • Object
show all
Includes:
Java::ParserPlugin
Defined in:
embulk-core/src/main/ruby/embulk/parser_plugin.rb

Instance Method Summary collapse

Constructor Details

#initialize(ruby_class) ⇒ JavaAdapter

Returns a new instance of JavaAdapter



36
37
38
# File 'embulk-core/src/main/ruby/embulk/parser_plugin.rb', line 36

def initialize(ruby_class)
  @ruby_class = ruby_class
end

Instance Method Details

#run(java_task_source, java_schema, java_file_input, java_output) ⇒ Object



50
51
52
53
54
55
56
57
58
59
60
61
62
# File 'embulk-core/src/main/ruby/embulk/parser_plugin.rb', line 50

def run(java_task_source, java_schema, java_file_input, java_output)
  task_source = DataSource.from_java(java_task_source)
  schema = Schema.from_java(java_schema)
  file_input = FileInput.new(java_file_input)
  page_builder = PageBuilder.new(schema, java_output)
  begin
    @ruby_class.new(task_source, schema, page_builder).run(file_input)
    nil
  ensure
    page_builder.close
    # FileInput is closed by FileInputRunner
  end
end

#transaction(java_config, java_control) ⇒ Object



40
41
42
43
44
45
46
47
48
# File 'embulk-core/src/main/ruby/embulk/parser_plugin.rb', line 40

def transaction(java_config, java_control)
  config = DataSource.from_java(java_config)
  @ruby_class.transaction(config) do |task_source_hash,columns|
    java_task_source = DataSource.from_ruby_hash(task_source_hash).to_java
    java_schema = Schema.new(columns).to_java
    java_control.run(java_task_source, java_schema)
  end
  nil
end