IDEMPIERE-3916 Process to move client between databases / FHEG-599
This commit is contained in:
parent
e3f84efcb0
commit
51abcd9c80
|
@ -0,0 +1,285 @@
|
|||
SET SQLBLANKLINES ON
|
||||
SET DEFINE OFF
|
||||
|
||||
-- IDEMPIERE-3916 Process to move client between databases
|
||||
-- Mar 13, 2019 1:17:24 PM CET
|
||||
INSERT INTO AD_Process (AD_Process_ID,AD_Client_ID,AD_Org_ID,IsActive,Created,CreatedBy,Updated,UpdatedBy,Name,Description,IsReport,Value,IsDirectPrint,Classname,AccessLevel,EntityType,Statistic_Count,Statistic_Seconds,IsBetaFunctionality,IsServerProcess,ShowHelp,CopyFromProcess,AD_Process_UU) VALUES (200110,0,0,'Y',TO_DATE('2019-03-13 13:17:24','YYYY-MM-DD HH24:MI:SS'),100,TO_DATE('2019-03-13 13:17:24','YYYY-MM-DD HH24:MI:SS'),100,'Move Client','Process to move a client from an external database to current','N','MoveClient','N','org.idempiere.process.MoveClient','4','D',0,0,'N','N','Y','N','365a132a-7b8e-4f0f-b1d3-70db173df7f9')
|
||||
;
|
||||
|
||||
-- Mar 13, 2019 1:17:54 PM CET
|
||||
INSERT INTO AD_Menu (AD_Menu_ID,Name,Description,Action,AD_Client_ID,AD_Org_ID,IsActive,Created,CreatedBy,Updated,UpdatedBy,IsSummary,AD_Process_ID,IsSOTrx,IsReadOnly,EntityType,IsCentrallyMaintained,AD_Menu_UU) VALUES (200168,'Move Client','Process to move a client from an external database to current','P',0,0,'Y',TO_DATE('2019-03-13 13:17:53','YYYY-MM-DD HH24:MI:SS'),100,TO_DATE('2019-03-13 13:17:53','YYYY-MM-DD HH24:MI:SS'),100,'N',200110,'Y','N','D','Y','63aa38c7-b332-42d3-813e-912389e4f767')
|
||||
;
|
||||
|
||||
-- Mar 13, 2019 1:17:54 PM CET
|
||||
INSERT INTO AD_TreeNodeMM (AD_Client_ID,AD_Org_ID, IsActive,Created,CreatedBy,Updated,UpdatedBy, AD_Tree_ID, Node_ID, Parent_ID, SeqNo, AD_TreeNodeMM_UU) SELECT t.AD_Client_ID, 0, 'Y', SysDate, 100, SysDate, 100,t.AD_Tree_ID, 200168, 0, 999, Generate_UUID() FROM AD_Tree t WHERE t.AD_Client_ID=0 AND t.IsActive='Y' AND t.IsAllNodes='Y' AND t.TreeType='MM' AND NOT EXISTS (SELECT * FROM AD_TreeNodeMM e WHERE e.AD_Tree_ID=t.AD_Tree_ID AND Node_ID=200168)
|
||||
;
|
||||
|
||||
-- Mar 13, 2019 1:18:30 PM CET
|
||||
UPDATE AD_TreeNodeMM SET Parent_ID=0, SeqNo=0, Updated=SysDate WHERE AD_Tree_ID=10 AND Node_ID=218
|
||||
;
|
||||
|
||||
-- Mar 13, 2019 1:18:30 PM CET
|
||||
UPDATE AD_TreeNodeMM SET Parent_ID=0, SeqNo=1, Updated=SysDate WHERE AD_Tree_ID=10 AND Node_ID=153
|
||||
;
|
||||
|
||||
-- Mar 13, 2019 1:18:30 PM CET
|
||||
UPDATE AD_TreeNodeMM SET Parent_ID=0, SeqNo=2, Updated=SysDate WHERE AD_Tree_ID=10 AND Node_ID=263
|
||||
;
|
||||
|
||||
-- Mar 13, 2019 1:18:30 PM CET
|
||||
UPDATE AD_TreeNodeMM SET Parent_ID=0, SeqNo=3, Updated=SysDate WHERE AD_Tree_ID=10 AND Node_ID=166
|
||||
;
|
||||
|
||||
-- Mar 13, 2019 1:18:30 PM CET
|
||||
UPDATE AD_TreeNodeMM SET Parent_ID=0, SeqNo=4, Updated=SysDate WHERE AD_Tree_ID=10 AND Node_ID=203
|
||||
;
|
||||
|
||||
-- Mar 13, 2019 1:18:30 PM CET
|
||||
UPDATE AD_TreeNodeMM SET Parent_ID=0, SeqNo=5, Updated=SysDate WHERE AD_Tree_ID=10 AND Node_ID=53242
|
||||
;
|
||||
|
||||
-- Mar 13, 2019 1:18:30 PM CET
|
||||
UPDATE AD_TreeNodeMM SET Parent_ID=0, SeqNo=6, Updated=SysDate WHERE AD_Tree_ID=10 AND Node_ID=1000016
|
||||
;
|
||||
|
||||
-- Mar 13, 2019 1:18:30 PM CET
|
||||
UPDATE AD_TreeNodeMM SET Parent_ID=0, SeqNo=7, Updated=SysDate WHERE AD_Tree_ID=10 AND Node_ID=236
|
||||
;
|
||||
|
||||
-- Mar 13, 2019 1:18:30 PM CET
|
||||
UPDATE AD_TreeNodeMM SET Parent_ID=0, SeqNo=8, Updated=SysDate WHERE AD_Tree_ID=10 AND Node_ID=183
|
||||
;
|
||||
|
||||
-- Mar 13, 2019 1:18:30 PM CET
|
||||
UPDATE AD_TreeNodeMM SET Parent_ID=0, SeqNo=9, Updated=SysDate WHERE AD_Tree_ID=10 AND Node_ID=160
|
||||
;
|
||||
|
||||
-- Mar 13, 2019 1:18:30 PM CET
|
||||
UPDATE AD_TreeNodeMM SET Parent_ID=0, SeqNo=10, Updated=SysDate WHERE AD_Tree_ID=10 AND Node_ID=278
|
||||
;
|
||||
|
||||
-- Mar 13, 2019 1:18:30 PM CET
|
||||
UPDATE AD_TreeNodeMM SET Parent_ID=0, SeqNo=11, Updated=SysDate WHERE AD_Tree_ID=10 AND Node_ID=345
|
||||
;
|
||||
|
||||
-- Mar 13, 2019 1:18:30 PM CET
|
||||
UPDATE AD_TreeNodeMM SET Parent_ID=0, SeqNo=12, Updated=SysDate WHERE AD_Tree_ID=10 AND Node_ID=53296
|
||||
;
|
||||
|
||||
-- Mar 13, 2019 1:18:30 PM CET
|
||||
UPDATE AD_TreeNodeMM SET Parent_ID=0, SeqNo=13, Updated=SysDate WHERE AD_Tree_ID=10 AND Node_ID=53014
|
||||
;
|
||||
|
||||
-- Mar 13, 2019 1:18:30 PM CET
|
||||
UPDATE AD_TreeNodeMM SET Parent_ID=0, SeqNo=14, Updated=SysDate WHERE AD_Tree_ID=10 AND Node_ID=53108
|
||||
;
|
||||
|
||||
-- Mar 13, 2019 1:18:30 PM CET
|
||||
UPDATE AD_TreeNodeMM SET Parent_ID=0, SeqNo=15, Updated=SysDate WHERE AD_Tree_ID=10 AND Node_ID=1000036
|
||||
;
|
||||
|
||||
-- Mar 13, 2019 1:18:30 PM CET
|
||||
UPDATE AD_TreeNodeMM SET Parent_ID=0, SeqNo=16, Updated=SysDate WHERE AD_Tree_ID=10 AND Node_ID=1000095
|
||||
;
|
||||
|
||||
-- Mar 13, 2019 1:18:30 PM CET
|
||||
UPDATE AD_TreeNodeMM SET Parent_ID=155, SeqNo=0, Updated=SysDate WHERE AD_Tree_ID=10 AND Node_ID=161
|
||||
;
|
||||
|
||||
-- Mar 13, 2019 1:18:30 PM CET
|
||||
UPDATE AD_TreeNodeMM SET Parent_ID=155, SeqNo=1, Updated=SysDate WHERE AD_Tree_ID=10 AND Node_ID=367
|
||||
;
|
||||
|
||||
-- Mar 13, 2019 1:18:30 PM CET
|
||||
UPDATE AD_TreeNodeMM SET Parent_ID=155, SeqNo=2, Updated=SysDate WHERE AD_Tree_ID=10 AND Node_ID=456
|
||||
;
|
||||
|
||||
-- Mar 13, 2019 1:18:30 PM CET
|
||||
UPDATE AD_TreeNodeMM SET Parent_ID=155, SeqNo=3, Updated=SysDate WHERE AD_Tree_ID=10 AND Node_ID=501
|
||||
;
|
||||
|
||||
-- Mar 13, 2019 1:18:30 PM CET
|
||||
UPDATE AD_TreeNodeMM SET Parent_ID=155, SeqNo=4, Updated=SysDate WHERE AD_Tree_ID=10 AND Node_ID=326
|
||||
;
|
||||
|
||||
-- Mar 13, 2019 1:18:30 PM CET
|
||||
UPDATE AD_TreeNodeMM SET Parent_ID=155, SeqNo=5, Updated=SysDate WHERE AD_Tree_ID=10 AND Node_ID=566
|
||||
;
|
||||
|
||||
-- Mar 13, 2019 1:18:30 PM CET
|
||||
UPDATE AD_TreeNodeMM SET Parent_ID=155, SeqNo=6, Updated=SysDate WHERE AD_Tree_ID=10 AND Node_ID=392
|
||||
;
|
||||
|
||||
-- Mar 13, 2019 1:18:30 PM CET
|
||||
UPDATE AD_TreeNodeMM SET Parent_ID=155, SeqNo=7, Updated=SysDate WHERE AD_Tree_ID=10 AND Node_ID=113
|
||||
;
|
||||
|
||||
-- Mar 13, 2019 1:18:30 PM CET
|
||||
UPDATE AD_TreeNodeMM SET Parent_ID=155, SeqNo=8, Updated=SysDate WHERE AD_Tree_ID=10 AND Node_ID=220
|
||||
;
|
||||
|
||||
-- Mar 13, 2019 1:18:30 PM CET
|
||||
UPDATE AD_TreeNodeMM SET Parent_ID=155, SeqNo=9, Updated=SysDate WHERE AD_Tree_ID=10 AND Node_ID=351
|
||||
;
|
||||
|
||||
-- Mar 13, 2019 1:18:30 PM CET
|
||||
UPDATE AD_TreeNodeMM SET Parent_ID=155, SeqNo=10, Updated=SysDate WHERE AD_Tree_ID=10 AND Node_ID=289
|
||||
;
|
||||
|
||||
-- Mar 13, 2019 1:18:30 PM CET
|
||||
UPDATE AD_TreeNodeMM SET Parent_ID=155, SeqNo=11, Updated=SysDate WHERE AD_Tree_ID=10 AND Node_ID=302
|
||||
;
|
||||
|
||||
-- Mar 13, 2019 1:18:30 PM CET
|
||||
UPDATE AD_TreeNodeMM SET Parent_ID=155, SeqNo=12, Updated=SysDate WHERE AD_Tree_ID=10 AND Node_ID=200168
|
||||
;
|
||||
|
||||
-- Mar 13, 2019 1:18:30 PM CET
|
||||
UPDATE AD_TreeNodeMM SET Parent_ID=155, SeqNo=13, Updated=SysDate WHERE AD_Tree_ID=10 AND Node_ID=303
|
||||
;
|
||||
|
||||
-- Mar 13, 2019 1:18:30 PM CET
|
||||
UPDATE AD_TreeNodeMM SET Parent_ID=155, SeqNo=14, Updated=SysDate WHERE AD_Tree_ID=10 AND Node_ID=200047
|
||||
;
|
||||
|
||||
-- Mar 13, 2019 1:18:30 PM CET
|
||||
UPDATE AD_TreeNodeMM SET Parent_ID=155, SeqNo=15, Updated=SysDate WHERE AD_Tree_ID=10 AND Node_ID=200048
|
||||
;
|
||||
|
||||
-- Mar 13, 2019 1:18:30 PM CET
|
||||
UPDATE AD_TreeNodeMM SET Parent_ID=155, SeqNo=16, Updated=SysDate WHERE AD_Tree_ID=10 AND Node_ID=321
|
||||
;
|
||||
|
||||
-- Mar 13, 2019 1:18:30 PM CET
|
||||
UPDATE AD_TreeNodeMM SET Parent_ID=155, SeqNo=17, Updated=SysDate WHERE AD_Tree_ID=10 AND Node_ID=461
|
||||
;
|
||||
|
||||
-- Mar 13, 2019 1:18:30 PM CET
|
||||
UPDATE AD_TreeNodeMM SET Parent_ID=155, SeqNo=18, Updated=SysDate WHERE AD_Tree_ID=10 AND Node_ID=53193
|
||||
;
|
||||
|
||||
-- Mar 13, 2019 1:18:30 PM CET
|
||||
UPDATE AD_TreeNodeMM SET Parent_ID=155, SeqNo=19, Updated=SysDate WHERE AD_Tree_ID=10 AND Node_ID=53322
|
||||
;
|
||||
|
||||
-- Mar 13, 2019 1:18:30 PM CET
|
||||
UPDATE AD_TreeNodeMM SET Parent_ID=155, SeqNo=20, Updated=SysDate WHERE AD_Tree_ID=10 AND Node_ID=383
|
||||
;
|
||||
|
||||
-- Mar 13, 2019 1:19:21 PM CET
|
||||
INSERT INTO AD_Element (AD_Element_ID,AD_Client_ID,AD_Org_ID,IsActive,Created,CreatedBy,Updated,UpdatedBy,ColumnName,Name,Description,PrintName,EntityType,AD_Element_UU) VALUES (203294,0,0,'Y',TO_DATE('2019-03-13 13:19:21','YYYY-MM-DD HH24:MI:SS'),100,TO_DATE('2019-03-13 13:19:21','YYYY-MM-DD HH24:MI:SS'),100,'ClientsToExclude','Clients to Exclude','Comma separated list of client IDs to exclude','Clients to Exclude','D','6e7efabf-8c3c-424a-a22f-ccfcb7ff426d')
|
||||
;
|
||||
|
||||
-- Mar 13, 2019 1:20:08 PM CET
|
||||
INSERT INTO AD_Element (AD_Element_ID,AD_Client_ID,AD_Org_ID,IsActive,Created,CreatedBy,Updated,UpdatedBy,ColumnName,Name,Description,PrintName,EntityType,AD_Element_UU) VALUES (203295,0,0,'Y',TO_DATE('2019-03-13 13:20:08','YYYY-MM-DD HH24:MI:SS'),100,TO_DATE('2019-03-13 13:20:08','YYYY-MM-DD HH24:MI:SS'),100,'ClientsToInclude','Clients to Include','Comma separated list of client IDs to include','Clients to Include','D','d43df270-66c5-4f08-a3a0-7a9125f2b19a')
|
||||
;
|
||||
|
||||
-- Mar 13, 2019 1:20:21 PM CET
|
||||
INSERT INTO AD_Element (AD_Element_ID,AD_Client_ID,AD_Org_ID,IsActive,Created,CreatedBy,Updated,UpdatedBy,ColumnName,Name,Description,PrintName,EntityType,AD_Element_UU) VALUES (203296,0,0,'Y',TO_DATE('2019-03-13 13:20:21','YYYY-MM-DD HH24:MI:SS'),100,TO_DATE('2019-03-13 13:20:21','YYYY-MM-DD HH24:MI:SS'),100,'TablesToExclude','Tables to Exclude','Comma separated list of tables to exclude','Tables to Exclude','D','9e56bd23-c125-46a4-a1e7-c126c8398888')
|
||||
;
|
||||
|
||||
-- Mar 13, 2019 1:20:34 PM CET
|
||||
INSERT INTO AD_Element (AD_Element_ID,AD_Client_ID,AD_Org_ID,IsActive,Created,CreatedBy,Updated,UpdatedBy,ColumnName,Name,PrintName,EntityType,AD_Element_UU) VALUES (203297,0,0,'Y',TO_DATE('2019-03-13 13:20:34','YYYY-MM-DD HH24:MI:SS'),100,TO_DATE('2019-03-13 13:20:34','YYYY-MM-DD HH24:MI:SS'),100,'JDBC_URL','JDBC URL','JDBC URL','D','dcae66f5-4e3c-4ede-9cc1-f590e4e01ff1')
|
||||
;
|
||||
|
||||
-- Mar 13, 2019 1:21:19 PM CET
|
||||
INSERT INTO AD_Process_Para (AD_Process_Para_ID,AD_Client_ID,AD_Org_ID,IsActive,Created,CreatedBy,Updated,UpdatedBy,Name,AD_Process_ID,SeqNo,AD_Reference_ID,IsRange,FieldLength,IsMandatory,ColumnName,IsCentrallyMaintained,EntityType,AD_Element_ID,AD_Process_Para_UU,IsEncrypted) VALUES (200256,0,0,'Y',TO_DATE('2019-03-13 13:21:19','YYYY-MM-DD HH24:MI:SS'),100,TO_DATE('2019-03-13 13:21:19','YYYY-MM-DD HH24:MI:SS'),100,'JDBC URL',200110,10,10,'N',1000,'Y','JDBC_URL','Y','D',203297,'d85a4590-ebdb-412a-8356-8acd1afc2d58','N')
|
||||
;
|
||||
|
||||
-- Mar 13, 2019 1:21:42 PM CET
|
||||
INSERT INTO AD_Process_Para (AD_Process_Para_ID,AD_Client_ID,AD_Org_ID,IsActive,Created,CreatedBy,Updated,UpdatedBy,Name,AD_Process_ID,SeqNo,AD_Reference_ID,IsRange,FieldLength,IsMandatory,ColumnName,IsCentrallyMaintained,EntityType,AD_Element_ID,AD_Process_Para_UU,IsEncrypted) VALUES (200257,0,0,'Y',TO_DATE('2019-03-13 13:21:41','YYYY-MM-DD HH24:MI:SS'),100,TO_DATE('2019-03-13 13:21:41','YYYY-MM-DD HH24:MI:SS'),100,'User Name',200110,20,10,'N',100,'N','UserName','Y','D',1903,'47c346a2-5bdf-46e2-baef-43c5b5e4c800','N')
|
||||
;
|
||||
|
||||
-- Mar 13, 2019 1:22:13 PM CET
|
||||
INSERT INTO AD_Process_Para (AD_Process_Para_ID,AD_Client_ID,AD_Org_ID,IsActive,Created,CreatedBy,Updated,UpdatedBy,Name,Description,Help,AD_Process_ID,SeqNo,AD_Reference_ID,IsRange,FieldLength,IsMandatory,ColumnName,IsCentrallyMaintained,EntityType,AD_Element_ID,AD_Process_Para_UU,IsEncrypted) VALUES (200258,0,0,'Y',TO_DATE('2019-03-13 13:22:12','YYYY-MM-DD HH24:MI:SS'),100,TO_DATE('2019-03-13 13:22:12','YYYY-MM-DD HH24:MI:SS'),100,'Password','Password of any length (case sensitive)','The Password for this User. Passwords are required to identify authorized users. For iDempiere Users, you can change the password via the Process "Reset Password".',200110,30,10,'N',100,'N','Password','Y','D',498,'7e5b47a3-5bd1-4e92-adb7-d58d4a725932','Y')
|
||||
;
|
||||
|
||||
-- Mar 13, 2019 1:22:34 PM CET
|
||||
INSERT INTO AD_Process_Para (AD_Process_Para_ID,AD_Client_ID,AD_Org_ID,IsActive,Created,CreatedBy,Updated,UpdatedBy,Name,Description,AD_Process_ID,SeqNo,AD_Reference_ID,IsRange,FieldLength,IsMandatory,ColumnName,IsCentrallyMaintained,EntityType,AD_Element_ID,AD_Process_Para_UU,IsEncrypted) VALUES (200259,0,0,'Y',TO_DATE('2019-03-13 13:22:34','YYYY-MM-DD HH24:MI:SS'),100,TO_DATE('2019-03-13 13:22:34','YYYY-MM-DD HH24:MI:SS'),100,'Tables to Exclude','Comma separated list of tables to exclude',200110,40,10,'N',32000,'N','TablesToExclude','Y','D',203296,'25677162-7d62-4319-9c0e-1ff8dfbccf09','N')
|
||||
;
|
||||
|
||||
-- Mar 13, 2019 1:23:04 PM CET
|
||||
INSERT INTO AD_Process_Para (AD_Process_Para_ID,AD_Client_ID,AD_Org_ID,IsActive,Created,CreatedBy,Updated,UpdatedBy,Name,Description,AD_Process_ID,SeqNo,AD_Reference_ID,IsRange,FieldLength,IsMandatory,ColumnName,IsCentrallyMaintained,EntityType,AD_Element_ID,AD_Process_Para_UU,IsEncrypted) VALUES (200260,0,0,'Y',TO_DATE('2019-03-13 13:23:04','YYYY-MM-DD HH24:MI:SS'),100,TO_DATE('2019-03-13 13:23:04','YYYY-MM-DD HH24:MI:SS'),100,'Clients to Include','Comma separated list of client IDs to include',200110,50,10,'N',32000,'N','ClientsToInclude','Y','D',203295,'3284012a-252f-4410-9a55-ae8f1c121f5a','N')
|
||||
;
|
||||
|
||||
-- Mar 13, 2019 1:23:30 PM CET
|
||||
INSERT INTO AD_Process_Para (AD_Process_Para_ID,AD_Client_ID,AD_Org_ID,IsActive,Created,CreatedBy,Updated,UpdatedBy,Name,Description,AD_Process_ID,SeqNo,AD_Reference_ID,IsRange,FieldLength,IsMandatory,ColumnName,IsCentrallyMaintained,EntityType,AD_Element_ID,AD_Process_Para_UU,IsEncrypted) VALUES (200261,0,0,'Y',TO_DATE('2019-03-13 13:23:30','YYYY-MM-DD HH24:MI:SS'),100,TO_DATE('2019-03-13 13:23:30','YYYY-MM-DD HH24:MI:SS'),100,'Clients to Exclude','Comma separated list of client IDs to exclude',200110,60,10,'N',32000,'N','ClientsToExclude','Y','D',203294,'cac0280e-0e34-4c66-b055-51276d75821c','N')
|
||||
;
|
||||
|
||||
-- Mar 13, 2019 1:23:54 PM CET
|
||||
INSERT INTO AD_Process_Para (AD_Process_Para_ID,AD_Client_ID,AD_Org_ID,IsActive,Created,CreatedBy,Updated,UpdatedBy,Name,Description,AD_Process_ID,SeqNo,AD_Reference_ID,IsRange,FieldLength,IsMandatory,DefaultValue,ColumnName,IsCentrallyMaintained,EntityType,AD_Element_ID,AD_Process_Para_UU,IsEncrypted) VALUES (200262,0,0,'Y',TO_DATE('2019-03-13 13:23:54','YYYY-MM-DD HH24:MI:SS'),100,TO_DATE('2019-03-13 13:23:54','YYYY-MM-DD HH24:MI:SS'),100,'Only Validate Data','Validate the date and do not process',200110,70,20,'N',0,'Y','Y','IsValidateOnly','Y','D',2168,'cb303081-dc25-48b1-b6d4-dcf8d17708c2','N')
|
||||
;
|
||||
|
||||
-- Mar 13, 2019 1:24:35 PM CET
|
||||
INSERT INTO AD_Element (AD_Element_ID,AD_Client_ID,AD_Org_ID,IsActive,Created,CreatedBy,Updated,UpdatedBy,ColumnName,Name,PrintName,EntityType,AD_Element_UU) VALUES (203298,0,0,'Y',TO_DATE('2019-03-13 13:24:34','YYYY-MM-DD HH24:MI:SS'),100,TO_DATE('2019-03-13 13:24:34','YYYY-MM-DD HH24:MI:SS'),100,'IsPreserveIDs','Preserve IDs','Preserve IDs','D','717c4728-0178-499b-a846-e70a790e7f96')
|
||||
;
|
||||
|
||||
-- Mar 13, 2019 1:24:55 PM CET
|
||||
INSERT INTO AD_Process_Para (AD_Process_Para_ID,AD_Client_ID,AD_Org_ID,IsActive,Created,CreatedBy,Updated,UpdatedBy,Name,AD_Process_ID,SeqNo,AD_Reference_ID,IsRange,FieldLength,IsMandatory,DefaultValue,ColumnName,IsCentrallyMaintained,EntityType,AD_Element_ID,AD_Process_Para_UU,IsEncrypted) VALUES (200263,0,0,'Y',TO_DATE('2019-03-13 13:24:55','YYYY-MM-DD HH24:MI:SS'),100,TO_DATE('2019-03-13 13:24:55','YYYY-MM-DD HH24:MI:SS'),100,'Preserve IDs',200110,80,20,'N',1,'Y','N','IsPreserveIDs','Y','D',203298,'e81f21da-5126-4009-876b-c477315ba0ea','N')
|
||||
;
|
||||
|
||||
-- Mar 13, 2019 1:25:01 PM CET
|
||||
UPDATE AD_Process_Para SET FieldLength=1,Updated=TO_DATE('2019-03-13 13:25:01','YYYY-MM-DD HH24:MI:SS'),UpdatedBy=100 WHERE AD_Process_Para_ID=200262
|
||||
;
|
||||
|
||||
-- Mar 13, 2019 6:39:33 PM CET
|
||||
UPDATE AD_Process_Para SET Description='Comma separated list of tables that require to preserve the IDs', AD_Reference_ID=10, FieldLength=32000, IsMandatory='N', DefaultValue=NULL,Updated=TO_DATE('2019-03-13 18:39:33','YYYY-MM-DD HH24:MI:SS'),UpdatedBy=100 WHERE AD_Process_Para_ID=200263
|
||||
;
|
||||
|
||||
CREATE TABLE T_MoveClient (AD_PInstance_ID NUMBER(10), TableName VARCHAR2(40), Source_ID NUMBER(10), Target_ID NUMBER(10))
|
||||
;
|
||||
|
||||
CREATE UNIQUE INDEX UX_T_MoveClient ON T_MoveClient (AD_PInstance_ID,TableName,Source_ID)
|
||||
;
|
||||
|
||||
-- Mar 13, 2019 7:28:16 PM CET
|
||||
UPDATE AD_Process_Para SET FieldLength=2000,Updated=TO_DATE('2019-03-13 19:28:16','YYYY-MM-DD HH24:MI:SS'),UpdatedBy=100 WHERE AD_Process_Para_ID=200259
|
||||
;
|
||||
|
||||
-- Mar 13, 2019 7:28:19 PM CET
|
||||
UPDATE AD_Process_Para SET FieldLength=2000,Updated=TO_DATE('2019-03-13 19:28:19','YYYY-MM-DD HH24:MI:SS'),UpdatedBy=100 WHERE AD_Process_Para_ID=200260
|
||||
;
|
||||
|
||||
-- Mar 13, 2019 7:28:22 PM CET
|
||||
UPDATE AD_Process_Para SET FieldLength=2000,Updated=TO_DATE('2019-03-13 19:28:22','YYYY-MM-DD HH24:MI:SS'),UpdatedBy=100 WHERE AD_Process_Para_ID=200261
|
||||
;
|
||||
|
||||
-- Mar 13, 2019 7:28:27 PM CET
|
||||
UPDATE AD_Process_Para SET FieldLength=2000,Updated=TO_DATE('2019-03-13 19:28:27','YYYY-MM-DD HH24:MI:SS'),UpdatedBy=100 WHERE AD_Process_Para_ID=200263
|
||||
;
|
||||
|
||||
-- Mar 13, 2019 7:29:49 PM CET
|
||||
UPDATE AD_Column SET FieldLength=2000,Updated=TO_DATE('2019-03-13 19:29:49','YYYY-MM-DD HH24:MI:SS'),UpdatedBy=100 WHERE AD_Column_ID=5664
|
||||
;
|
||||
|
||||
-- Mar 13, 2019 7:29:51 PM CET
|
||||
ALTER TABLE AD_PInstance_Para MODIFY Info VARCHAR2(2000) DEFAULT NULL
|
||||
;
|
||||
|
||||
-- Mar 13, 2019 7:29:59 PM CET
|
||||
UPDATE AD_Column SET FieldLength=2000,Updated=TO_DATE('2019-03-13 19:29:59','YYYY-MM-DD HH24:MI:SS'),UpdatedBy=100 WHERE AD_Column_ID=5665
|
||||
;
|
||||
|
||||
-- Mar 13, 2019 7:30:00 PM CET
|
||||
ALTER TABLE AD_PInstance_Para MODIFY Info_To VARCHAR2(2000) DEFAULT NULL
|
||||
;
|
||||
|
||||
-- Mar 13, 2019 7:30:20 PM CET
|
||||
UPDATE AD_Column SET FieldLength=2000,Updated=TO_DATE('2019-03-13 19:30:20','YYYY-MM-DD HH24:MI:SS'),UpdatedBy=100 WHERE AD_Column_ID=2791
|
||||
;
|
||||
|
||||
-- Mar 13, 2019 7:30:21 PM CET
|
||||
ALTER TABLE AD_PInstance_Para MODIFY P_String VARCHAR2(2000) DEFAULT NULL
|
||||
;
|
||||
|
||||
-- Mar 13, 2019 7:30:28 PM CET
|
||||
UPDATE AD_Column SET FieldLength=2000,Updated=TO_DATE('2019-03-13 19:30:28','YYYY-MM-DD HH24:MI:SS'),UpdatedBy=100 WHERE AD_Column_ID=2792
|
||||
;
|
||||
|
||||
-- Mar 13, 2019 7:30:30 PM CET
|
||||
ALTER TABLE AD_PInstance_Para MODIFY P_String_To VARCHAR2(2000) DEFAULT NULL
|
||||
;
|
||||
|
||||
SELECT register_migration_script('201903131326_IDEMPIERE-3916.sql') FROM dual
|
||||
;
|
||||
|
|
@ -0,0 +1,282 @@
|
|||
-- IDEMPIERE-3916 Process to move client between databases
|
||||
-- Mar 13, 2019 1:17:24 PM CET
|
||||
INSERT INTO AD_Process (AD_Process_ID,AD_Client_ID,AD_Org_ID,IsActive,Created,CreatedBy,Updated,UpdatedBy,Name,Description,IsReport,Value,IsDirectPrint,Classname,AccessLevel,EntityType,Statistic_Count,Statistic_Seconds,IsBetaFunctionality,IsServerProcess,ShowHelp,CopyFromProcess,AD_Process_UU) VALUES (200110,0,0,'Y',TO_TIMESTAMP('2019-03-13 13:17:24','YYYY-MM-DD HH24:MI:SS'),100,TO_TIMESTAMP('2019-03-13 13:17:24','YYYY-MM-DD HH24:MI:SS'),100,'Move Client','Process to move a client from an external database to current','N','MoveClient','N','org.idempiere.process.MoveClient','4','D',0,0,'N','N','Y','N','365a132a-7b8e-4f0f-b1d3-70db173df7f9')
|
||||
;
|
||||
|
||||
-- Mar 13, 2019 1:17:54 PM CET
|
||||
INSERT INTO AD_Menu (AD_Menu_ID,Name,Description,"action",AD_Client_ID,AD_Org_ID,IsActive,Created,CreatedBy,Updated,UpdatedBy,IsSummary,AD_Process_ID,IsSOTrx,IsReadOnly,EntityType,IsCentrallyMaintained,AD_Menu_UU) VALUES (200168,'Move Client','Process to move a client from an external database to current','P',0,0,'Y',TO_TIMESTAMP('2019-03-13 13:17:53','YYYY-MM-DD HH24:MI:SS'),100,TO_TIMESTAMP('2019-03-13 13:17:53','YYYY-MM-DD HH24:MI:SS'),100,'N',200110,'Y','N','D','Y','63aa38c7-b332-42d3-813e-912389e4f767')
|
||||
;
|
||||
|
||||
-- Mar 13, 2019 1:17:54 PM CET
|
||||
INSERT INTO AD_TreeNodeMM (AD_Client_ID,AD_Org_ID, IsActive,Created,CreatedBy,Updated,UpdatedBy, AD_Tree_ID, Node_ID, Parent_ID, SeqNo, AD_TreeNodeMM_UU) SELECT t.AD_Client_ID, 0, 'Y', statement_timestamp(), 100, statement_timestamp(), 100,t.AD_Tree_ID, 200168, 0, 999, Generate_UUID() FROM AD_Tree t WHERE t.AD_Client_ID=0 AND t.IsActive='Y' AND t.IsAllNodes='Y' AND t.TreeType='MM' AND NOT EXISTS (SELECT * FROM AD_TreeNodeMM e WHERE e.AD_Tree_ID=t.AD_Tree_ID AND Node_ID=200168)
|
||||
;
|
||||
|
||||
-- Mar 13, 2019 1:18:30 PM CET
|
||||
UPDATE AD_TreeNodeMM SET Parent_ID=0, SeqNo=0, Updated=statement_timestamp() WHERE AD_Tree_ID=10 AND Node_ID=218
|
||||
;
|
||||
|
||||
-- Mar 13, 2019 1:18:30 PM CET
|
||||
UPDATE AD_TreeNodeMM SET Parent_ID=0, SeqNo=1, Updated=statement_timestamp() WHERE AD_Tree_ID=10 AND Node_ID=153
|
||||
;
|
||||
|
||||
-- Mar 13, 2019 1:18:30 PM CET
|
||||
UPDATE AD_TreeNodeMM SET Parent_ID=0, SeqNo=2, Updated=statement_timestamp() WHERE AD_Tree_ID=10 AND Node_ID=263
|
||||
;
|
||||
|
||||
-- Mar 13, 2019 1:18:30 PM CET
|
||||
UPDATE AD_TreeNodeMM SET Parent_ID=0, SeqNo=3, Updated=statement_timestamp() WHERE AD_Tree_ID=10 AND Node_ID=166
|
||||
;
|
||||
|
||||
-- Mar 13, 2019 1:18:30 PM CET
|
||||
UPDATE AD_TreeNodeMM SET Parent_ID=0, SeqNo=4, Updated=statement_timestamp() WHERE AD_Tree_ID=10 AND Node_ID=203
|
||||
;
|
||||
|
||||
-- Mar 13, 2019 1:18:30 PM CET
|
||||
UPDATE AD_TreeNodeMM SET Parent_ID=0, SeqNo=5, Updated=statement_timestamp() WHERE AD_Tree_ID=10 AND Node_ID=53242
|
||||
;
|
||||
|
||||
-- Mar 13, 2019 1:18:30 PM CET
|
||||
UPDATE AD_TreeNodeMM SET Parent_ID=0, SeqNo=6, Updated=statement_timestamp() WHERE AD_Tree_ID=10 AND Node_ID=1000016
|
||||
;
|
||||
|
||||
-- Mar 13, 2019 1:18:30 PM CET
|
||||
UPDATE AD_TreeNodeMM SET Parent_ID=0, SeqNo=7, Updated=statement_timestamp() WHERE AD_Tree_ID=10 AND Node_ID=236
|
||||
;
|
||||
|
||||
-- Mar 13, 2019 1:18:30 PM CET
|
||||
UPDATE AD_TreeNodeMM SET Parent_ID=0, SeqNo=8, Updated=statement_timestamp() WHERE AD_Tree_ID=10 AND Node_ID=183
|
||||
;
|
||||
|
||||
-- Mar 13, 2019 1:18:30 PM CET
|
||||
UPDATE AD_TreeNodeMM SET Parent_ID=0, SeqNo=9, Updated=statement_timestamp() WHERE AD_Tree_ID=10 AND Node_ID=160
|
||||
;
|
||||
|
||||
-- Mar 13, 2019 1:18:30 PM CET
|
||||
UPDATE AD_TreeNodeMM SET Parent_ID=0, SeqNo=10, Updated=statement_timestamp() WHERE AD_Tree_ID=10 AND Node_ID=278
|
||||
;
|
||||
|
||||
-- Mar 13, 2019 1:18:30 PM CET
|
||||
UPDATE AD_TreeNodeMM SET Parent_ID=0, SeqNo=11, Updated=statement_timestamp() WHERE AD_Tree_ID=10 AND Node_ID=345
|
||||
;
|
||||
|
||||
-- Mar 13, 2019 1:18:30 PM CET
|
||||
UPDATE AD_TreeNodeMM SET Parent_ID=0, SeqNo=12, Updated=statement_timestamp() WHERE AD_Tree_ID=10 AND Node_ID=53296
|
||||
;
|
||||
|
||||
-- Mar 13, 2019 1:18:30 PM CET
|
||||
UPDATE AD_TreeNodeMM SET Parent_ID=0, SeqNo=13, Updated=statement_timestamp() WHERE AD_Tree_ID=10 AND Node_ID=53014
|
||||
;
|
||||
|
||||
-- Mar 13, 2019 1:18:30 PM CET
|
||||
UPDATE AD_TreeNodeMM SET Parent_ID=0, SeqNo=14, Updated=statement_timestamp() WHERE AD_Tree_ID=10 AND Node_ID=53108
|
||||
;
|
||||
|
||||
-- Mar 13, 2019 1:18:30 PM CET
|
||||
UPDATE AD_TreeNodeMM SET Parent_ID=0, SeqNo=15, Updated=statement_timestamp() WHERE AD_Tree_ID=10 AND Node_ID=1000036
|
||||
;
|
||||
|
||||
-- Mar 13, 2019 1:18:30 PM CET
|
||||
UPDATE AD_TreeNodeMM SET Parent_ID=0, SeqNo=16, Updated=statement_timestamp() WHERE AD_Tree_ID=10 AND Node_ID=1000095
|
||||
;
|
||||
|
||||
-- Mar 13, 2019 1:18:30 PM CET
|
||||
UPDATE AD_TreeNodeMM SET Parent_ID=155, SeqNo=0, Updated=statement_timestamp() WHERE AD_Tree_ID=10 AND Node_ID=161
|
||||
;
|
||||
|
||||
-- Mar 13, 2019 1:18:30 PM CET
|
||||
UPDATE AD_TreeNodeMM SET Parent_ID=155, SeqNo=1, Updated=statement_timestamp() WHERE AD_Tree_ID=10 AND Node_ID=367
|
||||
;
|
||||
|
||||
-- Mar 13, 2019 1:18:30 PM CET
|
||||
UPDATE AD_TreeNodeMM SET Parent_ID=155, SeqNo=2, Updated=statement_timestamp() WHERE AD_Tree_ID=10 AND Node_ID=456
|
||||
;
|
||||
|
||||
-- Mar 13, 2019 1:18:30 PM CET
|
||||
UPDATE AD_TreeNodeMM SET Parent_ID=155, SeqNo=3, Updated=statement_timestamp() WHERE AD_Tree_ID=10 AND Node_ID=501
|
||||
;
|
||||
|
||||
-- Mar 13, 2019 1:18:30 PM CET
|
||||
UPDATE AD_TreeNodeMM SET Parent_ID=155, SeqNo=4, Updated=statement_timestamp() WHERE AD_Tree_ID=10 AND Node_ID=326
|
||||
;
|
||||
|
||||
-- Mar 13, 2019 1:18:30 PM CET
|
||||
UPDATE AD_TreeNodeMM SET Parent_ID=155, SeqNo=5, Updated=statement_timestamp() WHERE AD_Tree_ID=10 AND Node_ID=566
|
||||
;
|
||||
|
||||
-- Mar 13, 2019 1:18:30 PM CET
|
||||
UPDATE AD_TreeNodeMM SET Parent_ID=155, SeqNo=6, Updated=statement_timestamp() WHERE AD_Tree_ID=10 AND Node_ID=392
|
||||
;
|
||||
|
||||
-- Mar 13, 2019 1:18:30 PM CET
|
||||
UPDATE AD_TreeNodeMM SET Parent_ID=155, SeqNo=7, Updated=statement_timestamp() WHERE AD_Tree_ID=10 AND Node_ID=113
|
||||
;
|
||||
|
||||
-- Mar 13, 2019 1:18:30 PM CET
|
||||
UPDATE AD_TreeNodeMM SET Parent_ID=155, SeqNo=8, Updated=statement_timestamp() WHERE AD_Tree_ID=10 AND Node_ID=220
|
||||
;
|
||||
|
||||
-- Mar 13, 2019 1:18:30 PM CET
|
||||
UPDATE AD_TreeNodeMM SET Parent_ID=155, SeqNo=9, Updated=statement_timestamp() WHERE AD_Tree_ID=10 AND Node_ID=351
|
||||
;
|
||||
|
||||
-- Mar 13, 2019 1:18:30 PM CET
|
||||
UPDATE AD_TreeNodeMM SET Parent_ID=155, SeqNo=10, Updated=statement_timestamp() WHERE AD_Tree_ID=10 AND Node_ID=289
|
||||
;
|
||||
|
||||
-- Mar 13, 2019 1:18:30 PM CET
|
||||
UPDATE AD_TreeNodeMM SET Parent_ID=155, SeqNo=11, Updated=statement_timestamp() WHERE AD_Tree_ID=10 AND Node_ID=302
|
||||
;
|
||||
|
||||
-- Mar 13, 2019 1:18:30 PM CET
|
||||
UPDATE AD_TreeNodeMM SET Parent_ID=155, SeqNo=12, Updated=statement_timestamp() WHERE AD_Tree_ID=10 AND Node_ID=200168
|
||||
;
|
||||
|
||||
-- Mar 13, 2019 1:18:30 PM CET
|
||||
UPDATE AD_TreeNodeMM SET Parent_ID=155, SeqNo=13, Updated=statement_timestamp() WHERE AD_Tree_ID=10 AND Node_ID=303
|
||||
;
|
||||
|
||||
-- Mar 13, 2019 1:18:30 PM CET
|
||||
UPDATE AD_TreeNodeMM SET Parent_ID=155, SeqNo=14, Updated=statement_timestamp() WHERE AD_Tree_ID=10 AND Node_ID=200047
|
||||
;
|
||||
|
||||
-- Mar 13, 2019 1:18:30 PM CET
|
||||
UPDATE AD_TreeNodeMM SET Parent_ID=155, SeqNo=15, Updated=statement_timestamp() WHERE AD_Tree_ID=10 AND Node_ID=200048
|
||||
;
|
||||
|
||||
-- Mar 13, 2019 1:18:30 PM CET
|
||||
UPDATE AD_TreeNodeMM SET Parent_ID=155, SeqNo=16, Updated=statement_timestamp() WHERE AD_Tree_ID=10 AND Node_ID=321
|
||||
;
|
||||
|
||||
-- Mar 13, 2019 1:18:30 PM CET
|
||||
UPDATE AD_TreeNodeMM SET Parent_ID=155, SeqNo=17, Updated=statement_timestamp() WHERE AD_Tree_ID=10 AND Node_ID=461
|
||||
;
|
||||
|
||||
-- Mar 13, 2019 1:18:30 PM CET
|
||||
UPDATE AD_TreeNodeMM SET Parent_ID=155, SeqNo=18, Updated=statement_timestamp() WHERE AD_Tree_ID=10 AND Node_ID=53193
|
||||
;
|
||||
|
||||
-- Mar 13, 2019 1:18:30 PM CET
|
||||
UPDATE AD_TreeNodeMM SET Parent_ID=155, SeqNo=19, Updated=statement_timestamp() WHERE AD_Tree_ID=10 AND Node_ID=53322
|
||||
;
|
||||
|
||||
-- Mar 13, 2019 1:18:30 PM CET
|
||||
UPDATE AD_TreeNodeMM SET Parent_ID=155, SeqNo=20, Updated=statement_timestamp() WHERE AD_Tree_ID=10 AND Node_ID=383
|
||||
;
|
||||
|
||||
-- Mar 13, 2019 1:19:21 PM CET
|
||||
INSERT INTO AD_Element (AD_Element_ID,AD_Client_ID,AD_Org_ID,IsActive,Created,CreatedBy,Updated,UpdatedBy,ColumnName,Name,Description,PrintName,EntityType,AD_Element_UU) VALUES (203294,0,0,'Y',TO_TIMESTAMP('2019-03-13 13:19:21','YYYY-MM-DD HH24:MI:SS'),100,TO_TIMESTAMP('2019-03-13 13:19:21','YYYY-MM-DD HH24:MI:SS'),100,'ClientsToExclude','Clients to Exclude','Comma separated list of client IDs to exclude','Clients to Exclude','D','6e7efabf-8c3c-424a-a22f-ccfcb7ff426d')
|
||||
;
|
||||
|
||||
-- Mar 13, 2019 1:20:08 PM CET
|
||||
INSERT INTO AD_Element (AD_Element_ID,AD_Client_ID,AD_Org_ID,IsActive,Created,CreatedBy,Updated,UpdatedBy,ColumnName,Name,Description,PrintName,EntityType,AD_Element_UU) VALUES (203295,0,0,'Y',TO_TIMESTAMP('2019-03-13 13:20:08','YYYY-MM-DD HH24:MI:SS'),100,TO_TIMESTAMP('2019-03-13 13:20:08','YYYY-MM-DD HH24:MI:SS'),100,'ClientsToInclude','Clients to Include','Comma separated list of client IDs to include','Clients to Include','D','d43df270-66c5-4f08-a3a0-7a9125f2b19a')
|
||||
;
|
||||
|
||||
-- Mar 13, 2019 1:20:21 PM CET
|
||||
INSERT INTO AD_Element (AD_Element_ID,AD_Client_ID,AD_Org_ID,IsActive,Created,CreatedBy,Updated,UpdatedBy,ColumnName,Name,Description,PrintName,EntityType,AD_Element_UU) VALUES (203296,0,0,'Y',TO_TIMESTAMP('2019-03-13 13:20:21','YYYY-MM-DD HH24:MI:SS'),100,TO_TIMESTAMP('2019-03-13 13:20:21','YYYY-MM-DD HH24:MI:SS'),100,'TablesToExclude','Tables to Exclude','Comma separated list of tables to exclude','Tables to Exclude','D','9e56bd23-c125-46a4-a1e7-c126c8398888')
|
||||
;
|
||||
|
||||
-- Mar 13, 2019 1:20:34 PM CET
|
||||
INSERT INTO AD_Element (AD_Element_ID,AD_Client_ID,AD_Org_ID,IsActive,Created,CreatedBy,Updated,UpdatedBy,ColumnName,Name,PrintName,EntityType,AD_Element_UU) VALUES (203297,0,0,'Y',TO_TIMESTAMP('2019-03-13 13:20:34','YYYY-MM-DD HH24:MI:SS'),100,TO_TIMESTAMP('2019-03-13 13:20:34','YYYY-MM-DD HH24:MI:SS'),100,'JDBC_URL','JDBC URL','JDBC URL','D','dcae66f5-4e3c-4ede-9cc1-f590e4e01ff1')
|
||||
;
|
||||
|
||||
-- Mar 13, 2019 1:21:19 PM CET
|
||||
INSERT INTO AD_Process_Para (AD_Process_Para_ID,AD_Client_ID,AD_Org_ID,IsActive,Created,CreatedBy,Updated,UpdatedBy,Name,AD_Process_ID,SeqNo,AD_Reference_ID,IsRange,FieldLength,IsMandatory,ColumnName,IsCentrallyMaintained,EntityType,AD_Element_ID,AD_Process_Para_UU,IsEncrypted) VALUES (200256,0,0,'Y',TO_TIMESTAMP('2019-03-13 13:21:19','YYYY-MM-DD HH24:MI:SS'),100,TO_TIMESTAMP('2019-03-13 13:21:19','YYYY-MM-DD HH24:MI:SS'),100,'JDBC URL',200110,10,10,'N',1000,'Y','JDBC_URL','Y','D',203297,'d85a4590-ebdb-412a-8356-8acd1afc2d58','N')
|
||||
;
|
||||
|
||||
-- Mar 13, 2019 1:21:42 PM CET
|
||||
INSERT INTO AD_Process_Para (AD_Process_Para_ID,AD_Client_ID,AD_Org_ID,IsActive,Created,CreatedBy,Updated,UpdatedBy,Name,AD_Process_ID,SeqNo,AD_Reference_ID,IsRange,FieldLength,IsMandatory,ColumnName,IsCentrallyMaintained,EntityType,AD_Element_ID,AD_Process_Para_UU,IsEncrypted) VALUES (200257,0,0,'Y',TO_TIMESTAMP('2019-03-13 13:21:41','YYYY-MM-DD HH24:MI:SS'),100,TO_TIMESTAMP('2019-03-13 13:21:41','YYYY-MM-DD HH24:MI:SS'),100,'User Name',200110,20,10,'N',100,'N','UserName','Y','D',1903,'47c346a2-5bdf-46e2-baef-43c5b5e4c800','N')
|
||||
;
|
||||
|
||||
-- Mar 13, 2019 1:22:13 PM CET
|
||||
INSERT INTO AD_Process_Para (AD_Process_Para_ID,AD_Client_ID,AD_Org_ID,IsActive,Created,CreatedBy,Updated,UpdatedBy,Name,Description,Help,AD_Process_ID,SeqNo,AD_Reference_ID,IsRange,FieldLength,IsMandatory,ColumnName,IsCentrallyMaintained,EntityType,AD_Element_ID,AD_Process_Para_UU,IsEncrypted) VALUES (200258,0,0,'Y',TO_TIMESTAMP('2019-03-13 13:22:12','YYYY-MM-DD HH24:MI:SS'),100,TO_TIMESTAMP('2019-03-13 13:22:12','YYYY-MM-DD HH24:MI:SS'),100,'Password','Password of any length (case sensitive)','The Password for this User. Passwords are required to identify authorized users. For iDempiere Users, you can change the password via the Process "Reset Password".',200110,30,10,'N',100,'N','Password','Y','D',498,'7e5b47a3-5bd1-4e92-adb7-d58d4a725932','Y')
|
||||
;
|
||||
|
||||
-- Mar 13, 2019 1:22:34 PM CET
|
||||
INSERT INTO AD_Process_Para (AD_Process_Para_ID,AD_Client_ID,AD_Org_ID,IsActive,Created,CreatedBy,Updated,UpdatedBy,Name,Description,AD_Process_ID,SeqNo,AD_Reference_ID,IsRange,FieldLength,IsMandatory,ColumnName,IsCentrallyMaintained,EntityType,AD_Element_ID,AD_Process_Para_UU,IsEncrypted) VALUES (200259,0,0,'Y',TO_TIMESTAMP('2019-03-13 13:22:34','YYYY-MM-DD HH24:MI:SS'),100,TO_TIMESTAMP('2019-03-13 13:22:34','YYYY-MM-DD HH24:MI:SS'),100,'Tables to Exclude','Comma separated list of tables to exclude',200110,40,10,'N',32000,'N','TablesToExclude','Y','D',203296,'25677162-7d62-4319-9c0e-1ff8dfbccf09','N')
|
||||
;
|
||||
|
||||
-- Mar 13, 2019 1:23:04 PM CET
|
||||
INSERT INTO AD_Process_Para (AD_Process_Para_ID,AD_Client_ID,AD_Org_ID,IsActive,Created,CreatedBy,Updated,UpdatedBy,Name,Description,AD_Process_ID,SeqNo,AD_Reference_ID,IsRange,FieldLength,IsMandatory,ColumnName,IsCentrallyMaintained,EntityType,AD_Element_ID,AD_Process_Para_UU,IsEncrypted) VALUES (200260,0,0,'Y',TO_TIMESTAMP('2019-03-13 13:23:04','YYYY-MM-DD HH24:MI:SS'),100,TO_TIMESTAMP('2019-03-13 13:23:04','YYYY-MM-DD HH24:MI:SS'),100,'Clients to Include','Comma separated list of client IDs to include',200110,50,10,'N',32000,'N','ClientsToInclude','Y','D',203295,'3284012a-252f-4410-9a55-ae8f1c121f5a','N')
|
||||
;
|
||||
|
||||
-- Mar 13, 2019 1:23:30 PM CET
|
||||
INSERT INTO AD_Process_Para (AD_Process_Para_ID,AD_Client_ID,AD_Org_ID,IsActive,Created,CreatedBy,Updated,UpdatedBy,Name,Description,AD_Process_ID,SeqNo,AD_Reference_ID,IsRange,FieldLength,IsMandatory,ColumnName,IsCentrallyMaintained,EntityType,AD_Element_ID,AD_Process_Para_UU,IsEncrypted) VALUES (200261,0,0,'Y',TO_TIMESTAMP('2019-03-13 13:23:30','YYYY-MM-DD HH24:MI:SS'),100,TO_TIMESTAMP('2019-03-13 13:23:30','YYYY-MM-DD HH24:MI:SS'),100,'Clients to Exclude','Comma separated list of client IDs to exclude',200110,60,10,'N',32000,'N','ClientsToExclude','Y','D',203294,'cac0280e-0e34-4c66-b055-51276d75821c','N')
|
||||
;
|
||||
|
||||
-- Mar 13, 2019 1:23:54 PM CET
|
||||
INSERT INTO AD_Process_Para (AD_Process_Para_ID,AD_Client_ID,AD_Org_ID,IsActive,Created,CreatedBy,Updated,UpdatedBy,Name,Description,AD_Process_ID,SeqNo,AD_Reference_ID,IsRange,FieldLength,IsMandatory,DefaultValue,ColumnName,IsCentrallyMaintained,EntityType,AD_Element_ID,AD_Process_Para_UU,IsEncrypted) VALUES (200262,0,0,'Y',TO_TIMESTAMP('2019-03-13 13:23:54','YYYY-MM-DD HH24:MI:SS'),100,TO_TIMESTAMP('2019-03-13 13:23:54','YYYY-MM-DD HH24:MI:SS'),100,'Only Validate Data','Validate the date and do not process',200110,70,20,'N',0,'Y','Y','IsValidateOnly','Y','D',2168,'cb303081-dc25-48b1-b6d4-dcf8d17708c2','N')
|
||||
;
|
||||
|
||||
-- Mar 13, 2019 1:24:35 PM CET
|
||||
INSERT INTO AD_Element (AD_Element_ID,AD_Client_ID,AD_Org_ID,IsActive,Created,CreatedBy,Updated,UpdatedBy,ColumnName,Name,PrintName,EntityType,AD_Element_UU) VALUES (203298,0,0,'Y',TO_TIMESTAMP('2019-03-13 13:24:34','YYYY-MM-DD HH24:MI:SS'),100,TO_TIMESTAMP('2019-03-13 13:24:34','YYYY-MM-DD HH24:MI:SS'),100,'IsPreserveIDs','Preserve IDs','Preserve IDs','D','717c4728-0178-499b-a846-e70a790e7f96')
|
||||
;
|
||||
|
||||
-- Mar 13, 2019 1:24:55 PM CET
|
||||
INSERT INTO AD_Process_Para (AD_Process_Para_ID,AD_Client_ID,AD_Org_ID,IsActive,Created,CreatedBy,Updated,UpdatedBy,Name,AD_Process_ID,SeqNo,AD_Reference_ID,IsRange,FieldLength,IsMandatory,DefaultValue,ColumnName,IsCentrallyMaintained,EntityType,AD_Element_ID,AD_Process_Para_UU,IsEncrypted) VALUES (200263,0,0,'Y',TO_TIMESTAMP('2019-03-13 13:24:55','YYYY-MM-DD HH24:MI:SS'),100,TO_TIMESTAMP('2019-03-13 13:24:55','YYYY-MM-DD HH24:MI:SS'),100,'Preserve IDs',200110,80,20,'N',1,'Y','N','IsPreserveIDs','Y','D',203298,'e81f21da-5126-4009-876b-c477315ba0ea','N')
|
||||
;
|
||||
|
||||
-- Mar 13, 2019 1:25:01 PM CET
|
||||
UPDATE AD_Process_Para SET FieldLength=1,Updated=TO_TIMESTAMP('2019-03-13 13:25:01','YYYY-MM-DD HH24:MI:SS'),UpdatedBy=100 WHERE AD_Process_Para_ID=200262
|
||||
;
|
||||
|
||||
-- Mar 13, 2019 6:39:33 PM CET
|
||||
UPDATE AD_Process_Para SET Description='Comma separated list of tables that require to preserve the IDs', AD_Reference_ID=10, FieldLength=32000, IsMandatory='N', DefaultValue=NULL,Updated=TO_TIMESTAMP('2019-03-13 18:39:33','YYYY-MM-DD HH24:MI:SS'),UpdatedBy=100 WHERE AD_Process_Para_ID=200263
|
||||
;
|
||||
|
||||
CREATE TABLE T_MoveClient (AD_PInstance_ID NUMERIC(10), TableName VARCHAR(40), Source_ID NUMERIC(10), Target_ID NUMERIC(10))
|
||||
;
|
||||
|
||||
CREATE UNIQUE INDEX UX_T_MoveClient ON T_MoveClient (AD_PInstance_ID,TableName,Source_ID)
|
||||
;
|
||||
|
||||
-- Mar 13, 2019 7:28:16 PM CET
|
||||
UPDATE AD_Process_Para SET FieldLength=2000,Updated=TO_TIMESTAMP('2019-03-13 19:28:16','YYYY-MM-DD HH24:MI:SS'),UpdatedBy=100 WHERE AD_Process_Para_ID=200259
|
||||
;
|
||||
|
||||
-- Mar 13, 2019 7:28:19 PM CET
|
||||
UPDATE AD_Process_Para SET FieldLength=2000,Updated=TO_TIMESTAMP('2019-03-13 19:28:19','YYYY-MM-DD HH24:MI:SS'),UpdatedBy=100 WHERE AD_Process_Para_ID=200260
|
||||
;
|
||||
|
||||
-- Mar 13, 2019 7:28:22 PM CET
|
||||
UPDATE AD_Process_Para SET FieldLength=2000,Updated=TO_TIMESTAMP('2019-03-13 19:28:22','YYYY-MM-DD HH24:MI:SS'),UpdatedBy=100 WHERE AD_Process_Para_ID=200261
|
||||
;
|
||||
|
||||
-- Mar 13, 2019 7:28:27 PM CET
|
||||
UPDATE AD_Process_Para SET FieldLength=2000,Updated=TO_TIMESTAMP('2019-03-13 19:28:27','YYYY-MM-DD HH24:MI:SS'),UpdatedBy=100 WHERE AD_Process_Para_ID=200263
|
||||
;
|
||||
|
||||
-- Mar 13, 2019 7:29:49 PM CET
|
||||
UPDATE AD_Column SET FieldLength=2000,Updated=TO_TIMESTAMP('2019-03-13 19:29:49','YYYY-MM-DD HH24:MI:SS'),UpdatedBy=100 WHERE AD_Column_ID=5664
|
||||
;
|
||||
|
||||
-- Mar 13, 2019 7:29:51 PM CET
|
||||
INSERT INTO t_alter_column values('ad_pinstance_para','Info','VARCHAR(2000)',null,'NULL')
|
||||
;
|
||||
|
||||
-- Mar 13, 2019 7:29:59 PM CET
|
||||
UPDATE AD_Column SET FieldLength=2000,Updated=TO_TIMESTAMP('2019-03-13 19:29:59','YYYY-MM-DD HH24:MI:SS'),UpdatedBy=100 WHERE AD_Column_ID=5665
|
||||
;
|
||||
|
||||
-- Mar 13, 2019 7:30:00 PM CET
|
||||
INSERT INTO t_alter_column values('ad_pinstance_para','Info_To','VARCHAR(2000)',null,'NULL')
|
||||
;
|
||||
|
||||
-- Mar 13, 2019 7:30:20 PM CET
|
||||
UPDATE AD_Column SET FieldLength=2000,Updated=TO_TIMESTAMP('2019-03-13 19:30:20','YYYY-MM-DD HH24:MI:SS'),UpdatedBy=100 WHERE AD_Column_ID=2791
|
||||
;
|
||||
|
||||
-- Mar 13, 2019 7:30:21 PM CET
|
||||
INSERT INTO t_alter_column values('ad_pinstance_para','P_String','VARCHAR(2000)',null,'NULL')
|
||||
;
|
||||
|
||||
-- Mar 13, 2019 7:30:28 PM CET
|
||||
UPDATE AD_Column SET FieldLength=2000,Updated=TO_TIMESTAMP('2019-03-13 19:30:28','YYYY-MM-DD HH24:MI:SS'),UpdatedBy=100 WHERE AD_Column_ID=2792
|
||||
;
|
||||
|
||||
-- Mar 13, 2019 7:30:30 PM CET
|
||||
INSERT INTO t_alter_column values('ad_pinstance_para','P_String_To','VARCHAR(2000)',null,'NULL')
|
||||
;
|
||||
|
||||
SELECT register_migration_script('201903131326_IDEMPIERE-3916.sql') FROM dual
|
||||
;
|
||||
|
|
@ -0,0 +1,839 @@
|
|||
/***********************************************************************
|
||||
* This file is part of iDempiere ERP Open Source *
|
||||
* http://www.idempiere.org *
|
||||
* *
|
||||
* Copyright (C) Contributors *
|
||||
* *
|
||||
* This program is free software; you can redistribute it and/or *
|
||||
* modify it under the terms of the GNU General Public License *
|
||||
* as published by the Free Software Foundation; either version 2 *
|
||||
* of the License, or (at your option) any later version. *
|
||||
* *
|
||||
* This program is distributed in the hope that it will be useful, *
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
|
||||
* GNU General Public License for more details. *
|
||||
* *
|
||||
* You should have received a copy of the GNU General Public License *
|
||||
* along with this program; if not, write to the Free Software *
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, *
|
||||
* MA 02110-1301, USA. *
|
||||
* *
|
||||
* Contributors: *
|
||||
* - Carlos Ruiz - globalqss *
|
||||
* Sponsored by FH *
|
||||
**********************************************************************/
|
||||
|
||||
package org.idempiere.process;
|
||||
|
||||
import java.sql.Connection;
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.logging.Level;
|
||||
|
||||
import org.adempiere.exceptions.AdempiereException;
|
||||
import org.compiere.db.CConnection;
|
||||
import org.compiere.model.MColumn;
|
||||
import org.compiere.model.MSequence;
|
||||
import org.compiere.model.MTable;
|
||||
import org.compiere.model.Query;
|
||||
import org.compiere.process.ProcessInfoParameter;
|
||||
import org.compiere.process.SvrProcess;
|
||||
import org.compiere.util.AdempiereUserError;
|
||||
import org.compiere.util.DB;
|
||||
import org.compiere.util.DisplayType;
|
||||
import org.compiere.util.Util;
|
||||
|
||||
public class MoveClient extends SvrProcess {
|
||||
|
||||
// Process to move a client from a external database to current
|
||||
|
||||
private String p_JDBC_URL; // JDBC URL of the external database
|
||||
private String p_UserName; // optional to connect to the JDBC URL, if empty use the same as target
|
||||
private String p_Password; // optional to connect to the JDBC URL, if empty use the same as target
|
||||
private String p_TablesToExclude; // optional, comma separated list of tables to exclude
|
||||
private String p_ClientsToInclude; // optional, comma separated list, if empty then all clients >= 1000000 will be moved
|
||||
private String p_ClientsToExclude; // optional, comma separated list of clients to exclude
|
||||
private boolean p_IsValidateOnly; // to do just validation and not execute the process
|
||||
private String p_IsPreserveIDs; // optional, comma separated list of tables that require to preserve IDs
|
||||
|
||||
final static String insertConversionId = "INSERT INTO T_MoveClient (AD_PInstance_ID, TableName, Source_ID, Target_ID) VALUES (?, ?, ?, ?)";
|
||||
|
||||
private Connection externalConn;
|
||||
private StringBuffer p_excludeTablesWhere = new StringBuffer();
|
||||
private StringBuffer p_whereClient = new StringBuffer();
|
||||
private List<String> p_errorList = new ArrayList<String>();
|
||||
private List<String> p_tablesVerifiedList = new ArrayList<String>();
|
||||
private List<String> p_tablesToPreserveIDsList = new ArrayList<String>();
|
||||
private List<String> p_tablesToExcludeList = new ArrayList<String>();
|
||||
private List<String> p_columnsVerifiedList = new ArrayList<String>();
|
||||
private List<String> p_idSystemConversionList = new ArrayList<String>(); // can consume lot of memory but it helps for performance
|
||||
|
||||
@Override
|
||||
protected void prepare() {
|
||||
// defaults
|
||||
p_IsValidateOnly = true;
|
||||
//
|
||||
for (ProcessInfoParameter para : getParameter()) {
|
||||
String name = para.getParameterName();
|
||||
if ("JDBC_URL".equals(name)) {
|
||||
p_JDBC_URL = para.getParameterAsString();
|
||||
} else if ("UserName".equals(name)) {
|
||||
p_UserName = para.getParameterAsString();
|
||||
} else if ("Password".equals(name)) {
|
||||
p_Password = para.getParameterAsString();
|
||||
} else if ("TablesToExclude".equals(name)) {
|
||||
p_TablesToExclude = para.getParameterAsString();
|
||||
} else if ("ClientsToInclude".equals(name)) {
|
||||
p_ClientsToInclude = para.getParameterAsString();
|
||||
} else if ("ClientsToExclude".equals(name)) {
|
||||
p_ClientsToExclude = para.getParameterAsString();
|
||||
} else if ("IsValidateOnly".equals(name)) {
|
||||
p_IsValidateOnly = para.getParameterAsBoolean();
|
||||
} else if ("IsPreserveIDs".equals(name)) {
|
||||
p_IsPreserveIDs = para.getParameterAsString();
|
||||
} else {
|
||||
log.log(Level.SEVERE, "Unknown Parameter: " + name);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String doIt() throws Exception {
|
||||
// validate parameters
|
||||
if (Util.isEmpty(p_JDBC_URL, true))
|
||||
throw new AdempiereException("Fill mandatory JDBC_URL");
|
||||
if (! Util.isEmpty(p_ClientsToInclude, true) && ! Util.isEmpty(p_ClientsToExclude, true))
|
||||
throw new AdempiereException("Clients to exclude and include cannot be used at the same time");
|
||||
if (Util.isEmpty(p_UserName, true))
|
||||
p_UserName = CConnection.get().getDbUid();
|
||||
if (Util.isEmpty(p_Password, true))
|
||||
p_Password = CConnection.get().getDbPwd();
|
||||
|
||||
// Construct the where clauses
|
||||
p_excludeTablesWhere.append("(UPPER(AD_Table.TableName) NOT LIKE 'T|_%' ESCAPE '|'"); // exclude temporary tables
|
||||
if (Util.isEmpty(p_TablesToExclude, true)) {
|
||||
p_excludeTablesWhere.append(")");
|
||||
} else {
|
||||
p_excludeTablesWhere.append(" AND UPPER(TableName) NOT IN (");
|
||||
boolean addComma = false;
|
||||
for (String tableName : p_TablesToExclude.split(",")) {
|
||||
p_tablesToExcludeList.add(tableName.toUpperCase());
|
||||
if (addComma) {
|
||||
p_excludeTablesWhere.append(",");
|
||||
} else {
|
||||
addComma = true;
|
||||
}
|
||||
p_excludeTablesWhere.append(DB.TO_STRING(tableName.toUpperCase()));
|
||||
}
|
||||
p_excludeTablesWhere.append("))");
|
||||
}
|
||||
|
||||
p_whereClient.append("AD_Client.AD_Client_ID NOT IN (0"); // by default exclude System
|
||||
if (! Util.isEmpty(p_ClientsToExclude, true)) {
|
||||
for (String clientStr : p_ClientsToExclude.split(",")) {
|
||||
p_whereClient.append(",");
|
||||
int clientInt;
|
||||
try {
|
||||
clientInt = Integer.parseInt(clientStr);
|
||||
} catch (NumberFormatException e) {
|
||||
throw new AdempiereException("Error in parameter Clients to Exclude, must be a list of integer separated by commas, wrong format: " + clientStr);
|
||||
}
|
||||
p_whereClient.append(clientInt);
|
||||
}
|
||||
}
|
||||
p_whereClient.append(")");
|
||||
if (! Util.isEmpty(p_ClientsToInclude, true)) {
|
||||
p_whereClient.append(" AND AD_Client.AD_Client_ID IN (");
|
||||
boolean addComma = false;
|
||||
for (String clientStr : p_ClientsToInclude.split(",")) {
|
||||
if (addComma) {
|
||||
p_whereClient.append(",");
|
||||
} else {
|
||||
addComma = true;
|
||||
}
|
||||
int clientInt;
|
||||
try {
|
||||
clientInt = Integer.parseInt(clientStr);
|
||||
} catch (NumberFormatException e) {
|
||||
throw new AdempiereException("Error in parameter Clients to Include, must be a list of integer separated by commas, wrong format: " + clientStr);
|
||||
}
|
||||
p_whereClient.append(clientInt);
|
||||
}
|
||||
p_whereClient.append(")");
|
||||
}
|
||||
|
||||
if (! Util.isEmpty(p_IsPreserveIDs, true)) {
|
||||
for (String tableName : p_IsPreserveIDs.split(",")) {
|
||||
p_tablesToPreserveIDsList.add(tableName.toUpperCase());
|
||||
}
|
||||
}
|
||||
|
||||
// Make the connection to external database
|
||||
externalConn = null;
|
||||
try {
|
||||
try {
|
||||
externalConn = DB.getDatabase(p_JDBC_URL).getDriverConnection(p_JDBC_URL, p_UserName, p_Password);
|
||||
} catch (Exception e) {
|
||||
throw new AdempiereException("Could not get a connection to " + p_JDBC_URL + ",\nCause: " + e.getLocalizedMessage());
|
||||
}
|
||||
|
||||
validate();
|
||||
if (p_errorList.size() > 0) {
|
||||
for (String err : p_errorList) {
|
||||
addLog(err);
|
||||
}
|
||||
return "@Error@";
|
||||
}
|
||||
|
||||
if (! p_IsValidateOnly) {
|
||||
moveClient();
|
||||
}
|
||||
} finally {
|
||||
if (externalConn != null)
|
||||
externalConn.close();
|
||||
}
|
||||
|
||||
checkSequences();
|
||||
|
||||
return "@OK@";
|
||||
}
|
||||
|
||||
private void validate() {
|
||||
// validate there are clients to move, and doesn't exist in target
|
||||
StringBuilder sqlValidClientsSB = new StringBuilder()
|
||||
.append("SELECT AD_Client_ID, Value, Name, AD_Client_UU FROM AD_Client WHERE ")
|
||||
.append(p_whereClient)
|
||||
.append(" ORDER BY Value");
|
||||
StringBuilder sqlValidateLocalClient = new StringBuilder()
|
||||
.append("SELECT COUNT(*) FROM AD_Client WHERE Value=? OR Name=? OR AD_Client_UU=?");
|
||||
if (p_tablesToPreserveIDsList.contains("AD_CLIENT")) {
|
||||
sqlValidateLocalClient.append(" OR AD_Client_ID=?");
|
||||
}
|
||||
String sqlValidClients = DB.getDatabase().convertStatement(sqlValidClientsSB.toString());
|
||||
PreparedStatement stmtVC = null;
|
||||
ResultSet rsVC = null;
|
||||
int noClients = 0;
|
||||
try {
|
||||
stmtVC = externalConn.prepareStatement(sqlValidClients, ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY);
|
||||
rsVC = stmtVC.executeQuery();
|
||||
while (rsVC.next()) {
|
||||
noClients++;
|
||||
int clientID = rsVC.getInt(1);
|
||||
String clientValue = rsVC.getString(2);
|
||||
String clientName = rsVC.getString(3);
|
||||
String clientUUID = rsVC.getString(4);
|
||||
int cnt = 0;
|
||||
if (p_tablesToPreserveIDsList.contains("AD_CLIENT")) {
|
||||
cnt = DB.getSQLValueEx(get_TrxName(), sqlValidateLocalClient.toString(), clientValue, clientName, clientUUID, clientID);
|
||||
} else {
|
||||
cnt = DB.getSQLValueEx(get_TrxName(), sqlValidateLocalClient.toString(), clientValue, clientName, clientUUID);
|
||||
}
|
||||
if (cnt > 0) {
|
||||
String msg = "Client " + clientValue + "/" + clientName + " already exists. UUID=" + clientUUID;
|
||||
if (p_tablesToPreserveIDsList.contains("AD_CLIENT")) {
|
||||
msg += ", ID=" + clientID;
|
||||
}
|
||||
p_errorList.add(msg);
|
||||
}
|
||||
}
|
||||
} catch (SQLException e) {
|
||||
throw new AdempiereException("Could not execute external query: " + sqlValidClients + "\nCause = " + e.getLocalizedMessage());
|
||||
} finally {
|
||||
DB.close(rsVC, stmtVC);
|
||||
}
|
||||
if (noClients <= 0) {
|
||||
throw new AdempiereUserError("No clients to move");
|
||||
}
|
||||
if (p_errorList.size() > 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
// validate if there are attachments using external storage provider - inform not implemented yet (blocking)
|
||||
if (! p_excludeTablesWhere.toString().contains("'AD_ATTACHMENT'")) {
|
||||
statusUpdate("Checking storage for attachments");
|
||||
StringBuilder sqlExternalAttachment = new StringBuilder()
|
||||
.append("SELECT COUNT(*) FROM AD_Attachment")
|
||||
.append(" JOIN AD_Client ON (AD_Attachment.AD_Client_ID=AD_Client.AD_Client_ID)")
|
||||
.append(" JOIN AD_ClientInfo ON (AD_Attachment.AD_Client_ID=AD_ClientInfo.AD_Client_ID)")
|
||||
.append(" JOIN AD_Table ON (AD_Attachment.AD_Table_ID=AD_Table.AD_Table_ID)")
|
||||
.append(" LEFT JOIN AD_StorageProvider ON (AD_StorageProvider.AD_StorageProvider_ID=AD_ClientInfo.AD_StorageProvider_ID)")
|
||||
.append(" WHERE AD_StorageProvider.Method IS NOT NULL AND AD_StorageProvider.Method!='DB'")
|
||||
.append(" AND ").append(p_whereClient)
|
||||
.append(" AND ").append(p_excludeTablesWhere);
|
||||
int cntES = countInExternal(sqlExternalAttachment.toString());
|
||||
if (cntES > 0) {
|
||||
throw new AdempiereUserError("There are attachments using external storage provider - that's not implemented yet");
|
||||
}
|
||||
}
|
||||
|
||||
// validate if there are archives using external storage provider - inform not implemented yet (blocking)
|
||||
if (! p_excludeTablesWhere.toString().contains("'AD_ARCHIVE'")) {
|
||||
statusUpdate("Checking storage for archives");
|
||||
StringBuilder sqlExternalArchive = new StringBuilder()
|
||||
.append("SELECT COUNT(*) FROM AD_Archive")
|
||||
.append(" JOIN AD_Client ON (AD_Archive.AD_Client_ID=AD_Client.AD_Client_ID)")
|
||||
.append(" JOIN AD_ClientInfo ON (AD_Archive.AD_Client_ID=AD_ClientInfo.AD_Client_ID)")
|
||||
.append(" JOIN AD_Table ON (AD_Archive.AD_Table_ID=AD_Table.AD_Table_ID)")
|
||||
.append(" LEFT JOIN AD_StorageProvider ON (AD_StorageProvider.AD_StorageProvider_ID=AD_ClientInfo.StorageArchive_ID)")
|
||||
.append(" WHERE AD_StorageProvider.Method IS NOT NULL AND AD_StorageProvider.Method!='DB'")
|
||||
.append(" AND ").append(p_whereClient)
|
||||
.append(" AND ").append(p_excludeTablesWhere);
|
||||
int cntEA = countInExternal(sqlExternalArchive.toString());
|
||||
if (cntEA > 0) {
|
||||
throw new AdempiereUserError("There are archives using external storage provider - that's not implemented yet");
|
||||
}
|
||||
}
|
||||
|
||||
// create list of tables to ignore
|
||||
// validate tables
|
||||
// for each source table not excluded
|
||||
StringBuilder sqlTablesSB = new StringBuilder()
|
||||
.append("SELECT TableName FROM AD_Table WHERE IsActive='Y' AND IsView='N' AND ")
|
||||
.append(p_excludeTablesWhere)
|
||||
.append(" ORDER BY TableName");
|
||||
|
||||
String sqlRemoteTables = DB.getDatabase().convertStatement(sqlTablesSB.toString());
|
||||
PreparedStatement stmtRT = null;
|
||||
ResultSet rsRT = null;
|
||||
try {
|
||||
stmtRT = externalConn.prepareStatement(sqlRemoteTables, ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY);
|
||||
rsRT = stmtRT.executeQuery();
|
||||
while (rsRT.next()) {
|
||||
String tableName = rsRT.getString(1);
|
||||
validateExternalTable(tableName);
|
||||
}
|
||||
} catch (SQLException e) {
|
||||
throw new AdempiereException("Could not execute external query: " + sqlRemoteTables + "\nCause = " + e.getLocalizedMessage());
|
||||
} finally {
|
||||
DB.close(rsRT, stmtRT);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private void validateExternalTable(String tableName) {
|
||||
statusUpdate("Validating table " + tableName);
|
||||
// if table doesn't have client data (taking into account include/exclude) in the source DB
|
||||
// add to the list of tables to ignore
|
||||
// ignore and continue with next table
|
||||
if (! "AD_Client".equalsIgnoreCase(tableName)) {
|
||||
StringBuilder sqlCountData = new StringBuilder()
|
||||
.append("SELECT COUNT(*) FROM ").append(tableName);
|
||||
if ("AD_Attribute_Value".equalsIgnoreCase(tableName)) {
|
||||
sqlCountData.append(" JOIN AD_Attribute ON (AD_Attribute_Value.AD_Attribute_ID=AD_Attribute.AD_Attribute_ID)");
|
||||
sqlCountData.append(" JOIN AD_Client ON (AD_Attribute.AD_Client_ID=AD_Client.AD_Client_ID)");
|
||||
} else if ("AD_PInstance_Log".equalsIgnoreCase(tableName)) {
|
||||
sqlCountData.append(" JOIN AD_PInstance ON (AD_PInstance_Log.AD_PInstance_ID=AD_PInstance.AD_PInstance_ID)");
|
||||
sqlCountData.append(" JOIN AD_Client ON (AD_PInstance.AD_Client_ID=AD_Client.AD_Client_ID)");
|
||||
} else {
|
||||
sqlCountData.append(" JOIN AD_Client ON (").append(tableName).append(".AD_Client_ID=AD_Client.AD_Client_ID)");
|
||||
}
|
||||
sqlCountData.append(" WHERE ").append(p_whereClient);
|
||||
int cntCD = countInExternal(sqlCountData.toString());
|
||||
if (cntCD == 0) {
|
||||
if (log.isLoggable(Level.INFO)) log.info("Ignoring " + tableName + ", doesn't have client data");
|
||||
return;
|
||||
}
|
||||
if (cntCD > 0 && "AD_Attribute_Value".equalsIgnoreCase(tableName)) {
|
||||
throw new AdempiereUserError("Table " + tableName + " has data, migration not supported");
|
||||
}
|
||||
}
|
||||
|
||||
// if table is not present in target
|
||||
// inform blocking as it has client data
|
||||
MTable localTable = MTable.get(getCtx(), tableName);
|
||||
if (localTable == null || localTable.getAD_Table_ID() <= 0) {
|
||||
p_errorList.add("Table " + tableName + " doesn't exist");
|
||||
return;
|
||||
}
|
||||
|
||||
// for each source column
|
||||
final String sqlRemoteColumnsST = ""
|
||||
+ " SELECT AD_Column.ColumnName, AD_Column.AD_Reference_ID, AD_Column.FieldLength"
|
||||
+ " FROM AD_Column"
|
||||
+ " JOIN AD_Table ON (AD_Table.AD_Table_ID=AD_Column.AD_Table_ID)"
|
||||
+ " WHERE UPPER(AD_Table.TableName)=? AND AD_Column.IsActive='Y' AND AD_Column.ColumnSQL IS NULL"
|
||||
+ " ORDER BY AD_Column.ColumnName";
|
||||
String sqlRemoteColumns = DB.getDatabase().convertStatement(sqlRemoteColumnsST);
|
||||
PreparedStatement stmtRC = null;
|
||||
ResultSet rsRC = null;
|
||||
try {
|
||||
stmtRC = externalConn.prepareStatement(sqlRemoteColumns, ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY);
|
||||
stmtRC.setString(1, tableName.toUpperCase());
|
||||
rsRC = stmtRC.executeQuery();
|
||||
while (rsRC.next()) {
|
||||
String columnName = rsRC.getString(1);
|
||||
int refID = rsRC.getInt(2);
|
||||
int length = rsRC.getInt(3);
|
||||
if (columnName.equalsIgnoreCase("AD_Client_ID")) {
|
||||
p_columnsVerifiedList.add(tableName.toUpperCase() + "." + columnName.toUpperCase());
|
||||
} else {
|
||||
validateExternalColumn(tableName, columnName, refID, length);
|
||||
}
|
||||
}
|
||||
} catch (SQLException e) {
|
||||
throw new AdempiereException("Could not execute external query: " + sqlRemoteColumns + "\nCause = " + e.getLocalizedMessage());
|
||||
} finally {
|
||||
DB.close(rsRC, stmtRC);
|
||||
}
|
||||
p_tablesVerifiedList.add(tableName.toUpperCase());
|
||||
}
|
||||
|
||||
private void validateExternalColumn(String tableName, String columnName, int refID, int length) {
|
||||
// inform if column is not present in target (blocking as it has client data)
|
||||
// statusUpdate("Validating column " + tableName + "." + columnName);
|
||||
MColumn localColumn = MColumn.get(getCtx(), tableName, columnName);
|
||||
if (localColumn == null || localColumn.getAD_Column_ID() <= 0) {
|
||||
p_errorList.add("Column " + tableName + "." + columnName + " doesn't exist");
|
||||
return;
|
||||
}
|
||||
|
||||
// inform if db type is different (blocking as it has client data)
|
||||
if (refID <= MTable.MAX_OFFICIAL_ID
|
||||
&& localColumn.getAD_Reference_ID() <= MTable.MAX_OFFICIAL_ID
|
||||
&& refID != localColumn.getAD_Reference_ID()) {
|
||||
p_errorList.add("Column " + tableName + "." + columnName + " has different type in dictionary, external: " + refID + ", local: " + localColumn.getAD_Reference_ID());
|
||||
}
|
||||
|
||||
// inform blocking if lengths are different
|
||||
if (length != localColumn.getFieldLength()) {
|
||||
p_errorList.add("Column " + tableName + "." + columnName + " has different length in dictionary, external: " + length + ", local: " + localColumn.getFieldLength());
|
||||
}
|
||||
|
||||
StringBuilder sqlDataNotNullInColumn = new StringBuilder()
|
||||
.append("SELECT COUNT(*) FROM ").append(tableName)
|
||||
.append(" JOIN AD_Client ON (").append(tableName).append(".AD_Client_ID=AD_Client.AD_Client_ID)")
|
||||
.append(" WHERE ").append(tableName).append(".").append(columnName).append(" IS NOT NULL")
|
||||
.append(" AND ").append(p_whereClient);
|
||||
// validate if unsupported types have data
|
||||
if (refID == DisplayType.SingleSelectionGrid || refID == DisplayType.MultipleSelectionGrid) {
|
||||
int cntMI = countInExternal(sqlDataNotNullInColumn.toString());
|
||||
if (cntMI > 0) {
|
||||
// TODO: Implement ID conversion for multi-ID column types
|
||||
throw new AdempiereUserError("There is data in unsupported Multi-ID column " + tableName + "." + columnName);
|
||||
}
|
||||
}
|
||||
if (refID > MTable.MAX_OFFICIAL_ID) {
|
||||
int cntET = countInExternal(sqlDataNotNullInColumn.toString());
|
||||
if (cntET > 0) {
|
||||
// TODO: Implement support for non-official data types (must implement how to obtain the foreign table with MColumn.getReferenceTableName)
|
||||
throw new AdempiereUserError("There is data in unsupported non-official data type for column " + tableName + "." + columnName);
|
||||
}
|
||||
}
|
||||
|
||||
// when the column is a foreign key
|
||||
String foreignTable = localColumn.getReferenceTableName();
|
||||
if (foreignTable != null
|
||||
&& (foreignTable.equalsIgnoreCase(tableName) || "AD_PInstance_Log".equalsIgnoreCase(tableName))) {
|
||||
foreignTable = "";
|
||||
} else if ("C_BPartner".equalsIgnoreCase(tableName) && "AD_OrgBP_ID".equalsIgnoreCase(columnName)) {
|
||||
// Special case for C_BPartner.AD_OrgBP_ID defined as Button in dictionary
|
||||
foreignTable = "AD_Org";
|
||||
}
|
||||
if (! Util.isEmpty(foreignTable)) {
|
||||
// verify all foreign keys pointing to a different client
|
||||
// if pointing to a different client non-system
|
||||
// inform cross-client data corruption error
|
||||
// if pointing to system
|
||||
// add to list of columns with system foreign keys
|
||||
// inform if the system record is not in target database using uuid - blocking
|
||||
String uuidCol = MTable.getUUIDColumnName(foreignTable);
|
||||
StringBuilder sqlForeignClientSB = new StringBuilder();
|
||||
if ("AD_Ref_List".equalsIgnoreCase(foreignTable)) {
|
||||
sqlForeignClientSB
|
||||
.append("SELECT DISTINCT AD_Ref_List.AD_Client_ID, AD_Ref_List.AD_Ref_List_ID, AD_Ref_List.").append(uuidCol)
|
||||
.append(" FROM ").append(tableName);
|
||||
if (! "AD_Client".equalsIgnoreCase(tableName)) {
|
||||
sqlForeignClientSB.append(" JOIN AD_Client ON (").append(tableName).append(".AD_Client_ID=AD_Client.AD_Client_ID)");
|
||||
}
|
||||
sqlForeignClientSB.append(" JOIN AD_Ref_List ON (").append(tableName).append(".").append(columnName).append("=AD_Ref_List.");
|
||||
if ("AD_Ref_List_ID".equalsIgnoreCase(columnName)) {
|
||||
sqlForeignClientSB.append("AD_Ref_List_ID");
|
||||
} else {
|
||||
sqlForeignClientSB.append("Value");
|
||||
}
|
||||
sqlForeignClientSB.append(" AND AD_Ref_List.AD_Reference_ID=")
|
||||
.append(" (SELECT AD_Column.AD_Reference_Value_ID FROM AD_Column")
|
||||
.append(" JOIN AD_Table ON (AD_Column.AD_Table_ID=AD_Table.AD_Table_ID)")
|
||||
.append(" WHERE UPPER(AD_Table.TableName)='").append(tableName.toUpperCase())
|
||||
.append("' AND UPPER(AD_Column.ColumnName)='").append(columnName.toUpperCase()).append("'))")
|
||||
.append(" WHERE ").append(p_whereClient)
|
||||
.append(" AND ").append(foreignTable).append(".AD_Client_ID!=").append(tableName).append(".AD_Client_ID")
|
||||
.append(" ORDER BY 2");
|
||||
} else {
|
||||
sqlForeignClientSB
|
||||
.append("SELECT DISTINCT ").append(foreignTable).append(".AD_Client_ID, ")
|
||||
.append(foreignTable).append(".").append(foreignTable).append("_ID, ")
|
||||
.append(foreignTable).append(".").append(uuidCol)
|
||||
.append(" FROM ").append(tableName);
|
||||
if (! "AD_Client".equalsIgnoreCase(tableName)) {
|
||||
sqlForeignClientSB.append(" JOIN AD_Client ON (").append(tableName).append(".AD_Client_ID=AD_Client.AD_Client_ID)");
|
||||
}
|
||||
sqlForeignClientSB.append(" JOIN ").append(foreignTable)
|
||||
.append(" ON (").append(tableName).append(".").append(columnName).append("=").append(foreignTable).append(".");
|
||||
if ("AD_Language".equalsIgnoreCase(foreignTable) && !columnName.equalsIgnoreCase("AD_Language_ID")) {
|
||||
sqlForeignClientSB.append("AD_Language");
|
||||
} else if ("AD_EntityType".equalsIgnoreCase(foreignTable) && !columnName.equalsIgnoreCase("AD_EntityType_ID")) {
|
||||
sqlForeignClientSB.append("EntityType");
|
||||
} else {
|
||||
sqlForeignClientSB.append(foreignTable).append("_ID");
|
||||
}
|
||||
sqlForeignClientSB.append(")")
|
||||
.append(" WHERE ").append(p_whereClient)
|
||||
.append(" AND ").append(foreignTable).append(".AD_Client_ID!=").append(tableName).append(".AD_Client_ID")
|
||||
.append(" ORDER BY 2");
|
||||
}
|
||||
String sqlForeignClient = DB.getDatabase().convertStatement(sqlForeignClientSB.toString());
|
||||
PreparedStatement stmtFC = null;
|
||||
ResultSet rsFC = null;
|
||||
try {
|
||||
stmtFC = externalConn.prepareStatement(sqlForeignClient, ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY);
|
||||
rsFC = stmtFC.executeQuery();
|
||||
while (rsFC.next()) {
|
||||
int clientID = rsFC.getInt(1);
|
||||
int foreignID = rsFC.getInt(2);
|
||||
String foreignUU = rsFC.getString(3);
|
||||
if (clientID > 0) {
|
||||
p_errorList.add("Column " + tableName + "." + columnName + " has invalid cross-client reference to client " + clientID + " on ID=" + foreignID);
|
||||
continue;
|
||||
}
|
||||
if (foreignID > MTable.MAX_OFFICIAL_ID) {
|
||||
if (! p_idSystemConversionList.contains(foreignTable.toUpperCase() + "." + foreignID)) {
|
||||
int localID = getFromUUID(foreignTable, uuidCol, tableName, columnName, foreignUU, foreignID);
|
||||
if (localID < 0) {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (SQLException e) {
|
||||
throw new AdempiereException("Could not execute external query: " + sqlForeignClient + "\nCause = " + e.getLocalizedMessage());
|
||||
} finally {
|
||||
DB.close(rsFC, stmtFC);
|
||||
}
|
||||
}
|
||||
// add to the list of verified columns
|
||||
p_columnsVerifiedList.add(tableName.toUpperCase() + "." + columnName.toUpperCase());
|
||||
}
|
||||
|
||||
private int countInExternal(String sql) {
|
||||
int cnt = 0;
|
||||
sql = DB.getDatabase().convertStatement(sql);
|
||||
PreparedStatement stmt = null;
|
||||
ResultSet rs = null;
|
||||
try {
|
||||
stmt = externalConn.prepareStatement(sql, ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY);
|
||||
rs = stmt.executeQuery();
|
||||
if (rs.next())
|
||||
cnt = rs.getInt(1);
|
||||
} catch (SQLException e) {
|
||||
throw new AdempiereException("Could not execute external query: " + sql + "\nCause = " + e.getLocalizedMessage());
|
||||
} finally {
|
||||
DB.close(rs, stmt);
|
||||
}
|
||||
return cnt;
|
||||
}
|
||||
|
||||
private void moveClient() {
|
||||
// first do the validation, process cannot be executed if there are blocking situations
|
||||
// validation construct the list of tables and columns to process
|
||||
// NOTE that the whole process will be done in a single transaction, foreign keys will be validated on commit
|
||||
|
||||
List<MTable> tables = new Query(getCtx(), MTable.Table_Name,
|
||||
"IsView='N' AND " + p_excludeTablesWhere,
|
||||
get_TrxName())
|
||||
.setOnlyActiveRecords(true)
|
||||
.setOrderBy("TableName")
|
||||
.list();
|
||||
|
||||
// create/verify the ID conversions
|
||||
for (MTable table : tables) {
|
||||
String tableName = table.getTableName();
|
||||
if (! p_tablesVerifiedList.contains(tableName.toUpperCase())) {
|
||||
continue;
|
||||
}
|
||||
if (! p_columnsVerifiedList.contains(tableName.toUpperCase() + "." + tableName.toUpperCase() + "_ID")) {
|
||||
continue;
|
||||
}
|
||||
statusUpdate("Converting IDs for table " + tableName);
|
||||
StringBuilder selectVerifyIdSB = new StringBuilder()
|
||||
.append("SELECT ").append(tableName).append("_ID FROM ").append(tableName)
|
||||
.append(" WHERE ").append(tableName).append("_ID=?");
|
||||
StringBuilder selectGetIdsSB = new StringBuilder()
|
||||
.append("SELECT ").append(tableName).append(".").append(tableName).append("_ID FROM ").append(tableName);
|
||||
if (! "AD_Client".equalsIgnoreCase(tableName)) {
|
||||
selectGetIdsSB.append(" JOIN AD_Client ON (").append(tableName).append(".AD_Client_ID=AD_Client.AD_Client_ID)");
|
||||
}
|
||||
selectGetIdsSB.append(" WHERE ").append(p_whereClient)
|
||||
.append(" ORDER BY ").append(tableName).append("_ID");
|
||||
String selectGetIds = DB.getDatabase().convertStatement(selectGetIdsSB.toString());
|
||||
PreparedStatement stmtGI = null;
|
||||
ResultSet rsGI = null;
|
||||
try {
|
||||
stmtGI = externalConn.prepareStatement(selectGetIds, ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY);
|
||||
rsGI = stmtGI.executeQuery();
|
||||
while (rsGI.next()) {
|
||||
int sourceID = rsGI.getInt(1);
|
||||
int targetID = -1;
|
||||
if (p_tablesToPreserveIDsList.contains(tableName.toUpperCase())) {
|
||||
int localID = DB.getSQLValueEx(get_TrxName(), selectVerifyIdSB.toString(), sourceID);
|
||||
if (localID < 0) {
|
||||
targetID = sourceID;
|
||||
} else {
|
||||
throw new AdempiereException("In " + tableName + "." + tableName + "_ID already exist the ID=" + sourceID);
|
||||
}
|
||||
} else {
|
||||
targetID = DB.getNextID(getAD_Client_ID(), tableName, get_TrxName());
|
||||
}
|
||||
if (targetID >= 0) {
|
||||
DB.executeUpdateEx(insertConversionId,
|
||||
new Object[] {getAD_PInstance_ID(), tableName.toUpperCase(), sourceID, targetID},
|
||||
get_TrxName());
|
||||
}
|
||||
}
|
||||
} catch (SQLException e) {
|
||||
throw new AdempiereException("Could not execute external query: " + selectGetIds + "\nCause = " + e.getLocalizedMessage());
|
||||
} finally {
|
||||
DB.close(rsGI, stmtGI);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
try {
|
||||
commitEx(); // commit the T_MoveClient table to analyze potential problems
|
||||
} catch (SQLException e1) {
|
||||
throw new AdempiereException(e1);
|
||||
}
|
||||
|
||||
// get the source data and insert into target converting the IDs
|
||||
for (MTable table : tables) {
|
||||
String tableName = table.getTableName();
|
||||
if (! p_tablesVerifiedList.contains(tableName.toUpperCase())) {
|
||||
continue;
|
||||
}
|
||||
statusUpdate("Inserting data for table " + tableName);
|
||||
StringBuilder valuesSB = new StringBuilder();
|
||||
StringBuilder columnsSB = new StringBuilder();
|
||||
StringBuilder qColumnsSB = new StringBuilder();
|
||||
int ncols = 0;
|
||||
List<MColumn> columns = new ArrayList<MColumn>();
|
||||
for (MColumn column : table.getColumns(false)) {
|
||||
if (!column.isActive() || column.getColumnSQL() != null) {
|
||||
continue;
|
||||
}
|
||||
String columnName = column.getColumnName();
|
||||
if (! p_columnsVerifiedList.contains(tableName.toUpperCase() + "." + columnName.toUpperCase())) {
|
||||
continue;
|
||||
}
|
||||
if (columnsSB.length() > 0) {
|
||||
qColumnsSB.append(",");
|
||||
columnsSB.append(",");
|
||||
valuesSB.append(",");
|
||||
}
|
||||
qColumnsSB.append(tableName).append(".").append(columnName);
|
||||
columnsSB.append(columnName);
|
||||
valuesSB.append("?");
|
||||
columns.add(column);
|
||||
ncols++;
|
||||
}
|
||||
StringBuilder insertSB = new StringBuilder()
|
||||
.append("INSERT INTO ").append(tableName).append("(").append(columnsSB).append(") VALUES (").append(valuesSB).append(")");
|
||||
StringBuilder selectGetDataSB = new StringBuilder()
|
||||
.append("SELECT ").append(qColumnsSB)
|
||||
.append(" FROM ").append(tableName);
|
||||
if ("AD_PInstance_Log".equalsIgnoreCase(tableName)) {
|
||||
selectGetDataSB.append(" JOIN AD_PInstance ON (AD_PInstance_Log.AD_PInstance_ID=AD_PInstance.AD_PInstance_ID)");
|
||||
selectGetDataSB.append(" JOIN AD_Client ON (AD_PInstance.AD_Client_ID=AD_Client.AD_Client_ID)");
|
||||
} else if (! "AD_Client".equalsIgnoreCase(tableName)) {
|
||||
selectGetDataSB.append(" JOIN AD_Client ON (").append(tableName).append(".AD_Client_ID=AD_Client.AD_Client_ID)");
|
||||
}
|
||||
selectGetDataSB.append(" WHERE ").append(p_whereClient);
|
||||
String selectGetData = DB.getDatabase().convertStatement(selectGetDataSB.toString());
|
||||
PreparedStatement stmtGD = null;
|
||||
ResultSet rsGD = null;
|
||||
Object[] parameters = new Object[ncols];
|
||||
try {
|
||||
stmtGD = externalConn.prepareStatement(selectGetData, ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY);
|
||||
rsGD = stmtGD.executeQuery();
|
||||
while (rsGD.next()) {
|
||||
boolean insertRecord = true;
|
||||
for (int i = 0; i < ncols; i++) {
|
||||
MColumn column = columns.get(i);
|
||||
String columnName = column.getColumnName();
|
||||
String convertTable = column.getReferenceTableName();
|
||||
if ((tableName + "_ID").equalsIgnoreCase(columnName)) {
|
||||
convertTable = tableName;
|
||||
} else if ("C_BPartner".equalsIgnoreCase(tableName) && "AD_OrgBP_ID".equalsIgnoreCase(columnName)) {
|
||||
// Special case for C_BPartner.AD_OrgBP_ID defined as Button in dictionary
|
||||
convertTable = "AD_Org";
|
||||
} else if (convertTable != null
|
||||
&& ("AD_Ref_List".equalsIgnoreCase(convertTable)
|
||||
|| "AD_Language".equalsIgnoreCase(columnName)
|
||||
|| "EntityType".equalsIgnoreCase(columnName))) {
|
||||
convertTable = "";
|
||||
} else if ("Record_ID".equalsIgnoreCase(columnName) && table.getColumnIndex("AD_Table_ID") > 0) {
|
||||
// Special case for Record_ID
|
||||
int tableId = rsGD.getInt("AD_Table_ID");
|
||||
if (tableId > 0) {
|
||||
convertTable = getExternalTableName(tableId);
|
||||
} else {
|
||||
convertTable = "";
|
||||
}
|
||||
} else if ("AD_Preference".equalsIgnoreCase(tableName) && "Value".equalsIgnoreCase(columnName)) {
|
||||
// Special case for AD_Preference.Value
|
||||
String att = rsGD.getString("Attribute");
|
||||
if (att.toUpperCase().endsWith("_ID")) {
|
||||
convertTable = att.substring(0, att.length()-3);
|
||||
if ("C_DocTypeTarget".equals(convertTable)) {
|
||||
convertTable = "C_DocType";
|
||||
}
|
||||
} else {
|
||||
convertTable = "";
|
||||
}
|
||||
}
|
||||
if (! Util.isEmpty(convertTable)) {
|
||||
// Foreign - potential ID conversion
|
||||
int id = rsGD.getInt(i + 1);
|
||||
if (rsGD.wasNull()) {
|
||||
parameters[i] = null;
|
||||
} else {
|
||||
if (id >= MTable.MAX_OFFICIAL_ID) {
|
||||
int convertedId = -1;
|
||||
final String query = "SELECT Target_ID FROM T_MoveClient WHERE AD_PInstance_ID=? AND TableName=? AND Source_ID=?";
|
||||
try {
|
||||
convertedId = DB.getSQLValueEx(get_TrxName(),
|
||||
query,
|
||||
getAD_PInstance_ID(), convertTable.toUpperCase(), id);
|
||||
} catch (Exception e) {
|
||||
throw new AdempiereException("Could not execute query: " + query + "\nCause = " + e.getLocalizedMessage());
|
||||
}
|
||||
if (convertedId < 0) {
|
||||
// not found in the table - try to get it again - could be missed in first pass
|
||||
convertedId = getLocalIDFor(convertTable, id);
|
||||
if (convertedId < 0) {
|
||||
if ("Record_ID".equalsIgnoreCase(columnName) && table.getColumnIndex("AD_Table_ID") > 0) {
|
||||
if (p_tablesToExcludeList.contains(convertTable.toUpperCase())) {
|
||||
// record is pointing to a table that is not included, ignore it
|
||||
insertRecord = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
throw new AdempiereException("Found orphan record in " + tableName + "." + columnName + ": " + id + " related to table " + convertTable);
|
||||
}
|
||||
}
|
||||
id = convertedId;
|
||||
}
|
||||
if ("AD_Preference".equalsIgnoreCase(tableName) && "Value".equalsIgnoreCase(columnName)) {
|
||||
parameters[i] = String.valueOf(id);
|
||||
} else {
|
||||
parameters[i] = id;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
parameters[i] = rsGD.getObject(i + 1);
|
||||
if (rsGD.wasNull()) {
|
||||
parameters[i] = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (insertRecord) {
|
||||
try {
|
||||
DB.executeUpdateEx(insertSB.toString(), parameters, get_TrxName());
|
||||
} catch (Exception e) {
|
||||
throw new AdempiereException("Could not execute: " + insertSB + "\nCause = " + e.getLocalizedMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (SQLException e) {
|
||||
throw new AdempiereException("Could not execute external query: " + selectGetData + "\nCause = " + e.getLocalizedMessage());
|
||||
} finally {
|
||||
DB.close(rsGD, stmtGD);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// commit - here it can throw errors because of foreign keys, verify and inform
|
||||
statusUpdate("Committing. Validating foreign keys");
|
||||
try {
|
||||
commitEx();
|
||||
} catch (SQLException e) {
|
||||
throw new AdempiereException("Could not commit,\nCause: " + e.getLocalizedMessage());
|
||||
}
|
||||
}
|
||||
|
||||
private String getExternalTableName(int tableId) {
|
||||
String tableName = null;
|
||||
String sql = DB.getDatabase().convertStatement("SELECT TableName FROM AD_Table WHERE AD_Table_ID=?");
|
||||
PreparedStatement stmt = null;
|
||||
ResultSet rs = null;
|
||||
try {
|
||||
stmt = externalConn.prepareStatement(sql, ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY);
|
||||
stmt.setInt(1, tableId);
|
||||
rs = stmt.executeQuery();
|
||||
if (rs.next())
|
||||
tableName = rs.getString(1);
|
||||
} catch (SQLException e) {
|
||||
throw new AdempiereException("Could not execute external query: " + sql + "\nCause = " + e.getLocalizedMessage());
|
||||
} finally {
|
||||
DB.close(rs, stmt);
|
||||
}
|
||||
return tableName;
|
||||
}
|
||||
|
||||
private void checkSequences() {
|
||||
for (String tableName : p_tablesToPreserveIDsList) {
|
||||
MSequence seq = MSequence.get(getCtx(), tableName, get_TrxName());
|
||||
if (seq != null) {
|
||||
seq.validateTableIDValue(); // ignore output messages
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private int getLocalIDFor(String tableName, int foreignId) {
|
||||
String uuidCol = MTable.getUUIDColumnName(tableName);
|
||||
StringBuilder sqlRemoteUUSB = new StringBuilder()
|
||||
.append("SELECT ").append(uuidCol).append(" FROM ").append(tableName)
|
||||
.append(" WHERE ").append(tableName).append("_ID=?");
|
||||
String sqlRemoteUU = DB.getDatabase().convertStatement(sqlRemoteUUSB.toString());
|
||||
PreparedStatement stmtUU = null;
|
||||
ResultSet rs = null;
|
||||
String remoteUUID = null;
|
||||
try {
|
||||
stmtUU = externalConn.prepareStatement(sqlRemoteUU, ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY);
|
||||
stmtUU.setInt(1, foreignId);
|
||||
rs = stmtUU.executeQuery();
|
||||
if (rs.next())
|
||||
remoteUUID = rs.getString(1);
|
||||
} catch (SQLException e) {
|
||||
throw new AdempiereException("Could not execute external query: " + sqlRemoteUU + "\nCause = " + e.getLocalizedMessage());
|
||||
} finally {
|
||||
DB.close(rs, stmtUU);
|
||||
}
|
||||
int localID = -1;
|
||||
if (remoteUUID != null) {
|
||||
localID = getFromUUID(tableName, uuidCol, null, null, remoteUUID, foreignId);
|
||||
}
|
||||
return localID;
|
||||
}
|
||||
|
||||
private int getFromUUID(String foreignTable, String uuidCol, String tableName, String columnName, String foreignUU, int foreignID) {
|
||||
StringBuilder sqlCheckLocalUU = new StringBuilder()
|
||||
.append("SELECT ").append(foreignTable).append("_ID FROM ").append(foreignTable)
|
||||
.append(" WHERE ").append(uuidCol).append("=?");
|
||||
int localID = DB.getSQLValueEx(get_TrxName(), sqlCheckLocalUU.toString(), foreignUU);
|
||||
if (localID < 0) {
|
||||
p_errorList.add("Column " + tableName + "." + columnName + " has system reference not convertible, "
|
||||
+ foreignTable + "." + uuidCol + "=" + foreignUU);
|
||||
return -1;
|
||||
}
|
||||
DB.executeUpdateEx(insertConversionId,
|
||||
new Object[] {getAD_PInstance_ID(), foreignTable.toUpperCase(), foreignID, localID},
|
||||
get_TrxName());
|
||||
p_idSystemConversionList.add(foreignTable.toUpperCase() + "." + foreignID);
|
||||
return localID;
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue