Class: DbMeta::Oracle::Synonym

Inherits:
Base
  • Object
show all
Defined in:
lib/db_meta/oracle/types/synonym.rb

Constant Summary

Constants inherited from Base

Base::TYPES

Instance Attribute Summary collapse

Attributes inherited from Base

#extract_type, #name, #status, #system_object, #type

Instance Method Summary collapse

Methods inherited from Base

#ddl_drop, from_type, register_type, #system_object?

Methods included from Helper

#block, #create_folder, #pluralize, #remove_folder, #type_sequence, #write_buffer_to_file

Constructor Details

#initialize(args = {}) ⇒ Synonym

Returns a new instance of Synonym.



8
9
10
11
12
# File 'lib/db_meta/oracle/types/synonym.rb', line 8

def initialize(args = {})
  super

  @extract_type = :merged
end

Instance Attribute Details

Returns the value of attribute db_link.



6
7
8
# File 'lib/db_meta/oracle/types/synonym.rb', line 6

def db_link
  @db_link
end

#table_nameObject (readonly)

Returns the value of attribute table_name.



6
7
8
# File 'lib/db_meta/oracle/types/synonym.rb', line 6

def table_name
  @table_name
end

#table_ownerObject (readonly)

Returns the value of attribute table_owner.



6
7
8
# File 'lib/db_meta/oracle/types/synonym.rb', line 6

def table_owner
  @table_owner
end

Instance Method Details

#extract(args = {}) ⇒ Object



28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/db_meta/oracle/types/synonym.rb', line 28

def extract(args = {})
  line = ""
  line << "CREATE OR REPLACE SYNONYM #{@name} FOR "
  line << "#{@table_owner}." if @table_owner.size > 0
  line << @table_name.to_s
  line << "@#{@db_link}" if @db_link.size > 0
  line << ";"

  buffer = []
  buffer << line
  buffer.join("\n")
end

#fetch(args = {}) ⇒ Object



14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/db_meta/oracle/types/synonym.rb', line 14

def fetch(args = {})
  connection_class = args[:connection_class] || Connection
  connection = connection_class.instance.get
  cursor = connection.exec("select table_owner, table_name, db_link from user_synonyms where synonym_name = '#{@name}'")
  while (row = cursor.fetch)
    @table_owner = row[0].to_s
    @table_name = row[1].to_s
    @db_link = row[2].to_s
  end
  cursor.close
ensure
  connection.logoff
end