modules/org.openbravo.client.application/src-db/database/model/triggers/OBUIAPP_VIEW_IMPL_TRG.xml
author Harpreet Singh <harpreet@openbravo.com>
Fri, 10 Dec 2010 19:47:45 +0100
changeset 9076 c4f1a5c7d7c2
child 10772 802557f42def
permissions -rw-r--r--
Added 3.0 modules to modules dir and changed the VERSION number
harpreet@9076
     1
<?xml version="1.0"?>
harpreet@9076
     2
  <database name="TRIGGER OBUIAPP_VIEW_IMPL_TRG">
harpreet@9076
     3
    <trigger name="OBUIAPP_VIEW_IMPL_TRG" table="OBUIAPP_VIEW_IMPL" fires="before" insert="true" update="true" delete="true" foreach="row">
harpreet@9076
     4
      <body><![CDATA[
harpreet@9076
     5
harpreet@9076
     6
/*************************************************************************
harpreet@9076
     7
* The contents of this file are subject to the Openbravo  Public  License
harpreet@9076
     8
* Version  1.1  (the  "License"),  being   the  Mozilla   Public  License
harpreet@9076
     9
* Version 1.1  with a permitted attribution clause; you may not  use this
harpreet@9076
    10
* file except in compliance with the License. You  may  obtain  a copy of
harpreet@9076
    11
* the License at http://www.openbravo.com/legal/license.html
harpreet@9076
    12
* Software distributed under the License  is  distributed  on  an "AS IS"
harpreet@9076
    13
* basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
harpreet@9076
    14
* License for the specific  language  governing  rights  and  limitations
harpreet@9076
    15
* under the License.
harpreet@9076
    16
* The Original Code is Openbravo ERP.
harpreet@9076
    17
* The Initial Developer of the Original Code is Openbravo SL
harpreet@9076
    18
* All portions are Copyright (C) 2010 Openbravo SL
harpreet@9076
    19
* All Rights Reserved.
harpreet@9076
    20
* Contributor(s):  ______________________________________.
harpreet@9076
    21
************************************************************************/
harpreet@9076
    22
  devTemplate NUMBER;
harpreet@9076
    23
  devModule   CHAR(1);
harpreet@9076
    24
  currentModuleID  VARCHAR2(32);
harpreet@9076
    25
  vAux NUMBER;
harpreet@9076
    26
harpreet@9076
    27
BEGIN
harpreet@9076
    28
    
harpreet@9076
    29
    IF AD_isTriggerEnabled()='N' THEN RETURN;
harpreet@9076
    30
    END IF;   
harpreet@9076
    31
 
harpreet@9076
    32
 IF (UPDATING) or (INSERTING) THEN
harpreet@9076
    33
   IF :new.AD_Module_ID != '0' THEN
harpreet@9076
    34
    SELECT COUNT(*)
harpreet@9076
    35
      INTO vAux
harpreet@9076
    36
      FROM AD_MODULE_DBPREFIX
harpreet@9076
    37
     WHERE AD_MODULE_ID = :new.AD_Module_ID
harpreet@9076
    38
       AND instr(upper(:new.name), upper(name)||'_') = 1;
harpreet@9076
    39
    
harpreet@9076
    40
    IF vAux = 0 THEN
harpreet@9076
    41
      RAISE_APPLICATION_ERROR(-20536, 'Name must start with its module DB prefix') ;
harpreet@9076
    42
    END IF;
harpreet@9076
    43
  END IF;
harpreet@9076
    44
END IF;
harpreet@9076
    45
harpreet@9076
    46
  IF (UPDATING) THEN
harpreet@9076
    47
    IF (COALESCE(:NEW.AD_Module_ID , '.') != COALESCE(:OLD.AD_Module_ID , '.')) THEN
harpreet@9076
    48
      SELECT COUNT(*) 
harpreet@9076
    49
        INTO vAux
harpreet@9076
    50
        FROM AD_MODULE
harpreet@9076
    51
       WHERE AD_MODULE_ID = :old.AD_Module_ID
harpreet@9076
    52
        AND isindevelopment = 'N';
harpreet@9076
    53
      IF (vAux!=0) THEN
harpreet@9076
    54
        RAISE_APPLICATION_ERROR(-20000, '@ChangeNotInDevModule@');
harpreet@9076
    55
      END IF;
harpreet@9076
    56
    END IF;
harpreet@9076
    57
  END IF;
harpreet@9076
    58
harpreet@9076
    59
  SELECT COUNT(*)
harpreet@9076
    60
    INTO devTemplate
harpreet@9076
    61
    FROM AD_MODULE
harpreet@9076
    62
   WHERE IsInDevelopment = 'Y'
harpreet@9076
    63
     AND Type = 'T';
harpreet@9076
    64
     
harpreet@9076
    65
  IF (UPDATING OR INSERTING) THEN
harpreet@9076
    66
    currentModuleID := :new.AD_Module_ID;
harpreet@9076
    67
  ELSE
harpreet@9076
    68
    currentModuleID := :old.AD_Module_ID;
harpreet@9076
    69
  END IF;
harpreet@9076
    70
harpreet@9076
    71
  SELECT M.IsInDevelopment
harpreet@9076
    72
    INTO devModule
harpreet@9076
    73
    FROM AD_MODULE M
harpreet@9076
    74
   WHERE M.AD_MODULE_ID = currentModuleID;
harpreet@9076
    75
harpreet@9076
    76
    IF (UPDATING AND devTemplate=0 AND devModule='N') THEN
harpreet@9076
    77
    -- Cannot update an object in a module not in developement and without an active template
harpreet@9076
    78
      RAISE_APPLICATION_ERROR(-20000, '@20532@');
harpreet@9076
    79
    END IF;
harpreet@9076
    80
harpreet@9076
    81
  IF ((DELETING OR INSERTING) AND devModule='N') THEN
harpreet@9076
    82
  -- Cannot insert/delete objects in a module not in development.
harpreet@9076
    83
    RAISE_APPLICATION_ERROR(-20000, '@20533@');
harpreet@9076
    84
  END IF;
harpreet@9076
    85
harpreet@9076
    86
END OBUIAPP_VIEW_IMPL_TRG
harpreet@9076
    87
]]></body>
harpreet@9076
    88
    </trigger>
harpreet@9076
    89
  </database>