From 9d8cf4ff4cb388553122f964bbefa13af5cc9d3d Mon Sep 17 00:00:00 2001 From: Carlos Ruiz Date: Thu, 29 May 2008 06:09:06 +0000 Subject: [PATCH] Integrate [ 1936311 ] Migration of existing BOM to Libero BOM Contribution from Tony tspc --- db/ddlutils/oracle/functions/nextIDFunc.sql | 14 ++++ .../340s-trunk/167_create_nextidfunc.sql | 14 ++++ migration/340s-trunk/168_bom_migrate_ora.sql | 73 +++++++++++++++++++ .../postgresql/167_create_nextidfunc.sql | 2 + .../postgresql/168_bom_migrate_pg.sql | 73 +++++++++++++++++++ sqlj/postgresql/sqlj.ddr | 4 + sqlj/src/org/compiere/sqlj/Adempiere.java | 12 +++ 7 files changed, 192 insertions(+) create mode 100644 db/ddlutils/oracle/functions/nextIDFunc.sql create mode 100644 migration/340s-trunk/167_create_nextidfunc.sql create mode 100644 migration/340s-trunk/168_bom_migrate_ora.sql create mode 100644 migration/340s-trunk/postgresql/167_create_nextidfunc.sql create mode 100644 migration/340s-trunk/postgresql/168_bom_migrate_pg.sql diff --git a/db/ddlutils/oracle/functions/nextIDFunc.sql b/db/ddlutils/oracle/functions/nextIDFunc.sql new file mode 100644 index 0000000000..a4d20de89b --- /dev/null +++ b/db/ddlutils/oracle/functions/nextIDFunc.sql @@ -0,0 +1,14 @@ +CREATE OR REPLACE FUNCTION nextidfunc ( + p_ad_sequence_id IN NUMBER, + p_system IN CHAR +) + RETURN NUMBER +IS + PRAGMA AUTONOMOUS_TRANSACTION; + tmpvar NUMBER; +BEGIN + Nextid (p_ad_sequence_id, p_system, tmpvar); + COMMIT; + RETURN tmpvar; +END nextidfunc; +/ diff --git a/migration/340s-trunk/167_create_nextidfunc.sql b/migration/340s-trunk/167_create_nextidfunc.sql new file mode 100644 index 0000000000..807eb1091f --- /dev/null +++ b/migration/340s-trunk/167_create_nextidfunc.sql @@ -0,0 +1,14 @@ +CREATE OR REPLACE FUNCTION nextidfunc ( + p_ad_sequence_id IN NUMBER, + p_system IN CHAR +) + RETURN NUMBER +IS + PRAGMA AUTONOMOUS_TRANSACTION; + tmpvar NUMBER; +BEGIN + Nextid (p_ad_sequence_id, p_system, tmpvar); + COMMIT; + RETURN tmpvar; +END nextidfunc; +/ \ No newline at end of file diff --git a/migration/340s-trunk/168_bom_migrate_ora.sql b/migration/340s-trunk/168_bom_migrate_ora.sql new file mode 100644 index 0000000000..03b220c917 --- /dev/null +++ b/migration/340s-trunk/168_bom_migrate_ora.sql @@ -0,0 +1,73 @@ +INSERT INTO PP_PRODUCT_BOM + (pp_product_bom_id, ad_client_id, ad_org_id, isactive, created, + createdby, updated, updatedby, m_product_id, bomtype, VALUE, + NAME, description, help, documentno, revision, copyfrom, + m_changenotice_id, processing, validfrom, validto, + m_attributesetinstance_id, bomuse, c_uom_id) + SELECT m_product_id, ad_client_id, ad_org_id, isactive, created, createdby, + updated, updatedby, m_product_id, 'A', VALUE, NAME, description, + help, + nextidfunc ((SELECT ad_sequence_id + FROM AD_SEQUENCE + WHERE ad_client_id = mp.ad_client_id + AND NAME = 'DocumentNo_PP_Product_BOM'), + 'N' + ), + NULL, NULL, NULL, NULL, created, NULL, NULL, 'M', c_uom_id + FROM M_PRODUCT mp + WHERE isbom = 'Y' AND m_product_id < 1000000; + +INSERT INTO PP_PRODUCT_BOM + (pp_product_bom_id, ad_client_id, ad_org_id, isactive, created, + createdby, updated, updatedby, m_product_id, bomtype, VALUE, + NAME, description, help, documentno, revision, copyfrom, + m_changenotice_id, processing, validfrom, validto, + m_attributesetinstance_id, bomuse, c_uom_id) + SELECT nextidfunc (53015, 'N'), ad_client_id, ad_org_id, isactive, created, + createdby, updated, updatedby, m_product_id, 'A', VALUE, NAME, + description, help, + nextidfunc ((SELECT ad_sequence_id + FROM AD_SEQUENCE + WHERE ad_client_id = mp.ad_client_id + AND NAME = 'DocumentNo_PP_Product_BOM'), + 'N' + ), + NULL, NULL, NULL, NULL, created, NULL, NULL, 'M', c_uom_id + FROM M_PRODUCT mp + WHERE isbom = 'Y' AND m_product_id > 999999; + +INSERT INTO PP_PRODUCT_BOMLINE + (pp_product_bomline_id, ad_client_id, ad_org_id, isactive, + created, createdby, updated, updatedby, line, m_product_id, + pp_product_bom_id, qtybom, description, help, feature, assay, + backflushgroup, c_uom_id, componenttype, forecast, iscritical, + isqtypercentage, issuemethod, leadtimeoffset, + m_attributesetinstance_id, m_changenotice_id, qtybatch, scrap, + validfrom, validto) + SELECT mpb.m_product_bom_id, mpb.ad_client_id, mpb.ad_org_id, mpb.isactive, + mpb.created, mpb.createdby, mpb.updated, mpb.updatedby, mpb.line, + mpb.m_productbom_id, ppb.pp_product_bom_id, mpb.bomqty, + mpb.description, NULL, NULL, 0, NULL, mp.c_uom_id, 'CO', 0, 'N', + 'N', '0', 0, NULL, NULL, 0, 0, mpb.created, NULL + FROM M_PRODUCT_BOM mpb, PP_PRODUCT_BOM ppb, M_PRODUCT mp + WHERE mpb.m_product_id = ppb.m_product_id + AND mpb.m_productbom_id = mp.m_product_id + AND mpb.m_product_bom_id < 1000000; + +INSERT INTO PP_PRODUCT_BOMLINE + (pp_product_bomline_id, ad_client_id, ad_org_id, isactive, + created, createdby, updated, updatedby, line, m_product_id, + pp_product_bom_id, qtybom, description, help, feature, assay, + backflushgroup, c_uom_id, componenttype, forecast, iscritical, + isqtypercentage, issuemethod, leadtimeoffset, + m_attributesetinstance_id, m_changenotice_id, qtybatch, scrap, + validfrom, validto) + SELECT nextidfunc (53016, 'N'), mpb.ad_client_id, mpb.ad_org_id, + mpb.isactive, mpb.created, mpb.createdby, mpb.updated, + mpb.updatedby, mpb.line, mpb.m_productbom_id, ppb.pp_product_bom_id, + mpb.bomqty, mpb.description, NULL, NULL, 0, NULL, mp.c_uom_id, 'CO', + 0, 'N', 'N', '0', 0, NULL, NULL, 0, 0, mpb.created, NULL + FROM M_PRODUCT_BOM mpb, PP_PRODUCT_BOM ppb, M_PRODUCT mp + WHERE mpb.m_product_id = ppb.m_product_id + AND mpb.m_productbom_id = mp.m_product_id + AND mpb.m_product_bom_id > 999999; \ No newline at end of file diff --git a/migration/340s-trunk/postgresql/167_create_nextidfunc.sql b/migration/340s-trunk/postgresql/167_create_nextidfunc.sql new file mode 100644 index 0000000000..2ef75177f6 --- /dev/null +++ b/migration/340s-trunk/postgresql/167_create_nextidfunc.sql @@ -0,0 +1,2 @@ +-- placeholder +-- migration script just for oracle \ No newline at end of file diff --git a/migration/340s-trunk/postgresql/168_bom_migrate_pg.sql b/migration/340s-trunk/postgresql/168_bom_migrate_pg.sql new file mode 100644 index 0000000000..3a3a803f8f --- /dev/null +++ b/migration/340s-trunk/postgresql/168_bom_migrate_pg.sql @@ -0,0 +1,73 @@ +INSERT INTO PP_PRODUCT_BOM + (pp_product_bom_id, ad_client_id, ad_org_id, isactive, created, + createdby, updated, updatedby, m_product_id, bomtype, VALUE, + NAME, description, help, documentno, revision, copyfrom, + m_changenotice_id, processing, validfrom, validto, + m_attributesetinstance_id, bomuse, c_uom_id) + SELECT m_product_id, ad_client_id, ad_org_id, isactive, created, createdby, + updated, updatedby, m_product_id, 'A', VALUE, NAME, description, + help, + Nextid ((SELECT ad_sequence_id + FROM AD_SEQUENCE + WHERE ad_client_id = mp.ad_client_id + AND NAME = 'DocumentNo_PP_Product_BOM')::integer, + 'N' + ), + NULL, NULL, NULL, NULL, created, NULL, NULL, 'M', c_uom_id + FROM M_PRODUCT mp + WHERE isbom = 'Y' AND m_product_id < 1000000; + +INSERT INTO PP_PRODUCT_BOM + (pp_product_bom_id, ad_client_id, ad_org_id, isactive, created, + createdby, updated, updatedby, m_product_id, bomtype, VALUE, + NAME, description, help, documentno, revision, copyfrom, + m_changenotice_id, processing, validfrom, validto, + m_attributesetinstance_id, bomuse, c_uom_id) + SELECT Nextid (53015, 'N'), ad_client_id, ad_org_id, isactive, created, + createdby, updated, updatedby, m_product_id, 'A', VALUE, NAME, + description, help, + Nextid ((SELECT ad_sequence_id + FROM AD_SEQUENCE + WHERE ad_client_id = mp.ad_client_id + AND NAME = 'DocumentNo_PP_Product_BOM')::integer, + 'N' + ), + NULL, NULL, NULL, NULL, created, NULL, NULL, 'M', c_uom_id + FROM M_PRODUCT mp + WHERE isbom = 'Y' AND m_product_id > 999999; + +INSERT INTO PP_PRODUCT_BOMLINE + (pp_product_bomline_id, ad_client_id, ad_org_id, isactive, + created, createdby, updated, updatedby, line, m_product_id, + pp_product_bom_id, qtybom, description, help, feature, assay, + backflushgroup, c_uom_id, componenttype, forecast, iscritical, + isqtypercentage, issuemethod, leadtimeoffset, + m_attributesetinstance_id, m_changenotice_id, qtybatch, scrap, + validfrom, validto) + SELECT mpb.m_product_bom_id, mpb.ad_client_id, mpb.ad_org_id, mpb.isactive, + mpb.created, mpb.createdby, mpb.updated, mpb.updatedby, mpb.line, + mpb.m_productbom_id, ppb.pp_product_bom_id, mpb.bomqty, + mpb.description, NULL, NULL, 0, NULL, mp.c_uom_id, 'CO', 0, 'N', + 'N', '0', 0, NULL, NULL, 0, 0, mpb.created, NULL + FROM M_PRODUCT_BOM mpb, PP_PRODUCT_BOM ppb, M_PRODUCT mp + WHERE mpb.m_product_id = ppb.m_product_id + AND mpb.m_productbom_id = mp.m_product_id + AND mpb.m_product_bom_id < 1000000; + +INSERT INTO PP_PRODUCT_BOMLINE + (pp_product_bomline_id, ad_client_id, ad_org_id, isactive, + created, createdby, updated, updatedby, line, m_product_id, + pp_product_bom_id, qtybom, description, help, feature, assay, + backflushgroup, c_uom_id, componenttype, forecast, iscritical, + isqtypercentage, issuemethod, leadtimeoffset, + m_attributesetinstance_id, m_changenotice_id, qtybatch, scrap, + validfrom, validto) + SELECT Nextid (53016, 'N'), mpb.ad_client_id, mpb.ad_org_id, mpb.isactive, + mpb.created, mpb.createdby, mpb.updated, mpb.updatedby, mpb.line, + mpb.m_productbom_id, ppb.pp_product_bom_id, mpb.bomqty, + mpb.description, NULL, NULL, 0, NULL, mp.c_uom_id, 'CO', 0, 'N', + 'N', '0', 0, NULL, NULL, 0, 0, mpb.created, NULL + FROM M_PRODUCT_BOM mpb, PP_PRODUCT_BOM ppb, M_PRODUCT mp + WHERE mpb.m_product_id = ppb.m_product_id + AND mpb.m_productbom_id = mp.m_product_id + AND mpb.m_product_bom_id > 999999; diff --git a/sqlj/postgresql/sqlj.ddr b/sqlj/postgresql/sqlj.ddr index 13e6362a8e..9f4ffa7163 100755 --- a/sqlj/postgresql/sqlj.ddr +++ b/sqlj/postgresql/sqlj.ddr @@ -22,6 +22,10 @@ SQLActions[ ] = { AS 'org.compiere.sqlj.Adempiere.nextID(int,java.lang.String)' LANGUAGE java VOLATILE; + CREATE OR REPLACE FUNCTION nextIDfunc(AD_Sequence_ID INTEGER, System VARCHAR) + RETURNS INTEGER + AS 'org.compiere.sqlj.Adempiere.nextIDfunc(int,java.lang.String)' + LANGUAGE java VOLATILE; /** Product **/ CREATE OR REPLACE FUNCTION productAttribute (M_AttributeSetInstance_ID NUMERIC) diff --git a/sqlj/src/org/compiere/sqlj/Adempiere.java b/sqlj/src/org/compiere/sqlj/Adempiere.java index c462cc6dc0..4475b1aa1c 100644 --- a/sqlj/src/org/compiere/sqlj/Adempiere.java +++ b/sqlj/src/org/compiere/sqlj/Adempiere.java @@ -516,6 +516,18 @@ public class Adempiere implements Serializable return retValue; } // nextID + /** + * Next ID Function + * @param AD_Sequence_ID sequence + * @param System system + * @return ID or -1 + * @throws SQLException + */ + public static int nextIDfunc (int AD_Sequence_ID, String System) + throws SQLException + { + return nextID(AD_Sequence_ID, System); + } // nextIDfunc /** * get current Date (Timestamp)