<?xml version="1.0" encoding="UTF-8"?>
<java version="1.4.0_01" class="java.beans.XMLDecoder">
 <object class="java.util.HashMap">

  <!-- DB2 for z/OS identifies itself as DB2 -->
  <void method="put">
   <string>DB2</string>
   <object id="db2_host_trg_source" class="workbench.db.GetMetaDataSql">
    <void property="baseSql">
     <string>SELECT text FROM sysibm.systriggers</string>
    </void>
    <void property="objectNameField">
     <string>name</string>
    </void>
    <void property="schemaField">
     <string>schema</string>
    </void>
    <void property="useUpperCase">
     <boolean>true</boolean>
    </void>
   </object>
  </void>

  <void method="put">
    <string>DB2 UDB for AS/400</string>
    <object idref="db2_host_trg_source"/>
  </void>

  <void method="put">
   <string>DB2/NT</string>
   <object id="db2_trg_source" class="workbench.db.GetMetaDataSql">
    <void property="baseSql">
     <string>SELECT text FROM syscat.triggers</string>
    </void>
    <void property="objectNameField">
     <string>trigname</string>
    </void>
    <void property="schemaField">
     <string>trigschema</string>
    </void>
    <void property="useUpperCase">
     <boolean>true</boolean>
    </void>
   </object>
  </void>

  <void method="put">
   <string>DB2/LINUX</string>
   <object idref="db2_trg_source"/>
  </void>

  <void method="put">
   <string>DB2/NT64</string>
   <object idref="db2_trg_source"/>
  </void>

  <void method="put">
   <string>DB2/AIX64</string>
   <object idref="db2_trg_source"/>
  </void>

  <void method="put">
   <string>Oracle</string>
   <object id="ora_trg_source" class="workbench.db.GetMetaDataSql">
    <void property="baseSql">
     <string>SELECT 'CREATE OR REPLACE TRIGGER '|| description || decode(when_clause,NULL,'','WHEN ('|| when_clause ||')'||chr(10)), trigger_body FROM all_triggers</string>
    </void>
    <void property="objectNameField">
     <string>trigger_name</string>
    </void>
    <void property="schemaField">
     <string>owner</string>
    </void>
    <void property="useUpperCase">
     <boolean>true</boolean>
    </void>
   </object>
  </void>

  <void method="put">
   <string>Oracle8</string>
   <object idref="ora_trg_source"/>
  </void>

  <void method="put">
   <string>Microsoft SQL Server</string>
   <object class="workbench.db.GetMetaDataSql">
    <void property="baseSql">
     <string>exec sp_helptext</string>
    </void>
    <void property="isProcedureCall">
     <boolean>true</boolean>
    </void>
    <void property="objectNameArgumentPos">
     <int>1</int>
    </void>
   </object>
  </void>

  <void method="put">
   <string>PostgreSQL</string>
   <object class="workbench.db.GetMetaDataSql">
    <void property="baseObjectNameField">
     <string>tbl.relname</string>
    </void>
    <void property="baseSql">
     <string>SELECT replace(replace(pg_get_triggerdef(trg.oid), ' ON ', chr(10)||'  ON '), ' EXECUTE ', chr(10)||'  EXECUTE ')
       || ';' || chr(10)
       || chr(10) 
       || case
            when obj_description(trg.oid)::text is not null then
              'COMMENT ON '||trg.tgname||' ON '||tbl.relname||' IS '||quote_literal(obj_description(trg.oid))||';'||chr(10)
            else ''
          end
       || chr(10)
       || '---[ ' || src.proname || ' ]---' || chr(10)
       || 'CREATE OR REPLACE FUNCTION '||src.proname||'() RETURNS TRIGGER AS'||chr(10)||'$$'||chr(10)
       || src.prosrc
       || '$$'||chr(10)||'language '''||l.lanname||''''
from pg_trigger trg, pg_class tbl, pg_proc src, pg_language l
where trg.tgrelid = tbl.oid
 AND l.oid = src.prolang
 AND trg.tgfoid = src.oid
</string>
    </void>
    <void property="objectNameField">
     <string>trg.tgname</string>
    </void>
   </object>
  </void>

  <void method="put">
   <string>Microsoft SQL Server</string>
   <object class="workbench.db.GetMetaDataSql">
    <void property="baseSql">
     <string>exec sp_helptext</string>
    </void>
    <void property="isProcedureCall">
     <boolean>true</boolean>
    </void>
    <void property="objectNameArgumentPos">
     <int>1</int>
    </void>
   </object>
  </void>

  <void method="put">
   <string>MySQL</string>
   <object class="workbench.db.GetMetaDataSql">
    <void property="baseObjectNameField">
     <string>event_object_table</string>
    </void>
    <void property="baseSql">
     <string>SELECT concat('CREATE TRIGGER ',trigger_name, ' ', action_timing, ' ', event_manipulation, '\n  ON ', event_object_table, '\n  FOR EACH ROW', action_statement)
     FROM information_schema.triggers</string>
    </void>
    <void property="objectNameField">
     <string>trigger_name</string>
    </void>
    <void property="schemaField">
     <string>trigger_schema</string>
    </void>
   </object>
  </void>

  <void method="put">
   <string>H2</string>
   <object class="workbench.db.GetMetaDataSql">
    <void property="baseSql">
     <string>SELECT 'CREATE TRIGGER '||trigger_name||
        case before when 'true' then ' BEFORE ' else ' AFTER ' end||
        trigger_type||' ON '||table_name||char(10)||'  FOR EACH ROW CALL "'||java_class||'";'
        from information_schema.triggers
      </string>
    </void>
    <void property="objectNameField">
     <string>trigger_name</string>
    </void>
   </object>
  </void>

  <void method="put">
   <string>HSQL Database Engine 2.0</string>
   <object class="workbench.db.GetMetaDataSql">
    <void property="baseSql">
     <string>SELECT 'CREATE TRIGGER '||trigger_name||'\n'||
       action_timing||' '||event_manipulation||' ON '||event_object_table||'\n'||
       case
          when action_reference_new_row is not null or action_reference_old_row is not null then
          '\nREFERENCING ' ||
            CASE when action_reference_old_row is not null then 'OLD ROW AS '|| action_reference_old_row || ' '
            else '' END ||
            CASE when action_reference_new_row is not null then 'NEW ROW AS '|| action_reference_new_row
            else '' end
          else ''
       end||
       case
          when action_reference_new_table is not null or action_reference_old_table is not null then
          '\nREFERENCING ' ||
            CASE when action_reference_old_table is not null then 'OLD TABLE AS '|| action_reference_old_table || ' '
            else '' END ||
            CASE when action_reference_new_table is not null then 'NEW TABLE AS '|| action_reference_new_table
            else '' end
          else ''
       end||'\n'||
       trim(case
         when action_orientation = 'ROW' then 'FOR EACH ROW '
         else 'FOR EACH STATEMENT '
       end)||
       case
         when action_condition is not null then ' WHEN ('||action_condition||')'
         else ''
       end||'\n'||
       trim(action_statement)
       FROM information_schema.triggers
</string>
    </void>
    <void property="objectNameField">
     <string>trigger_name</string>
    </void>
   </object>
  </void>

  <void method="put">
   <string>HSQL Database Engine</string>
   <object class="workbench.db.GetMetaDataSql">
    <void property="baseSql">
     <string>SELECT description FROM information_schema.system_triggers</string>
    </void>
    <void property="objectNameField">
     <string>trigger_name</string>
    </void>
   </object>
  </void>

  <void method="put">
   <string>FirstSQL/J</string>
   <object class="workbench.db.GetMetaDataSql">
    <void property="baseSql">
     <string>SELECT 'CREATE TRIGGER ON '||table_name||'\n'||mode||' '||command||'\nWITH '||class_name||'.'||class_method||';\n\n'
    from definition_schema.systriggers
  </string>
    </void>
    <void property="objectNameField">
     <string>class_name||'.'||class_method</string>
    </void>
   </object>
  </void>

  <void method="put">
    <string>Adaptive Server Enterprise</string>
   <object id="ase_trg_source" class="workbench.db.GetMetaDataSql">
    <void property="baseSql">
     <string>select syscomments.text
 from sysobjects, syscomments
 where sysobjects.id = syscomments.id
and  sysobjects.type = &apos;TR&apos;</string>
    </void>
    <void property="objectNameField">
     <string>sysobjects.name</string>
    </void>
    <void property="orderBy">
     <string> order by syscomments.colid</string>
    </void>
   </object>
  </void>

  <void method="put">
    <string>Adaptive Server Anywhere</string>
    <object idref="ase_trg_source"/>
  </void>

  <void method="put">
   <string>Firebird</string>
   <object class="workbench.db.GetMetaDataSql">
    <void property="baseSql">
     <string>SELECT 'CREATE TRIGGER '||trim(rdb$trigger_name)||'\n'||
          trim(case
            when mod(rdb$trigger_type, 2) = 0 then 'AFTER'
          else 'BEFORE'
          END) ||' '||
          trim(case bin_and(rdb$trigger_type + 1, 254)
             when  2 then 'INSERT'
             when  4 THEN 'UPDATE'
             when  6 then 'DELETE'
             when  18 then 'INSERT OR UPDATE'
             when  26 then 'INSERT OR DELETE'
             when  12 then 'UPDATE OR INSERT'
             when  28 then 'UPDATE OR DELETE'
             when  14 then 'DELETE OR INSERT'
             when  22 then 'DELETE OR UPDATE'
             when  114 then 'INSERT OR UPDATE OR DELETE'
             when  60 then 'UPDATE OR DELETE OR INSERT'
             when  78 then 'DELETE OR INSERT OR UPDATE'
          end)||' \n'||rdb$trigger_source
          FROM rdb$triggers</string>
    </void>
    <void property="objectNameField">
     <string>rdb$trigger_name</string>
    </void>
    <void property="useUpperCase">
     <boolean>true</boolean>
    </void>
    <void property="schemaField">
     <string>RDB$OWNER_NAME</string>
    </void>
   </object>
  </void>

  <void method="put">
   <string>Apache Derby</string>
   <object id="id_derby_trg" class="workbench.db.GetMetaDataSql">
    <void property="baseSql">
     <string>
SELECT 'CREATE TRIGGER ' || trg.triggername || '\n  '
       || case when trg.type ='A' then 'AFTER'
          else 'BEFORE' end
       || ' '
       || case when trg.event = 'D' then 'DELETE'
            else case when trg.event = 'I' then 'INSERT'
                 else case when trg.event = 'U' THEN 'UPDATE' end
            end
          end
       || case when trg.referencedcolumns is not null then ' OF ' || trg.referencedcolumns else '' end
       || ' ON ' || t.tablename || '\n'
       || case when trg.referencingnew = 'true' then '  REFERENCING NEW AS ' || trg.newreferencingname
               when trg.referencingold = 'true' then '  REFERENCING OLD AS ' || trg.oldreferencingname
               when trg.referencingold = 'false' AND trg.referencingnew = 'false' THEN ''
          end
       || '\n'
       || case when trg.type = 'S' then '  FOR EACH STATEMENT '
               else '  FOR EACH ROW' end
       || '\n'
       || trg.triggerdefinition
from sys.systriggers trg, sys.systables t, sys.sysschemas s
where trg.tableid = t.tableid
and   t.schemaid = s.schemaid
      </string>
    </void>
    <void property="objectNameField">
     <string>trg.triggername</string>
    </void>
    <void property="useUpperCase">
     <boolean>true</boolean>
    </void>
    <void property="schemaField">
     <string>s.schemaname</string>
    </void>
   </object>
  </void>

  <void method="put">
   <string>Cloudscape</string>
   <object idref="id_derby_trg"/>
  </void>

  <void method="put">
   <string>Informix Dynamic Server</string>
   <object id="list_derby_trg" class="workbench.db.GetMetaDataSql">
    <void property="baseSql">
     <string>
        SELECT b.data, b.seqno
        FROM informix.systriggers t, informix.systrigbody b
        WHERE t.trigid=b.trigid
          AND b.datakey IN ('A', 'D')
      </string>
    </void>
    <void property="objectNameField">
     <string>t.trigname</string>
    </void>
    <void property="orderBy">
     <string>ORDER BY b.seqno</string>
    </void>
   </object>
  </void>

  <void method="put">
   <string>INGRES</string>
   <object class="workbench.db.GetMetaDataSql">
    <void property="baseSql">
     <string>select text_segment from iirules</string>
    </void>
    <void property="objectNameField">
     <string>rule_name</string>
    </void>
    <void property="schemaField">
     <string>rule_owner</string>
    </void>
    <void property="orderBy">
        <string>order by text_sequence</string>
    </void>
    <void property="useUpperCase">
     <boolean>false</boolean>
    </void>
   </object>
  </void>

 </object>
</java>

