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