Class: DataMetaDom::OraLexer::SqlOutput

Inherits:
Object
  • Object
show all
Defined in:
lib/dataMetaDom/ora.rb

Overview

Encapsulates 4 parts of DDL related SQL output:

  • Creates

  • Drops

  • Linking aka Coupling aka creating Foreign Keys

  • Unlinking aka Uncoupling aka dropping Foreign Keys

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(sqlTargetDir) ⇒ SqlOutput

Creates an instance into the given target directory in which all 4 parts of the SQL DDL process will be created.



91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
# File 'lib/dataMetaDom/ora.rb', line 91

def initialize(sqlTargetDir)
    @selTargetDir = sqlTargetDir
    @create = File.new("#{sqlTargetDir}/DDL-createTables.sql", 'wb')
    @crSeqs = File.new("#{sqlTargetDir}/DDL-createSeqs.sql", 'wb')
    @drSeqs = File.new("#{sqlTargetDir}/DDL-dropSeqs.sql", 'wb')
    @ixes = File.new("#{sqlTargetDir}/DDL-indexes.sql", 'wb')
    @drop = File.new("#{sqlTargetDir}/DDL-drop.sql", 'wb')
    @couple = File.new("#{sqlTargetDir}/DDL-couple.sql", 'wb')
    @uncouple = File.new("#{sqlTargetDir}/DDL-uncouple.sql", 'wb')
    @allScriptFiles = [@create, @drop, @couple, @uncouple, @drSeqs, @crSeqs, @ixes]
    @dropScripts = [@uncouple, @drop]
    @allScriptFiles.each { |f|
        f.puts %q</* Generated by DataMeta DOM Oracle utility
DO NOT EDIT MANUALLY, update the DataMeta DOM source and regen.
*/
>
    }
    @dropScripts.each { |ds|
        ds.puts %q<
/* Oracle does not have this feature: Disable all checks for safe dropping without any errors */

>
    }
end

Instance Attribute Details

#coupleObject (readonly)

Open output file into the couple SQL DDL statements, creating foreign keys



68
69
70
# File 'lib/dataMetaDom/ora.rb', line 68

def couple
  @couple
end

#createObject (readonly)

Open output file into create SQL DDL statements (CREATE TABLE)



58
59
60
# File 'lib/dataMetaDom/ora.rb', line 58

def create
  @create
end

#crSeqsObject (readonly)

Sequences and triggers - create



76
77
78
# File 'lib/dataMetaDom/ora.rb', line 76

def crSeqs
  @crSeqs
end

#dropObject (readonly)

Open output file into drop SQL DDL statements (DROP TABLE)



63
64
65
# File 'lib/dataMetaDom/ora.rb', line 63

def drop
  @drop
end

#drSeqsObject (readonly)

Sequences and triggers - drop



80
81
82
# File 'lib/dataMetaDom/ora.rb', line 80

def drSeqs
  @drSeqs
end

#ixesObject (readonly)

Indexes



84
85
86
# File 'lib/dataMetaDom/ora.rb', line 84

def ixes
  @ixes
end

#uncoupleObject (readonly)

Open output file into the uncouple SQL DDL statements, dropping foreign keys



72
73
74
# File 'lib/dataMetaDom/ora.rb', line 72

def uncouple
  @uncouple
end

Instance Method Details

#closeObject

Safely closes all the output files.



119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
# File 'lib/dataMetaDom/ora.rb', line 119

def close
    @dropScripts.each { |ds|
        ds.puts %q<

/* Placeholder for a drop footer */
>
    }
    @allScriptFiles.each { |f|
        begin
            f.close
        rescue Exception => x;
            $stderr.puts x.message
        end
    }
end