src-db/database/model/triggers/AD_TASK_TRG2.xml
author Juan Pablo Aroztegi <juanpablo.aroztegi@openbravo.com>
Wed, 03 Sep 2008 17:55:37 +0000
changeset 1605 8a0fe0193bef
parent 756 ae11e4610537
child 2078 cf88ca44cdd2
permissions -rw-r--r--
Merge r2.5x intro trunk
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) ;
adrian@94
    29
BEGIN
adrian@94
    30
  IF(UPDATING) THEN
gorkaion@239
    31
    IF NOT((COALESCE(:old.CLASSNAME, '.') <> COALESCE(:NEW.CLASSNAME, '.')
gorkaion@239
    32
   OR COALESCE(:old.IsActive, '.') <> COALESCE(:NEW.IsActive, '.')))
adrian@94
    33
  THEN
adrian@94
    34
      RETURN;
adrian@94
    35
    END IF;
adrian@94
    36
  END IF;
adrian@94
    37
  IF(DELETING OR UPDATING) THEN
adrian@94
    38
    IF :OLD.ISACTIVE='Y' AND :OLD.CLASSNAME IS NOT NULL THEN
adrian@94
    39
      DELETE
adrian@94
    40
      FROM AD_MODEL_OBJECT_MAPPING
adrian@94
    41
      WHERE AD_MODEL_OBJECT_ID IN
adrian@94
    42
        (
adrian@94
    43
        SELECT AD_MODEL_OBJECT_ID
adrian@94
    44
        FROM AD_MODEL_OBJECT
adrian@94
    45
        WHERE AD_MODEL_OBJECT.AD_TASK_ID=:old.AD_TASK_ID
adrian@94
    46
          AND ACTION='T'
adrian@94
    47
        )
adrian@94
    48
        ;
adrian@94
    49
      DELETE
adrian@94
    50
      FROM AD_MODEL_OBJECT
adrian@94
    51
      WHERE ACTION='T'
adrian@94
    52
        AND AD_MODEL_OBJECT.AD_TASK_ID=:OLD.AD_TASK_ID;
adrian@94
    53
    END IF;
adrian@94
    54
  END IF;
adrian@94
    55
  IF(INSERTING OR UPDATING) THEN
adrian@94
    56
    IF :NEW.ISACTIVE='Y' AND :NEW.CLASSNAME IS NOT NULL THEN
adrian@94
    57
      v_ClassName:=:new.CLASSNAME;
adrian@94
    58
      Ad_Sequence_Next('AD_Model_Object', :new.AD_Client_ID, v_ID) ;
adrian@94
    59
      INSERT
adrian@94
    60
      INTO AD_MODEL_OBJECT
adrian@94
    61
        (
adrian@94
    62
          AD_MODEL_OBJECT_ID, AD_CLIENT_ID, AD_ORG_ID,
adrian@94
    63
          ISACTIVE, CREATED, CREATEDBY,
adrian@94
    64
          UPDATED, UPDATEDBY, ACTION,
adrian@94
    65
          AD_TASK_ID, CLASSNAME, ISDEFAULT
adrian@94
    66
        )
adrian@94
    67
        VALUES
adrian@94
    68
        (
adrian@94
    69
          v_ID, :new.AD_CLIENT_ID, :new.AD_ORG_ID,
antonio@735
    70
           'Y', now(), :new.CREATEDBY,
antonio@735
    71
          now(), :new.UPDATEDBY, 'T',
adrian@94
    72
          :new.AD_TASK_ID,  'org.openbravo.erpCommon.' || v_WindowName || '.' || v_ClassName, 'Y'
adrian@94
    73
        )
adrian@94
    74
        ;
adrian@94
    75
      Ad_Sequence_Next('AD_Model_Object_Mapping', :new.AD_Client_ID, v_ID_MAP) ;
adrian@94
    76
      INSERT
adrian@94
    77
      INTO AD_MODEL_OBJECT_MAPPING
adrian@94
    78
        (
adrian@94
    79
          AD_MODEL_OBJECT_MAPPING_ID, AD_CLIENT_ID, AD_ORG_ID,
adrian@94
    80
          ISACTIVE, CREATED, CREATEDBY,
adrian@94
    81
          UPDATED, UPDATEDBY, AD_MODEL_OBJECT_ID,
adrian@94
    82
          MAPPINGNAME, ISDEFAULT
adrian@94
    83
        )
adrian@94
    84
        VALUES
adrian@94
    85
        (
adrian@94
    86
          v_ID_MAP, :new.AD_CLIENT_ID, :new.AD_ORG_ID,
antonio@735
    87
           'Y', now(), :new.CREATEDBY,
antonio@735
    88
          now(), :new.UPDATEDBY, v_ID,
adrian@94
    89
          ('/' || v_WindowName || '/' || v_ClassName || '.html'),
adrian@94
    90
           'Y'
adrian@94
    91
        )
adrian@94
    92
        ;
adrian@94
    93
    END IF;
adrian@94
    94
  END IF;
antonio@735
    95
END AD_TASK_TRG2
gorkaion@239
    96
]]></body>
adrian@94
    97
    </trigger>
adrian@94
    98
  </database>