IDEMPIERE-4358 Processes to drop some objects from database (#448)
Add process to rename a column directly from the Table and Column window
This commit is contained in:
parent
4c66c0018d
commit
46bc0e022f
|
@ -0,0 +1,39 @@
|
|||
SET SQLBLANKLINES ON
|
||||
SET DEFINE OFF
|
||||
|
||||
-- IDEMPIERE-4358 Processes to drop some objects from database
|
||||
-- Dec 8, 2020, 9:25:38 PM CET
|
||||
UPDATE AD_Process SET Value='DatabaseElementColumnRename',Classname='org.compiere.process.DatabaseElementColumnRename',Updated=TO_DATE('2020-12-08 21:25:38','YYYY-MM-DD HH24:MI:SS'),UpdatedBy=100 WHERE AD_Process_ID=200124
|
||||
;
|
||||
|
||||
-- Dec 8, 2020, 9:26:37 PM CET
|
||||
INSERT INTO AD_Process (AD_Process_ID,AD_Client_ID,AD_Org_ID,IsActive,Created,CreatedBy,Updated,UpdatedBy,Name,Description,Help,IsReport,Value,IsDirectPrint,Classname,AccessLevel,EntityType,Statistic_Count,Statistic_Seconds,IsBetaFunctionality,IsServerProcess,ShowHelp,CopyFromProcess,AD_Process_UU,AllowMultipleExecution) VALUES (200127,0,0,'Y',TO_DATE('2020-12-08 21:26:37','YYYY-MM-DD HH24:MI:SS'),100,TO_DATE('2020-12-08 21:26:37','YYYY-MM-DD HH24:MI:SS'),100,'Rename Column in Database','Rename Column in Database','This process rename the column on the database','N','DatabaseTableColumnRename','N','org.compiere.process.DatabaseTableColumnRename','4','D',0,0,'N','N','Y','N','b2da47fb-cc79-4d79-a526-d9ca8907ca57','P')
|
||||
;
|
||||
|
||||
-- Dec 8, 2020, 9:32:10 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,IsAutocomplete) VALUES (200334,0,0,'Y',TO_DATE('2020-12-08 21:32:10','YYYY-MM-DD HH24:MI:SS'),100,TO_DATE('2020-12-08 21:32:10','YYYY-MM-DD HH24:MI:SS'),100,'System Element','System Element enables the central maintenance of column description and help.','The System Element allows for the central maintenance of help, descriptions and terminology for a database column.',200127,10,30,'N',10,'Y','AD_Element_ID','Y','D',106,'65d005d9-7211-4806-b3b5-8d8ba51453a8','N','N')
|
||||
;
|
||||
|
||||
-- Dec 8, 2020, 9:33:15 PM CET
|
||||
INSERT INTO AD_ToolBarButton (AD_Client_ID,AD_Org_ID,Created,CreatedBy,ComponentName,IsActive,AD_ToolBarButton_ID,Name,Updated,UpdatedBy,IsCustomization,AD_ToolBarButton_UU,Action,AD_Tab_ID,AD_Process_ID,SeqNo,EntityType) VALUES (0,0,TO_DATE('2020-12-08 21:33:15','YYYY-MM-DD HH24:MI:SS'),100,'DatabaseTableColumnRename','Y',200111,'DatabaseTableColumnRename',TO_DATE('2020-12-08 21:33:15','YYYY-MM-DD HH24:MI:SS'),100,'N','53b26db7-e3bc-43f4-8d35-8c3fd5d36586','W',101,200127,30,'D')
|
||||
;
|
||||
|
||||
-- Dec 8, 2020, 9:44:30 PM CET
|
||||
UPDATE AD_ToolBarButton SET DisplayLogic='@IsView@=N',Updated=TO_DATE('2020-12-08 21:44:30','YYYY-MM-DD HH24:MI:SS'),UpdatedBy=100 WHERE AD_ToolBarButton_ID=200103
|
||||
;
|
||||
|
||||
-- Dec 8, 2020, 9:44:45 PM CET
|
||||
UPDATE AD_ToolBarButton SET DisplayLogic='@IsView@=N',Updated=TO_DATE('2020-12-08 21:44:45','YYYY-MM-DD HH24:MI:SS'),UpdatedBy=100 WHERE AD_ToolBarButton_ID=200104
|
||||
;
|
||||
|
||||
-- Dec 8, 2020, 9:45:17 PM CET
|
||||
UPDATE AD_ToolBarButton SET DisplayLogic='@IsView@=N',Updated=TO_DATE('2020-12-08 21:45:17','YYYY-MM-DD HH24:MI:SS'),UpdatedBy=100 WHERE AD_ToolBarButton_ID=200105
|
||||
;
|
||||
|
||||
-- Dec 8, 2020, 9:45:23 PM CET
|
||||
UPDATE AD_ToolBarButton SET DisplayLogic='@IsView@=N',Updated=TO_DATE('2020-12-08 21:45:23','YYYY-MM-DD HH24:MI:SS'),UpdatedBy=100 WHERE AD_ToolBarButton_ID=200111
|
||||
;
|
||||
|
||||
SELECT register_migration_script('202012082134_IDEMPIERE-4358.sql') FROM dual
|
||||
;
|
||||
|
|
@ -0,0 +1,36 @@
|
|||
-- IDEMPIERE-4358 Processes to drop some objects from database
|
||||
-- Dec 8, 2020, 9:25:38 PM CET
|
||||
UPDATE AD_Process SET Value='DatabaseElementColumnRename',Classname='org.compiere.process.DatabaseElementColumnRename',Updated=TO_TIMESTAMP('2020-12-08 21:25:38','YYYY-MM-DD HH24:MI:SS'),UpdatedBy=100 WHERE AD_Process_ID=200124
|
||||
;
|
||||
|
||||
-- Dec 8, 2020, 9:26:37 PM CET
|
||||
INSERT INTO AD_Process (AD_Process_ID,AD_Client_ID,AD_Org_ID,IsActive,Created,CreatedBy,Updated,UpdatedBy,Name,Description,Help,IsReport,Value,IsDirectPrint,Classname,AccessLevel,EntityType,Statistic_Count,Statistic_Seconds,IsBetaFunctionality,IsServerProcess,ShowHelp,CopyFromProcess,AD_Process_UU,AllowMultipleExecution) VALUES (200127,0,0,'Y',TO_TIMESTAMP('2020-12-08 21:26:37','YYYY-MM-DD HH24:MI:SS'),100,TO_TIMESTAMP('2020-12-08 21:26:37','YYYY-MM-DD HH24:MI:SS'),100,'Rename Column in Database','Rename Column in Database','This process rename the column on the database','N','DatabaseTableColumnRename','N','org.compiere.process.DatabaseTableColumnRename','4','D',0,0,'N','N','Y','N','b2da47fb-cc79-4d79-a526-d9ca8907ca57','P')
|
||||
;
|
||||
|
||||
-- Dec 8, 2020, 9:32:10 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,IsAutocomplete) VALUES (200334,0,0,'Y',TO_TIMESTAMP('2020-12-08 21:32:10','YYYY-MM-DD HH24:MI:SS'),100,TO_TIMESTAMP('2020-12-08 21:32:10','YYYY-MM-DD HH24:MI:SS'),100,'System Element','System Element enables the central maintenance of column description and help.','The System Element allows for the central maintenance of help, descriptions and terminology for a database column.',200127,10,30,'N',10,'Y','AD_Element_ID','Y','D',106,'65d005d9-7211-4806-b3b5-8d8ba51453a8','N','N')
|
||||
;
|
||||
|
||||
-- Dec 8, 2020, 9:33:15 PM CET
|
||||
INSERT INTO AD_ToolBarButton (AD_Client_ID,AD_Org_ID,Created,CreatedBy,ComponentName,IsActive,AD_ToolBarButton_ID,Name,Updated,UpdatedBy,IsCustomization,AD_ToolBarButton_UU,"action",AD_Tab_ID,AD_Process_ID,SeqNo,EntityType) VALUES (0,0,TO_TIMESTAMP('2020-12-08 21:33:15','YYYY-MM-DD HH24:MI:SS'),100,'DatabaseTableColumnRename','Y',200111,'DatabaseTableColumnRename',TO_TIMESTAMP('2020-12-08 21:33:15','YYYY-MM-DD HH24:MI:SS'),100,'N','53b26db7-e3bc-43f4-8d35-8c3fd5d36586','W',101,200127,30,'D')
|
||||
;
|
||||
|
||||
-- Dec 8, 2020, 9:44:30 PM CET
|
||||
UPDATE AD_ToolBarButton SET DisplayLogic='@IsView@=N',Updated=TO_TIMESTAMP('2020-12-08 21:44:30','YYYY-MM-DD HH24:MI:SS'),UpdatedBy=100 WHERE AD_ToolBarButton_ID=200103
|
||||
;
|
||||
|
||||
-- Dec 8, 2020, 9:44:45 PM CET
|
||||
UPDATE AD_ToolBarButton SET DisplayLogic='@IsView@=N',Updated=TO_TIMESTAMP('2020-12-08 21:44:45','YYYY-MM-DD HH24:MI:SS'),UpdatedBy=100 WHERE AD_ToolBarButton_ID=200104
|
||||
;
|
||||
|
||||
-- Dec 8, 2020, 9:45:17 PM CET
|
||||
UPDATE AD_ToolBarButton SET DisplayLogic='@IsView@=N',Updated=TO_TIMESTAMP('2020-12-08 21:45:17','YYYY-MM-DD HH24:MI:SS'),UpdatedBy=100 WHERE AD_ToolBarButton_ID=200105
|
||||
;
|
||||
|
||||
-- Dec 8, 2020, 9:45:23 PM CET
|
||||
UPDATE AD_ToolBarButton SET DisplayLogic='@IsView@=N',Updated=TO_TIMESTAMP('2020-12-08 21:45:23','YYYY-MM-DD HH24:MI:SS'),UpdatedBy=100 WHERE AD_ToolBarButton_ID=200111
|
||||
;
|
||||
|
||||
SELECT register_migration_script('202012082134_IDEMPIERE-4358.sql') FROM dual
|
||||
;
|
||||
|
|
@ -33,7 +33,7 @@ import org.compiere.util.DB;
|
|||
import org.compiere.util.Msg;
|
||||
import org.compiere.util.Util;
|
||||
|
||||
public class DatabaseColumnRename extends SvrProcess {
|
||||
public class DatabaseElementColumnRename extends SvrProcess {
|
||||
|
||||
private int p_AD_Element_ID = 0;
|
||||
// New Column Name
|
||||
|
@ -63,7 +63,7 @@ public class DatabaseColumnRename extends SvrProcess {
|
|||
}
|
||||
// Validate there is not another element with new column name
|
||||
int cnt = DB.getSQLValueEx(get_TrxName(),
|
||||
"SELECT COUNT(*) FROM AD_Element WHERE LOWER(ColumnName)=LOWER(?)",
|
||||
"SELECT COUNT(*) FROM AD_Element WHERE UPPER(ColumnName)=UPPER(?)",
|
||||
p_NewColumnName);
|
||||
if (cnt > 0) {
|
||||
throw new AdempiereException(Util.cleanAmp(Msg.parseTranslation(getCtx(), "@AlreadyExists@: @ColumnName@ = " + p_NewColumnName)));
|
||||
|
@ -81,4 +81,4 @@ public class DatabaseColumnRename extends SvrProcess {
|
|||
|
||||
return "@OK@";
|
||||
}
|
||||
} // DatabaseColumnRename
|
||||
} // DatabaseElementColumnRename
|
|
@ -0,0 +1,85 @@
|
|||
/***********************************************************************
|
||||
* 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 *
|
||||
**********************************************************************/
|
||||
|
||||
package org.compiere.process;
|
||||
|
||||
import java.util.logging.Level;
|
||||
|
||||
import org.adempiere.exceptions.AdempiereException;
|
||||
import org.compiere.model.MColumn;
|
||||
import org.compiere.model.M_Element;
|
||||
import org.compiere.util.DB;
|
||||
import org.compiere.util.Msg;
|
||||
import org.compiere.util.Util;
|
||||
|
||||
public class DatabaseTableColumnRename extends SvrProcess {
|
||||
|
||||
// New Element
|
||||
private int p_AD_Element_ID = 0;
|
||||
// This Column
|
||||
private int p_AD_Column_ID = 0;
|
||||
|
||||
@Override
|
||||
protected void prepare() {
|
||||
for (ProcessInfoParameter para : getParameter()) {
|
||||
String name = para.getParameterName();
|
||||
if ("AD_Element_ID".equals(name)) {
|
||||
p_AD_Element_ID = para.getParameterAsInt();
|
||||
} else {
|
||||
if (log.isLoggable(Level.INFO))
|
||||
log.log(Level.INFO, "Custom Parameter: " + name + "=" + para.getInfo());
|
||||
}
|
||||
}
|
||||
p_AD_Column_ID = getRecord_ID();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String doIt() throws Exception {
|
||||
MColumn column = new MColumn(getCtx(), p_AD_Column_ID, get_TrxName());
|
||||
M_Element element = new M_Element(getCtx(), p_AD_Element_ID, get_TrxName());
|
||||
if (column.getAD_Element_ID() == p_AD_Element_ID || element.getAD_Element_ID() <= 0) {
|
||||
throw new AdempiereException(Util.cleanAmp(Msg.parseTranslation(getCtx(), "@NotValid@: @AD_Element_ID@")));
|
||||
}
|
||||
String newColumnName = element.getColumnName();
|
||||
// Validate there is not another element with new column name
|
||||
int cnt = DB.getSQLValueEx(get_TrxName(),
|
||||
"SELECT COUNT(*) FROM AD_Column WHERE AD_Table_ID=? AND UPPER(ColumnName)=UPPER(?)",
|
||||
column.getAD_Table_ID(), newColumnName);
|
||||
if (cnt > 0) {
|
||||
throw new AdempiereException(Util.cleanAmp(Msg.parseTranslation(getCtx(), "@AlreadyExists@: @ColumnName@ = " + newColumnName)));
|
||||
}
|
||||
|
||||
column.setAD_Element_ID(p_AD_Element_ID);
|
||||
column.setName(element.getName());
|
||||
column.setDescription(element.getDescription());
|
||||
column.setHelp(element.getHelp());
|
||||
column.setPlaceholder(element.getPlaceholder());
|
||||
String msg = column.renameDBColumn(newColumnName);
|
||||
column.saveEx();
|
||||
addLog(msg);
|
||||
|
||||
return "@OK@";
|
||||
}
|
||||
} // DatabaseTableColumnRename
|
Loading…
Reference in New Issue