src-db/database/model/triggers/M_WAREHOUSE_TRG.xml
author Jorge Garcia <jorge.garcia@openbravo.com>
Wed, 20 May 2015 18:17:08 +0200
changeset 26789 f89eff26d185
parent 20233 934faa344e9e
child 26790 ef5da8dc7f38
permissions -rw-r--r--
Fixed issue 25278: Long time to update a warehouse with thousends of locators

On an environment with 60.000 locators for one of the warehouse, when updating
a field of the warehouse it takes a long time to save the record.

Part of the problem is the update of the m_warehouse table. When updated, the
trigger launch an update of the organization id for M_LOCATOR and
M_WAREHOUSE_ACCT tables.

The solution is to check if the organization has changed and, if not, avoid the
unnecessary update of those tables.
adrian@94
     1
<?xml version="1.0"?>
adrian@94
     2
  <database name="TRIGGER M_WAREHOUSE_TRG">
eduardo@1067
     3
    <trigger name="M_WAREHOUSE_TRG" table="M_WAREHOUSE" fires="after" insert="true" update="true" delete="false" foreach="row">
gorkaion@239
     4
      <body><![CDATA[
juanpablo@771
     5
    /*************************************************************************
juanpablo@771
     6
    * The contents of this file are subject to the Compiere Public
juanpablo@771
     7
    * License 1.1 ("License"); You may not use this file except in
juanpablo@771
     8
    * compliance with the License. You may obtain a copy of the License in
juanpablo@771
     9
    * the legal folder of your Openbravo installation.
adrian@94
    10
    * Software distributed under the License is distributed on an
adrian@94
    11
    * "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
adrian@94
    12
    * implied. See the License for the specific language governing rights
adrian@94
    13
    * and limitations under the License.
juanpablo@778
    14
    * The Original Code is  Compiere  ERP &  Business Solution
juanpablo@771
    15
    * The Initial Developer of the Original Code is Jorg Janke and ComPiere, Inc.
adrian@94
    16
    * Portions created by Jorg Janke are Copyright (C) 1999-2001 Jorg Janke,
adrian@94
    17
    * parts created by ComPiere are Copyright (C) ComPiere, Inc.;
adrian@94
    18
    * All Rights Reserved.
ggi@6701
    19
    * Contributor(s): Openbravo SLU
ggi@6701
    20
    * Contributions are Copyright (C) 2001-2008 Openbravo, S.L.U.
juanpablo@771
    21
    *
juanpablo@771
    22
    * Specifically, this derivative work is based upon the following Compiere
juanpablo@771
    23
    * file and version.
adrian@94
    24
    *************************************************************************
adrian@94
    25
    * New Accounting Defaults
adrian@94
    26
    */
adrian@94
    27
adrian@94
    28
adrian@94
    29
  TYPE RECORD IS REF CURSOR;
adrian@94
    30
  Cur_Defaults RECORD;
asier@2084
    31
    
adrian@94
    32
BEGIN
asier@2084
    33
    
asier@2084
    34
    IF AD_isTriggerEnabled()='N' THEN RETURN;
asier@2078
    35
    END IF;
asier@2078
    36
asier@2078
    37
eduardo@1067
    38
  IF(INSERTING) THEN
eduardo@1067
    39
    FOR Cur_Defaults IN
adrian@94
    40
      (
adrian@94
    41
      SELECT *
eduardo@1067
    42
      FROM C_AcctSchema_Default d
eduardo@1067
    43
      WHERE EXISTS
eduardo@1067
    44
        (
asier@1929
    45
      SELECT 1 
asier@1929
    46
      FROM AD_Org_AcctSchema
david@11803
    47
      WHERE (AD_IsOrgIncluded(AD_Org_ID, :new.AD_ORG_ID, :new.AD_Client_ID)<>-1
david@11803
    48
          OR AD_IsOrgIncluded(:new.AD_Org_ID, AD_ORG_ID, :new.AD_Client_ID)<>-1)
asier@1929
    49
      AND IsActive = 'Y'
asier@1929
    50
      AND AD_Org_AcctSchema.C_AcctSchema_ID = d.C_AcctSchema_ID
javier@15871
    51
      AND AD_Org_AcctSchema.AD_Client_ID=:new.AD_Client_ID
eduardo@1067
    52
        )
adrian@94
    53
      )
eduardo@1067
    54
    LOOP
eduardo@1067
    55
      INSERT
eduardo@1067
    56
      INTO M_Warehouse_Acct
eduardo@1067
    57
        (
juanpablo@1605
    58
          M_Warehouse_Acct_ID, M_Warehouse_ID, C_AcctSchema_ID, AD_Client_ID,
eduardo@1067
    59
          AD_Org_ID, IsActive, Created,
eduardo@1067
    60
          CreatedBy, Updated, UpdatedBy,
eduardo@1067
    61
          W_Inventory_Acct, W_Differences_Acct, W_Revaluation_Acct,
eduardo@1067
    62
          W_InvActualAdjust_Acct
eduardo@1067
    63
        )
eduardo@1067
    64
        VALUES
eduardo@1067
    65
        (
juanpablo@1605
    66
          get_uuid(), :new.M_Warehouse_ID, Cur_Defaults.C_AcctSchema_ID, :new.AD_Client_ID,
eduardo@1067
    67
          :new.AD_ORG_ID,  'Y', now(),
eduardo@1067
    68
          :new.CreatedBy, now(), :new.UpdatedBy,
eduardo@1067
    69
          Cur_Defaults.W_Inventory_Acct, Cur_Defaults.W_Differences_Acct, Cur_Defaults.W_Revaluation_Acct,
eduardo@1067
    70
          Cur_Defaults.W_InvActualAdjust_Acct
eduardo@1067
    71
        )
eduardo@1067
    72
        ;
eduardo@1067
    73
    END LOOP;
eduardo@1067
    74
  ELSIF (UPDATING) THEN
jorge@26789
    75
    IF (:new.AD_ORG_ID <> :old.AD_ORG_ID) THEN
jorge@26789
    76
      UPDATE M_WAREHOUSE_ACCT SET AD_ORG_ID = :new.AD_ORG_ID
jorge@26789
    77
      WHERE M_WAREHOUSE_ID = :new.M_WAREHOUSE_ID;
jon@20233
    78
    
jorge@26789
    79
      UPDATE M_LOCATOR SET AD_ORG_ID = :new.AD_ORG_ID
jorge@26789
    80
      WHERE M_WAREHOUSE_ID = :new.M_WAREHOUSE_ID;
jorge@26789
    81
      END IF;
eduardo@1067
    82
  END IF;
antonio@735
    83
END M_WAREHOUSE_TRG
gorkaion@239
    84
]]></body>
adrian@94
    85
    </trigger>
adrian@94
    86
  </database>