database/model/triggers/AD_TASK_TRG2.xml
author Adrián Romero <adrian.romero@openbravo.com>
Tue, 20 Nov 2007 16:27:14 +0000
changeset 94 4e7ba7b8a4ad
parent 59 85aab40b7d24
child 132 33c5ca45fcff
permissions -rw-r--r--
fix: Changed check constraint names and foreign key names to fit in to
30 characteres.
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">
adrian@94
     4
      <body>
adrian@94
     5
adrian@94
     6
adrian@94
     7
/*************************************************************************
adrian@94
     8
* The contents of this file are subject to the Openbravo  Public  License
adrian@94
     9
* Version  1.0  (the  "License"),  being   the  Mozilla   Public  License
adrian@94
    10
* Version 1.1  with a permitted attribution clause; you may not  use this
adrian@94
    11
* file except in compliance with the License. You  may  obtain  a copy of
adrian@94
    12
* the License at http://www.openbravo.com/legal/license.html
adrian@94
    13
* Software distributed under the License  is  distributed  on  an "AS IS"
adrian@94
    14
* basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
adrian@94
    15
* License for the specific  language  governing  rights  and  limitations
adrian@94
    16
* under the License.
adrian@94
    17
* The Original Code is Openbravo ERP.
adrian@94
    18
* The Initial Developer of the Original Code is Openbravo SL
adrian@94
    19
* All portions are Copyright (C) 2001-2006 Openbravo SL
adrian@94
    20
* All Rights Reserved.
adrian@94
    21
* Contributor(s):  ______________________________________.
adrian@94
    22
************************************************************************/
adrian@94
    23
  v_ID NUMBER(10) ;
adrian@94
    24
  v_ID_MAP     NUMBER(10) ;
adrian@94
    25
  v_WindowName VARCHAR2(60):='ad_tasks';
adrian@94
    26
  v_ClassName  VARCHAR2(60) ;
adrian@94
    27
BEGIN
adrian@94
    28
  IF(UPDATING) THEN
adrian@94
    29
    IF NOT((COALESCE(:old.CLASSNAME, '.') &lt;&gt; COALESCE(:NEW.CLASSNAME, '.')
adrian@94
    30
   OR COALESCE(:old.IsActive, '.') &lt;&gt; COALESCE(:NEW.IsActive, '.')))
adrian@94
    31
  THEN
adrian@94
    32
      RETURN;
adrian@94
    33
    END IF;
adrian@94
    34
  END IF;
adrian@94
    35
  IF(DELETING OR UPDATING) THEN
adrian@94
    36
    IF :OLD.ISACTIVE='Y' AND :OLD.CLASSNAME IS NOT NULL THEN
adrian@94
    37
      DELETE
adrian@94
    38
      FROM AD_MODEL_OBJECT_MAPPING
adrian@94
    39
      WHERE AD_MODEL_OBJECT_ID IN
adrian@94
    40
        (
adrian@94
    41
        SELECT AD_MODEL_OBJECT_ID
adrian@94
    42
        FROM AD_MODEL_OBJECT
adrian@94
    43
        WHERE AD_MODEL_OBJECT.AD_TASK_ID=:old.AD_TASK_ID
adrian@94
    44
          AND ACTION='T'
adrian@94
    45
        )
adrian@94
    46
        ;
adrian@94
    47
      DELETE
adrian@94
    48
      FROM AD_MODEL_OBJECT
adrian@94
    49
      WHERE ACTION='T'
adrian@94
    50
        AND AD_MODEL_OBJECT.AD_TASK_ID=:OLD.AD_TASK_ID;
adrian@94
    51
    END IF;
adrian@94
    52
  END IF;
adrian@94
    53
  IF(INSERTING OR UPDATING) THEN
adrian@94
    54
    IF :NEW.ISACTIVE='Y' AND :NEW.CLASSNAME IS NOT NULL THEN
adrian@94
    55
      v_ClassName:=:new.CLASSNAME;
adrian@94
    56
      Ad_Sequence_Next('AD_Model_Object', :new.AD_Client_ID, v_ID) ;
adrian@94
    57
      INSERT
adrian@94
    58
      INTO AD_MODEL_OBJECT
adrian@94
    59
        (
adrian@94
    60
          AD_MODEL_OBJECT_ID, AD_CLIENT_ID, AD_ORG_ID,
adrian@94
    61
          ISACTIVE, CREATED, CREATEDBY,
adrian@94
    62
          UPDATED, UPDATEDBY, ACTION,
adrian@94
    63
          AD_TASK_ID, CLASSNAME, ISDEFAULT
adrian@94
    64
        )
adrian@94
    65
        VALUES
adrian@94
    66
        (
adrian@94
    67
          v_ID, :new.AD_CLIENT_ID, :new.AD_ORG_ID,
adrian@94
    68
           'Y', SYSDATE, :new.CREATEDBY,
adrian@94
    69
          SYSDATE, :new.UPDATEDBY, 'T',
adrian@94
    70
          :new.AD_TASK_ID,  'org.openbravo.erpCommon.' || v_WindowName || '.' || v_ClassName, 'Y'
adrian@94
    71
        )
adrian@94
    72
        ;
adrian@94
    73
      Ad_Sequence_Next('AD_Model_Object_Mapping', :new.AD_Client_ID, v_ID_MAP) ;
adrian@94
    74
      INSERT
adrian@94
    75
      INTO AD_MODEL_OBJECT_MAPPING
adrian@94
    76
        (
adrian@94
    77
          AD_MODEL_OBJECT_MAPPING_ID, AD_CLIENT_ID, AD_ORG_ID,
adrian@94
    78
          ISACTIVE, CREATED, CREATEDBY,
adrian@94
    79
          UPDATED, UPDATEDBY, AD_MODEL_OBJECT_ID,
adrian@94
    80
          MAPPINGNAME, ISDEFAULT
adrian@94
    81
        )
adrian@94
    82
        VALUES
adrian@94
    83
        (
adrian@94
    84
          v_ID_MAP, :new.AD_CLIENT_ID, :new.AD_ORG_ID,
adrian@94
    85
           'Y', SYSDATE, :new.CREATEDBY,
adrian@94
    86
          SYSDATE, :new.UPDATEDBY, v_ID,
adrian@94
    87
          ('/' || v_WindowName || '/' || v_ClassName || '.html'),
adrian@94
    88
           'Y'
adrian@94
    89
        )
adrian@94
    90
        ;
adrian@94
    91
    END IF;
adrian@94
    92
  END IF;
adrian@94
    93
END AD_Task_Trg2
adrian@94
    94
adrian@94
    95
</body>
adrian@94
    96
    </trigger>
adrian@94
    97
  </database>