Class: DbMeta::Oracle::Index

Inherits:
Base
  • Object
show all
Defined in:
lib/db_meta/oracle/types/index.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 = {}) ⇒ Index

Returns a new instance of Index.



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

def initialize(args={})
  super(args)

  @extract_type = :embedded
  @columns = []
end

Instance Attribute Details

#index_typeObject (readonly)

Returns the value of attribute index_type.



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

def index_type
  @index_type
end

#table_nameObject (readonly)

Returns the value of attribute table_name.



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

def table_name
  @table_name
end

#tablespaceObject (readonly)

Returns the value of attribute tablespace.



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

def tablespace
  @tablespace
end

#uniquenessObject (readonly)

Returns the value of attribute uniqueness.



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

def uniqueness
  @uniqueness
end

Instance Method Details

#extract(args = {}) ⇒ Object



37
38
39
# File 'lib/db_meta/oracle/types/index.rb', line 37

def extract(args={})
  "CREATE#{ @uniqueness == 'UNIQUE' ? ' UNIQUE' : nil } INDEX #{@name} ON #{@table_name}(#{@columns.join(', ')});"
end

#fetch(args = {}) ⇒ Object



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/db_meta/oracle/types/index.rb', line 15

def fetch(args={})
  connection = Connection.instance.get
  cursor = connection.exec("select index_type, table_name, uniqueness, tablespace_name from user_indexes where index_name = '#{@name}'")
  while row = cursor.fetch()
    @index_type = row[0].to_s
    @table_name = row[1].to_s
    @uniqueness = row[2].to_s
    @tablespace = row[3].to_s
  end
  cursor.close

  # involved columns
  cursor = connection.exec("select column_name from user_ind_columns where index_name = '#{@name}' order by column_position")
  while row = cursor.fetch()
    @columns << row[0].to_s
  end
  cursor.close

ensure
  connection.logoff
end