Class: Mkxms::Mssql::Trigger
- Inherits:
-
Object
- Object
- Mkxms::Mssql::Trigger
- Extended by:
- Utils::InitializedAttributes
- Includes:
- Dependencies, ExtendedProperties, Property::Hosting, Property::SchemaScoped, Utils::SchemaQualifiedName, XMigra::MSSQLSpecifics
- Defined in:
- lib/mkxms/mssql/dml_trigger_handler.rb
Instance Attribute Summary collapse
-
#clr_impl ⇒ Object
Returns the value of attribute clr_impl.
-
#disabled ⇒ Object
Returns the value of attribute disabled.
-
#execute_as ⇒ Object
Returns the value of attribute execute_as.
-
#name ⇒ Object
Returns the value of attribute name.
-
#not_replicable ⇒ Object
Returns the value of attribute not_replicable.
-
#schema ⇒ Object
Returns the value of attribute schema.
-
#table ⇒ Object
Returns the value of attribute table.
-
#timing ⇒ Object
Returns the value of attribute timing.
Instance Method Summary collapse
- #clr_definition ⇒ Object
-
#initialize(schema, name, timing, execute_as: nil, disabled: false, not_replicable: false) ⇒ Trigger
constructor
A new instance of Trigger.
- #to_sql ⇒ Object
Methods included from Utils::InitializedAttributes
Methods included from Utils::SchemaQualifiedName
Methods included from Dependencies
Methods included from ExtendedProperties
Methods included from Property::Hosting
Methods included from Property::SchemaScoped
#property_subject_identifiers, #subitem_extended_properties_sql
Constructor Details
#initialize(schema, name, timing, execute_as: nil, disabled: false, not_replicable: false) ⇒ Trigger
Returns a new instance of Trigger.
15 16 17 18 19 20 21 22 |
# File 'lib/mkxms/mssql/dml_trigger_handler.rb', line 15 def initialize(schema, name, timing, execute_as: nil, disabled: false, not_replicable: false) @schema = schema @name = name @timing = timing @execute_as = execute_as @disabled = disabled @not_replicable = not_replicable end |
Instance Attribute Details
#clr_impl ⇒ Object
Returns the value of attribute clr_impl.
24 25 26 |
# File 'lib/mkxms/mssql/dml_trigger_handler.rb', line 24 def clr_impl @clr_impl end |
#disabled ⇒ Object
Returns the value of attribute disabled.
24 25 26 |
# File 'lib/mkxms/mssql/dml_trigger_handler.rb', line 24 def disabled @disabled end |
#execute_as ⇒ Object
Returns the value of attribute execute_as.
24 25 26 |
# File 'lib/mkxms/mssql/dml_trigger_handler.rb', line 24 def execute_as @execute_as end |
#name ⇒ Object
Returns the value of attribute name.
24 25 26 |
# File 'lib/mkxms/mssql/dml_trigger_handler.rb', line 24 def name @name end |
#not_replicable ⇒ Object
Returns the value of attribute not_replicable.
24 25 26 |
# File 'lib/mkxms/mssql/dml_trigger_handler.rb', line 24 def not_replicable @not_replicable end |
#schema ⇒ Object
Returns the value of attribute schema.
24 25 26 |
# File 'lib/mkxms/mssql/dml_trigger_handler.rb', line 24 def schema @schema end |
#table ⇒ Object
Returns the value of attribute table.
24 25 26 |
# File 'lib/mkxms/mssql/dml_trigger_handler.rb', line 24 def table @table end |
#timing ⇒ Object
Returns the value of attribute timing.
24 25 26 |
# File 'lib/mkxms/mssql/dml_trigger_handler.rb', line 24 def timing @timing end |
Instance Method Details
#clr_definition ⇒ Object
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/mkxms/mssql/dml_trigger_handler.rb', line 40 def clr_definition [].tap do |lines| lines << "CREATE TRIGGER #{schema}.#{name}" lines << "ON #{table.qualified_name}" case execute_as when 'OWNER' lines << "WITH EXECUTE AS OWNER" when String lines << "WITH EXECUTE AS #{execute_as.sql_quoted}" end lines << "#{timing} #{events.join(', ')}" lines << "NOT FOR REPLICATION" if not_replicable lines << "AS EXTERNAL NAME #{clr_impl.full_specifier};" end.join("\n") end |
#to_sql ⇒ Object
28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/mkxms/mssql/dml_trigger_handler.rb', line 28 def to_sql def_sql = clr_impl ? clr_definition : definition [def_sql..gsub(/ +\n/, "\n")].tap do |result| unless (ep_sql = extended_properties_sql).empty? result << ep_sql.joined_on_new_lines end if disabled result << "DISABLE TRIGGER #{qualified_name} ON #{table.qualified_name};" end end.join(ddl_block_separator) end |