database/model/triggers/AD_TAB_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_TAB_TRG2">
adrian@94
     3
    <trigger name="AD_TAB_TRG2" table="AD_TAB" 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);
adrian@94
    26
 v_ClassName     VARCHAR2(60);
adrian@94
    27
 v_IsActive      CHAR(1) := 'Y';
adrian@94
    28
BEGIN
adrian@94
    29
  IF (UPDATING) THEN
adrian@94
    30
    IF NOT((COALESCE(:old.NAME,'.')&lt;&gt;COALESCE(:NEW.NAME,'.') OR COALESCE(:old.IsActive,'.')&lt;&gt;COALESCE(:NEW.IsActive,'.'))) THEN
adrian@94
    31
      RETURN;
adrian@94
    32
    END IF;
adrian@94
    33
  END IF;
adrian@94
    34
 IF (DELETING OR UPDATING) THEN
adrian@94
    35
  DELETE FROM AD_MODEL_OBJECT_MAPPING WHERE AD_MODEL_OBJECT_ID IN (
adrian@94
    36
      SELECT AD_MODEL_OBJECT_ID FROM AD_MODEL_OBJECT WHERE AD_MODEL_OBJECT.AD_TAB_ID=:old.AD_TAB_ID AND ACTION = 'W');
adrian@94
    37
  DELETE FROM AD_MODEL_OBJECT WHERE ACTION = 'W' AND AD_MODEL_OBJECT.AD_TAB_ID = :OLD.AD_TAB_ID;
adrian@94
    38
 END IF;
adrian@94
    39
adrian@94
    40
 IF (INSERTING OR UPDATING) THEN
adrian@94
    41
     SELECT MAX(TO_CHAR(ISACTIVE)) INTO v_IsActive
adrian@94
    42
  FROM AD_WINDOW
adrian@94
    43
  WHERE AD_WINDOW_ID = :NEW.AD_WINDOW_ID;
adrian@94
    44
adrian@94
    45
  IF v_IsActive &lt;&gt; 'Y' THEN
adrian@94
    46
      v_IsActive := :NEW.ISACTIVE;
adrian@94
    47
  END IF;
adrian@94
    48
  SELECT AD_MAPPING_FORMAT(TO_CHAR(W.NAME)), AD_MAPPING_FORMAT(TO_CHAR(:new.NAME))
adrian@94
    49
  INTO v_WindowName, v_ClassName
adrian@94
    50
  FROM AD_WINDOW W
adrian@94
    51
  WHERE W.AD_WINDOW_ID = :new.AD_WINDOW_ID;
adrian@94
    52
adrian@94
    53
  Ad_Sequence_Next('AD_Model_Object', :new.AD_Client_ID, v_ID);
adrian@94
    54
  INSERT INTO AD_MODEL_OBJECT (AD_MODEL_OBJECT_ID, AD_CLIENT_ID, AD_ORG_ID, ISACTIVE, CREATED, CREATEDBY,
adrian@94
    55
  UPDATED, UPDATEDBY, ACTION, AD_TAB_ID, CLASSNAME, ISDEFAULT)
adrian@94
    56
  VALUES (v_ID, :new.AD_CLIENT_ID, :new.AD_ORG_ID, v_IsActive, SYSDATE, :new.CREATEDBY,
adrian@94
    57
  SYSDATE, :new.UPDATEDBY, 'W', :new.AD_TAB_ID, 'org.openbravo.erpWindows.' || v_WindowName || '.' || v_ClassName, 'Y');
adrian@94
    58
adrian@94
    59
  Ad_Sequence_Next('AD_Model_Object_Mapping', :new.AD_Client_ID, v_ID_MAP);
adrian@94
    60
  INSERT INTO AD_MODEL_OBJECT_MAPPING (AD_MODEL_OBJECT_MAPPING_ID, AD_CLIENT_ID, AD_ORG_ID,
adrian@94
    61
  ISACTIVE, CREATED, CREATEDBY, UPDATED, UPDATEDBY, AD_MODEL_OBJECT_ID, MAPPINGNAME, ISDEFAULT)
adrian@94
    62
  VALUES (v_ID_MAP, :new.AD_CLIENT_ID, :new.AD_ORG_ID, v_IsActive, SYSDATE, :new.CREATEDBY,
adrian@94
    63
  SYSDATE, :new.UPDATEDBY, v_ID, ('/' || v_WindowName || '/' || v_ClassName || '_Relation.html'), 'Y');
adrian@94
    64
adrian@94
    65
  Ad_Sequence_Next('AD_Model_Object_Mapping', :new.AD_Client_ID, v_ID_MAP);
adrian@94
    66
  INSERT INTO AD_MODEL_OBJECT_MAPPING (AD_MODEL_OBJECT_MAPPING_ID, AD_CLIENT_ID, AD_ORG_ID,
adrian@94
    67
  ISACTIVE, CREATED, CREATEDBY, UPDATED, UPDATEDBY, AD_MODEL_OBJECT_ID, MAPPINGNAME, ISDEFAULT)
adrian@94
    68
  VALUES (v_ID_MAP, :new.AD_CLIENT_ID, :new.AD_ORG_ID, v_IsActive, SYSDATE, :new.CREATEDBY,
adrian@94
    69
  SYSDATE, :new.UPDATEDBY, v_ID, ('/' || v_WindowName || '/' || v_ClassName || '_Edition.html'), 'N');
adrian@94
    70
adrian@94
    71
  Ad_Sequence_Next('AD_Model_Object_Mapping', :new.AD_Client_ID, v_ID_MAP);
adrian@94
    72
  INSERT INTO AD_MODEL_OBJECT_MAPPING (AD_MODEL_OBJECT_MAPPING_ID, AD_CLIENT_ID, AD_ORG_ID,
adrian@94
    73
  ISACTIVE, CREATED, CREATEDBY, UPDATED, UPDATEDBY, AD_MODEL_OBJECT_ID, MAPPINGNAME, ISDEFAULT)
adrian@94
    74
  VALUES (v_ID_MAP, :new.AD_CLIENT_ID, :new.AD_ORG_ID, v_IsActive, SYSDATE, :new.CREATEDBY,
adrian@94
    75
  SYSDATE, :new.UPDATEDBY, v_ID, ('/' || v_WindowName || '/' || v_ClassName || '_Excel.xls'), 'N');
adrian@94
    76
adrian@94
    77
  Ad_Sequence_Next('AD_Model_Object', :new.AD_Client_ID, v_ID);
adrian@94
    78
  INSERT INTO AD_MODEL_OBJECT (AD_MODEL_OBJECT_ID, AD_CLIENT_ID, AD_ORG_ID, ISACTIVE, CREATED, CREATEDBY,
adrian@94
    79
  UPDATED, UPDATEDBY, ACTION, AD_TAB_ID, CLASSNAME, ISDEFAULT)
adrian@94
    80
  VALUES (v_ID, :new.AD_CLIENT_ID, :new.AD_ORG_ID, v_IsActive, SYSDATE, :new.CREATEDBY,
adrian@94
    81
  SYSDATE, :new.UPDATEDBY, 'W', :new.AD_TAB_ID, 'org.openbravo.erpCommon.ad_callouts.ComboReloads' || :new.ad_tab_id, 'N');
adrian@94
    82
adrian@94
    83
  Ad_Sequence_Next('AD_Model_Object_Mapping', :new.AD_Client_ID, v_ID_MAP);
adrian@94
    84
  INSERT INTO AD_MODEL_OBJECT_MAPPING (AD_MODEL_OBJECT_MAPPING_ID, AD_CLIENT_ID, AD_ORG_ID,
adrian@94
    85
  ISACTIVE, CREATED, CREATEDBY, UPDATED, UPDATEDBY, AD_MODEL_OBJECT_ID, MAPPINGNAME, ISDEFAULT)
adrian@94
    86
  VALUES (v_ID_MAP, :new.AD_CLIENT_ID, :new.AD_ORG_ID, v_IsActive, SYSDATE, :new.CREATEDBY,
adrian@94
    87
  SYSDATE, :new.UPDATEDBY, v_ID, ('/ad_callouts/ComboReloads' || :new.ad_tab_id || '.html'), 'N');
adrian@94
    88
 END IF;
adrian@94
    89
adrian@94
    90
END AD_Tab_Trg2
adrian@94
    91
</body>
adrian@94
    92
    </trigger>
adrian@94
    93
  </database>