src-db/database/model/triggers/AD_TASK_TRG2.xml
author Asier Lostalé <asier.lostale@openbravo.com>
Mon, 24 Nov 2008 12:32:14 +0000
changeset 2078 cf88ca44cdd2
parent 1605 8a0fe0193bef
child 2084 5081e251a384
permissions -rw-r--r--
Add infrastructure for triggers soft disable
adrian@94
     1
<?xml version="1.0"?>
adrian@94
     2
  <database name="TRIGGER AD_TASK_TRG2">
adrian@94
     3
    <trigger name="AD_TASK_TRG2" table="AD_TASK" fires="after" insert="true" update="true" delete="true" foreach="row">
gorkaion@239
     4
      <body><![CDATA[
gorkaion@239
     5
adrian@170
     6
adrian@94
     7
adrian@94
     8
adrian@94
     9
/*************************************************************************
adrian@94
    10
* The contents of this file are subject to the Openbravo  Public  License
adrian@94
    11
* Version  1.0  (the  "License"),  being   the  Mozilla   Public  License
adrian@94
    12
* Version 1.1  with a permitted attribution clause; you may not  use this
adrian@94
    13
* file except in compliance with the License. You  may  obtain  a copy of
adrian@94
    14
* the License at http://www.openbravo.com/legal/license.html
adrian@94
    15
* Software distributed under the License  is  distributed  on  an "AS IS"
adrian@94
    16
* basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
adrian@94
    17
* License for the specific  language  governing  rights  and  limitations
adrian@94
    18
* under the License.
adrian@94
    19
* The Original Code is Openbravo ERP.
adrian@94
    20
* The Initial Developer of the Original Code is Openbravo SL
adrian@94
    21
* All portions are Copyright (C) 2001-2006 Openbravo SL
adrian@94
    22
* All Rights Reserved.
adrian@94
    23
* Contributor(s):  ______________________________________.
adrian@94
    24
************************************************************************/
juanpablo@1605
    25
  v_ID VARCHAR2(32) ;
juanpablo@1605
    26
  v_ID_MAP     VARCHAR2(32) ;
adrian@94
    27
  v_WindowName VARCHAR2(60):='ad_tasks';
adrian@94
    28
  v_ClassName  VARCHAR2(60) ;
asier@2078
    29
    v_ADEnabledTriggers NUMBER;
adrian@94
    30
BEGIN
asier@2078
    31
    SELECT COUNT(*) INTO v_ADEnabledTriggers FROM AD_ENABLE_TRIGGERS WHERE ISENABLED='N';
asier@2078
    32
    IF v_ADEnabledTriggers!=0 THEN RETURN;
asier@2078
    33
    END IF;
asier@2078
    34
asier@2078
    35
adrian@94
    36
  IF(UPDATING) THEN
gorkaion@239
    37
    IF NOT((COALESCE(:old.CLASSNAME, '.') <> COALESCE(:NEW.CLASSNAME, '.')
gorkaion@239
    38
   OR COALESCE(:old.IsActive, '.') <> COALESCE(:NEW.IsActive, '.')))
adrian@94
    39
  THEN
adrian@94
    40
      RETURN;
adrian@94
    41
    END IF;
adrian@94
    42
  END IF;
adrian@94
    43
  IF(DELETING OR UPDATING) THEN
adrian@94
    44
    IF :OLD.ISACTIVE='Y' AND :OLD.CLASSNAME IS NOT NULL THEN
adrian@94
    45
      DELETE
adrian@94
    46
      FROM AD_MODEL_OBJECT_MAPPING
adrian@94
    47
      WHERE AD_MODEL_OBJECT_ID IN
adrian@94
    48
        (
adrian@94
    49
        SELECT AD_MODEL_OBJECT_ID
adrian@94
    50
        FROM AD_MODEL_OBJECT
adrian@94
    51
        WHERE AD_MODEL_OBJECT.AD_TASK_ID=:old.AD_TASK_ID
adrian@94
    52
          AND ACTION='T'
adrian@94
    53
        )
adrian@94
    54
        ;
adrian@94
    55
      DELETE
adrian@94
    56
      FROM AD_MODEL_OBJECT
adrian@94
    57
      WHERE ACTION='T'
adrian@94
    58
        AND AD_MODEL_OBJECT.AD_TASK_ID=:OLD.AD_TASK_ID;
adrian@94
    59
    END IF;
adrian@94
    60
  END IF;
adrian@94
    61
  IF(INSERTING OR UPDATING) THEN
adrian@94
    62
    IF :NEW.ISACTIVE='Y' AND :NEW.CLASSNAME IS NOT NULL THEN
adrian@94
    63
      v_ClassName:=:new.CLASSNAME;
adrian@94
    64
      Ad_Sequence_Next('AD_Model_Object', :new.AD_Client_ID, v_ID) ;
adrian@94
    65
      INSERT
adrian@94
    66
      INTO AD_MODEL_OBJECT
adrian@94
    67
        (
adrian@94
    68
          AD_MODEL_OBJECT_ID, AD_CLIENT_ID, AD_ORG_ID,
adrian@94
    69
          ISACTIVE, CREATED, CREATEDBY,
adrian@94
    70
          UPDATED, UPDATEDBY, ACTION,
adrian@94
    71
          AD_TASK_ID, CLASSNAME, ISDEFAULT
adrian@94
    72
        )
adrian@94
    73
        VALUES
adrian@94
    74
        (
adrian@94
    75
          v_ID, :new.AD_CLIENT_ID, :new.AD_ORG_ID,
antonio@735
    76
           'Y', now(), :new.CREATEDBY,
antonio@735
    77
          now(), :new.UPDATEDBY, 'T',
adrian@94
    78
          :new.AD_TASK_ID,  'org.openbravo.erpCommon.' || v_WindowName || '.' || v_ClassName, 'Y'
adrian@94
    79
        )
adrian@94
    80
        ;
adrian@94
    81
      Ad_Sequence_Next('AD_Model_Object_Mapping', :new.AD_Client_ID, v_ID_MAP) ;
adrian@94
    82
      INSERT
adrian@94
    83
      INTO AD_MODEL_OBJECT_MAPPING
adrian@94
    84
        (
adrian@94
    85
          AD_MODEL_OBJECT_MAPPING_ID, AD_CLIENT_ID, AD_ORG_ID,
adrian@94
    86
          ISACTIVE, CREATED, CREATEDBY,
adrian@94
    87
          UPDATED, UPDATEDBY, AD_MODEL_OBJECT_ID,
adrian@94
    88
          MAPPINGNAME, ISDEFAULT
adrian@94
    89
        )
adrian@94
    90
        VALUES
adrian@94
    91
        (
adrian@94
    92
          v_ID_MAP, :new.AD_CLIENT_ID, :new.AD_ORG_ID,
antonio@735
    93
           'Y', now(), :new.CREATEDBY,
antonio@735
    94
          now(), :new.UPDATEDBY, v_ID,
adrian@94
    95
          ('/' || v_WindowName || '/' || v_ClassName || '.html'),
adrian@94
    96
           'Y'
adrian@94
    97
        )
adrian@94
    98
        ;
adrian@94
    99
    END IF;
adrian@94
   100
  END IF;
antonio@735
   101
END AD_TASK_TRG2
gorkaion@239
   102
]]></body>
adrian@94
   103
    </trigger>
adrian@94
   104
  </database>