From 27cf18d1f1f4fac004c3d099249b3fd9d387f143 Mon Sep 17 00:00:00 2001 From: Nicolas Micoud Date: Wed, 15 Jul 2015 08:23:51 -0500 Subject: [PATCH 01/11] IDEMPIERE-2720 Run as Job + EMail : title not translated --- .../src/org/adempiere/webui/apps/AbstractProcessDialog.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/apps/AbstractProcessDialog.java b/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/apps/AbstractProcessDialog.java index 9b855a1fc6..f21892a2fb 100644 --- a/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/apps/AbstractProcessDialog.java +++ b/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/apps/AbstractProcessDialog.java @@ -700,13 +700,13 @@ public abstract class AbstractProcessDialog extends Window implements IProcessUI if (sendEmail) { MClient client = MClient.get(m_ctx, AD_Client_ID); - client.sendEMailAttachments(AD_User_ID, process.getName(), m_pi.getSummary() + " " + m_pi.getLogInfo(), getDownloadFiles()); + client.sendEMailAttachments(AD_User_ID, process.get_Translation("Name", Env.getAD_Language(Env.getCtx())), m_pi.getSummary() + " " + m_pi.getLogInfo(), getDownloadFiles()); } if (createNotice) { MNote note = new MNote(m_ctx, "BackgroundJob", AD_User_ID, null); - note.setTextMsg(process.getName() + "\n" + m_pi.getSummary()); + note.setTextMsg(process.get_Translation("Name", Env.getAD_Language(Env.getCtx())) + "\n" + m_pi.getSummary()); note.setRecord(MPInstance.Table_ID, m_pi.getAD_PInstance_ID()); note.saveEx(); From 1fbe0d67d98067ebeba1784f4bead63b9af675a9 Mon Sep 17 00:00:00 2001 From: Carlos Ruiz Date: Wed, 15 Jul 2015 08:27:19 -0500 Subject: [PATCH 02/11] IDEMPIERE-2720 Run as Job + EMail : title not translated --- .../src/org/compiere/process/ServerProcessCtl.java | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/org.adempiere.base/src/org/compiere/process/ServerProcessCtl.java b/org.adempiere.base/src/org/compiere/process/ServerProcessCtl.java index 3e9caa739f..c8196e3961 100644 --- a/org.adempiere.base/src/org/compiere/process/ServerProcessCtl.java +++ b/org.adempiere.base/src/org/compiere/process/ServerProcessCtl.java @@ -16,6 +16,7 @@ import org.compiere.util.DB; import org.compiere.util.Env; import org.compiere.util.Msg; import org.compiere.util.Trx; +import org.compiere.util.Util; import org.compiere.wf.MWFProcess; public class ServerProcessCtl implements Runnable { @@ -278,7 +279,8 @@ public class ServerProcessCtl implements Runnable { m_pi.setReportingProcess(true); // Start Report ----------------------------------------------- boolean ok = ServerReportCtl.start(m_pi); - m_pi.setSummary("Report", !ok); + String summ = Util.cleanAmp(Msg.getMsg(Env.getCtx(), "Report")); + m_pi.setSummary(summ, !ok); } /********************************************************************** * Process submission From 74e344785715553cfef071ee597be5f305197118 Mon Sep 17 00:00:00 2001 From: Carlos Ruiz Date: Thu, 23 Jul 2015 09:24:58 -0500 Subject: [PATCH 03/11] IDEMPIERE-2629 M_StorageOnHand Qty and Total M_Transaction Qty did not match / integrate peer review from hengsin --- org.adempiere.base/src/org/compiere/model/MProductionLine.java | 3 --- org.adempiere.base/src/org/compiere/model/MStorageOnHand.java | 2 +- .../src/org/compiere/model/MStorageReservation.java | 2 +- 3 files changed, 2 insertions(+), 5 deletions(-) diff --git a/org.adempiere.base/src/org/compiere/model/MProductionLine.java b/org.adempiere.base/src/org/compiere/model/MProductionLine.java index c99d7324a9..959490faf6 100644 --- a/org.adempiere.base/src/org/compiere/model/MProductionLine.java +++ b/org.adempiere.base/src/org/compiere/model/MProductionLine.java @@ -121,7 +121,6 @@ public class MProductionLine extends X_M_ProductionLine { MStorageOnHand storage = MStorageOnHand.getCreate(getCtx(), getM_Locator_ID(), getM_Product_ID(), asi.get_ID(),dateMPolicy, get_TrxName()); storage.addQtyOnHand(getMovementQty()); - storage.load(storage.get_TrxName()); if (log.isLoggable(Level.FINE))log.log(Level.FINE, "Created finished goods line " + getLine()); return errorString.toString(); @@ -180,7 +179,6 @@ public class MProductionLine extends X_M_ProductionLine { } DB.getDatabase().forUpdate(storages[sl], 120); storages[sl].addQtyOnHand(lineQty.negate()); - storages[sl].load(storages[sl].get_TrxName()); qtyToMove = qtyToMove.subtract(lineQty); if (log.isLoggable(Level.FINE))log.log(Level.FINE, getLine() + " Qty moved = " + lineQty + ", Remaining = " + qtyToMove ); } @@ -239,7 +237,6 @@ public class MProductionLine extends X_M_ProductionLine { if (log.isLoggable(Level.FINE))log.log(Level.FINE, "Saved transaction for " + toString()); } storage.addQtyOnHand(lineQty.negate()); - storage.load(storage.get_TrxName()); qtyToMove = qtyToMove.subtract(lineQty); if (log.isLoggable(Level.FINE))log.log(Level.FINE, getLine() + " Qty moved = " + lineQty + ", Remaining = " + qtyToMove ); } diff --git a/org.adempiere.base/src/org/compiere/model/MStorageOnHand.java b/org.adempiere.base/src/org/compiere/model/MStorageOnHand.java index 14bb46a74e..128dd5a274 100644 --- a/org.adempiere.base/src/org/compiere/model/MStorageOnHand.java +++ b/org.adempiere.base/src/org/compiere/model/MStorageOnHand.java @@ -737,7 +737,6 @@ public class MStorageOnHand extends X_M_StorageOnHand } storage.addQtyOnHand(diffQtyOnHand); - storage.load(storage.get_TrxName()); if (storage.getQtyOnHand().signum() == -1) { if (MWarehouse.get(Env.getCtx(), M_Warehouse_ID).isDisallowNegativeInv()) { throw new AdempiereException(Msg.getMsg(ctx, "NegativeInventoryDisallowed")); @@ -760,6 +759,7 @@ public class MStorageOnHand extends X_M_StorageOnHand DB.executeUpdateEx(sql, new Object[] {addition, Env.getAD_User_ID(Env.getCtx()), getM_Product_ID(), getM_Locator_ID(), getM_AttributeSetInstance_ID(), getDateMaterialPolicy()}, get_TrxName()); + load(get_TrxName()); } /************************************************************************** diff --git a/org.adempiere.base/src/org/compiere/model/MStorageReservation.java b/org.adempiere.base/src/org/compiere/model/MStorageReservation.java index 2155a2ac17..1683487e83 100644 --- a/org.adempiere.base/src/org/compiere/model/MStorageReservation.java +++ b/org.adempiere.base/src/org/compiere/model/MStorageReservation.java @@ -249,7 +249,6 @@ public class MStorageReservation extends X_M_StorageReservation { } storage.addQty(diffQty); - storage.load(storage.get_TrxName()); if (s_log.isLoggable(Level.FINE)) { StringBuilder diffText = new StringBuilder("(Qty=").append(diffQty).append(") -> ").append(storage.toString()); s_log.fine(diffText.toString()); @@ -267,6 +266,7 @@ public class MStorageReservation extends X_M_StorageReservation { DB.executeUpdateEx(sql, new Object[] {addition, Env.getAD_User_ID(Env.getCtx()), getM_Product_ID(), getM_Warehouse_ID(), getM_AttributeSetInstance_ID(), isSOTrx()}, get_TrxName()); + load(get_TrxName()); } /** From fad1e4e34bd3b586b7b238166d72e5e2f8a5fc58 Mon Sep 17 00:00:00 2001 From: Carlos Ruiz Date: Thu, 23 Jul 2015 21:00:56 -0500 Subject: [PATCH 04/11] IDEMPIERE-2739 Some exceptions uncaught and hidden in AbstractEventHandler --- .../src/org/adempiere/base/event/AbstractEventHandler.java | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/org.adempiere.base/src/org/adempiere/base/event/AbstractEventHandler.java b/org.adempiere.base/src/org/adempiere/base/event/AbstractEventHandler.java index 937828f7b6..8af7a945ed 100644 --- a/org.adempiere.base/src/org/adempiere/base/event/AbstractEventHandler.java +++ b/org.adempiere.base/src/org/adempiere/base/event/AbstractEventHandler.java @@ -138,7 +138,10 @@ public abstract class AbstractEventHandler implements EventHandler { * @param e */ protected void addError(Event event, Throwable e) { - addErrorMessage(event, e.getLocalizedMessage()); + String msg = e.getLocalizedMessage(); + if (msg == null) + msg = e.toString(); + addErrorMessage(event, msg); } /** From f419cad4f8d533e41f27eecf5e78ac40d36b33de Mon Sep 17 00:00:00 2001 From: sauljabin Date: Mon, 27 Jul 2015 15:34:56 -0500 Subject: [PATCH 05/11] IDEMPIERE-2740 Webservice without session causing no changelog --- .../org/idempiere/adinterface/CompiereService.java | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/org.idempiere.webservices/WEB-INF/src/org/idempiere/adinterface/CompiereService.java b/org.idempiere.webservices/WEB-INF/src/org/idempiere/adinterface/CompiereService.java index bd2852b1c6..23993f2582 100644 --- a/org.idempiere.webservices/WEB-INF/src/org/idempiere/adinterface/CompiereService.java +++ b/org.idempiere.webservices/WEB-INF/src/org/idempiere/adinterface/CompiereService.java @@ -17,9 +17,11 @@ import java.sql.SQLException; import java.sql.Timestamp; import java.text.SimpleDateFormat; import java.util.Properties; +import java.util.UUID; import java.util.logging.Level; import org.adempiere.util.ServerContext; +import org.compiere.model.MSession; import org.compiere.model.MUser; import org.compiere.util.CLogger; import org.compiere.util.DB; @@ -135,6 +137,7 @@ public class CompiereService { { if (m_connected) { + Env.logout(); ServerContext.dispose(); m_ctx = null; m_loggedin = false; @@ -274,6 +277,16 @@ public class CompiereService { Env.setContext( getCtx(), "#M_Warehouse_ID", M_Warehouse_ID ); Env.setContext(m_ctx, Env.LANGUAGE, m_language.getAD_Language()); + // Create session + MSession session = MSession.get (getCtx(), false); + if (session == null){ + log.fine("No Session found"); + session = MSession.get (getCtx(), true); + } + session.setWebSession(UUID.randomUUID().toString()); + session.setDescription(session.getDescription() + " WebService" ); + session.saveEx(); + m_loggedin = true; return true; } From f14c24a608186d57f1151d09bdf10a40cddc4473 Mon Sep 17 00:00:00 2001 From: Carlos Ruiz Date: Mon, 27 Jul 2015 15:38:01 -0500 Subject: [PATCH 06/11] IDEMPIERE-2740 Webservice without session causing no changelog / peer review --- .../src/org/idempiere/adinterface/CompiereService.java | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/org.idempiere.webservices/WEB-INF/src/org/idempiere/adinterface/CompiereService.java b/org.idempiere.webservices/WEB-INF/src/org/idempiere/adinterface/CompiereService.java index 23993f2582..bd01f4651f 100644 --- a/org.idempiere.webservices/WEB-INF/src/org/idempiere/adinterface/CompiereService.java +++ b/org.idempiere.webservices/WEB-INF/src/org/idempiere/adinterface/CompiereService.java @@ -17,7 +17,6 @@ import java.sql.SQLException; import java.sql.Timestamp; import java.text.SimpleDateFormat; import java.util.Properties; -import java.util.UUID; import java.util.logging.Level; import org.adempiere.util.ServerContext; @@ -283,8 +282,7 @@ public class CompiereService { log.fine("No Session found"); session = MSession.get (getCtx(), true); } - session.setWebSession(UUID.randomUUID().toString()); - session.setDescription(session.getDescription() + " WebService" ); + session.setWebSession("WebService"); session.saveEx(); m_loggedin = true; From d67471319f63496d2dec9241fe35e00eceaf5a38 Mon Sep 17 00:00:00 2001 From: hieplq Date: Mon, 20 Jul 2015 02:03:37 +0700 Subject: [PATCH 07/11] IDEMPIERE-1440:line description alignment wrong on document printing --- .../src/org/compiere/print/layout/TableElement.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/org.adempiere.base/src/org/compiere/print/layout/TableElement.java b/org.adempiere.base/src/org/compiere/print/layout/TableElement.java index 92ac9f3c2b..3eb11ad110 100644 --- a/org.adempiere.base/src/org/compiere/print/layout/TableElement.java +++ b/org.adempiere.base/src/org/compiere/print/layout/TableElement.java @@ -1503,7 +1503,7 @@ public class TableElement extends PrintElement if (str.length() > 0) { usedHeight = 0; - String[] lines = Pattern.compile("$", Pattern.MULTILINE).split(str); + String[] lines = Pattern.compile("\n", Pattern.MULTILINE).split(str); for (int lineNo = 0; lineNo < lines.length; lineNo++) { aString = new AttributedString(lines[lineNo]); From d4b9295e704003aff0496ec89cf185e8ab85b70c Mon Sep 17 00:00:00 2001 From: Carlos Ruiz Date: Tue, 28 Jul 2015 20:52:33 -0500 Subject: [PATCH 08/11] IDEMPIERE-1440:line description alignment wrong on document printing / apply same patch from hieplq in other Pattern.compile --- .../src/org/compiere/print/layout/LocationElement.java | 4 ++-- .../src/org/compiere/print/layout/StringElement.java | 6 +++--- .../src/org/compiere/print/layout/TableElement.java | 4 ++-- .../src/org/adempiere/db/oracle/config/ConfigOracle.java | 3 ++- 4 files changed, 9 insertions(+), 8 deletions(-) diff --git a/org.adempiere.base/src/org/compiere/print/layout/LocationElement.java b/org.adempiere.base/src/org/compiere/print/layout/LocationElement.java index 94130b191a..875ae4ae34 100644 --- a/org.adempiere.base/src/org/compiere/print/layout/LocationElement.java +++ b/org.adempiere.base/src/org/compiere/print/layout/LocationElement.java @@ -76,7 +76,7 @@ public class LocationElement extends GridElement else if (ml.isAddressLinesReverse()) { setData(index++, 0, ml.getCountry(true, language), font, color); - String[] lines = Pattern.compile("$", Pattern.MULTILINE).split(ml.getCityRegionPostal()); + String[] lines = Pattern.compile("\n", Pattern.MULTILINE).split(ml.getCityRegionPostal()); for (int i = 0; i < lines.length; i++) setData(index++, 0, lines[i], font, color); if (ml.getAddress4() != null && ml.getAddress4().length() > 0) @@ -98,7 +98,7 @@ public class LocationElement extends GridElement setData(index++, 0, ml.getAddress3(), font, color); if (ml.getAddress4() != null && ml.getAddress4().length() > 0) setData(index++, 0, ml.getAddress4(), font, color); - String[] lines = Pattern.compile("$", Pattern.MULTILINE).split(ml.getCityRegionPostal()); + String[] lines = Pattern.compile("\n", Pattern.MULTILINE).split(ml.getCityRegionPostal()); for (int i = 0; i < lines.length; i++) setData(index++, 0, lines[i], font, color); setData(index++, 0, ml.getCountry(true, language), font, color); diff --git a/org.adempiere.base/src/org/compiere/print/layout/StringElement.java b/org.adempiere.base/src/org/compiere/print/layout/StringElement.java index 6935799597..445d6a5f88 100644 --- a/org.adempiere.base/src/org/compiere/print/layout/StringElement.java +++ b/org.adempiere.base/src/org/compiere/print/layout/StringElement.java @@ -80,7 +80,7 @@ public class StringElement extends PrintElement } } m_ID = ID; - String[] lines = Pattern.compile("$", Pattern.MULTILINE).split(inText); + String[] lines = Pattern.compile("\n", Pattern.MULTILINE).split(inText); m_string_paper = new AttributedString[lines.length]; m_string_view = new AttributedString[lines.length]; for (int i = 0; i < lines.length; i++) @@ -155,7 +155,7 @@ public class StringElement extends PrintElement endOffset = labelSuffix.length(); } m_ID = ID; - String[] lines = Pattern.compile("$", Pattern.MULTILINE).split(text); + String[] lines = Pattern.compile("\n", Pattern.MULTILINE).split(text); m_string_paper = new AttributedString[lines.length]; m_string_view = new AttributedString[lines.length]; for (int i = 0; i < lines.length; i++) @@ -230,7 +230,7 @@ public class StringElement extends PrintElement return; String inText = Msg.parseTranslation(ctx, m_originalString); // log.fine( "StringElement.translate", inText); - String[] lines = Pattern.compile("$", Pattern.MULTILINE).split(inText); + String[] lines = Pattern.compile("\n", Pattern.MULTILINE).split(inText); m_string_paper = new AttributedString[lines.length]; for (int i = 0; i < lines.length; i++) { diff --git a/org.adempiere.base/src/org/compiere/print/layout/TableElement.java b/org.adempiere.base/src/org/compiere/print/layout/TableElement.java index 3eb11ad110..cd1a26b2ba 100644 --- a/org.adempiere.base/src/org/compiere/print/layout/TableElement.java +++ b/org.adempiere.base/src/org/compiere/print/layout/TableElement.java @@ -431,7 +431,7 @@ public class TableElement extends PrintElement } else { - String[] lines = Pattern.compile("$", Pattern.MULTILINE).split(string); + String[] lines = Pattern.compile("\n", Pattern.MULTILINE).split(string); for (int lineNo = 0; lineNo < lines.length; lineNo++) { AttributedString aString = new AttributedString(lines[lineNo]); @@ -503,7 +503,7 @@ public class TableElement extends PrintElement { float height = 0; // - String[] lines = Pattern.compile("$", Pattern.MULTILINE).split(string); + String[] lines = Pattern.compile("\n", Pattern.MULTILINE).split(string); for (int lineNo = 0; lineNo < lines.length; lineNo++) { AttributedString aString = new AttributedString(lines[lineNo]); diff --git a/org.compiere.db.oracle.provider/src/org/adempiere/db/oracle/config/ConfigOracle.java b/org.compiere.db.oracle.provider/src/org/adempiere/db/oracle/config/ConfigOracle.java index 66a2422903..8f0ae3a057 100644 --- a/org.compiere.db.oracle.provider/src/org/adempiere/db/oracle/config/ConfigOracle.java +++ b/org.compiere.db.oracle.provider/src/org/adempiere/db/oracle/config/ConfigOracle.java @@ -247,7 +247,8 @@ public class ConfigOracle implements IDatabaseConfig return null; ArrayList list = new ArrayList(); - Pattern pattern = Pattern.compile("$", Pattern.MULTILINE); + Pattern pattern = Pattern.compile("\n", Pattern.MULTILINE); + System.out.println(tnsnames); String[] lines = pattern.split(tnsnames); for (int i = 0; i < lines.length; i++) { From e5ee78c374a841754cf9b31611e7bb290476dd0d Mon Sep 17 00:00:00 2001 From: hieplq Date: Wed, 29 Jul 2015 19:33:59 +0800 Subject: [PATCH 09/11] IDEMPIERE-2742:Record repeated in info window --- .../WEB-INF/src/org/adempiere/webui/panel/InfoPanel.java | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/panel/InfoPanel.java b/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/panel/InfoPanel.java index 200d07da46..f440765828 100644 --- a/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/panel/InfoPanel.java +++ b/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/panel/InfoPanel.java @@ -619,11 +619,11 @@ public abstract class InfoPanel extends Window implements EventListener, } else { - if (end >= cacheEnd || end <= 0) + if (end > cacheEnd || end <= 0) { - end = cacheEnd-1; + end = cacheEnd; } - return line.subList(start, end+1); + return line.subList(start, end); } } @@ -1344,7 +1344,7 @@ public abstract class InfoPanel extends Window implements EventListener, int start = pageNo * pageSize; int end = start + pageSize; if (end >= m_count) - end = m_count - 1; + end = m_count; List subList = readLine(start, end); model = new ListModelTable(subList); model.setSorter(this); From d63e1b2bd390150dbe20ab6b6a9e9d6c3893063f Mon Sep 17 00:00:00 2001 From: Carlos Ruiz Date: Wed, 29 Jul 2015 08:49:41 -0500 Subject: [PATCH 10/11] IDEMPIERE-2672 Region field in Tax Rate window default OR when default country is not USA --- migration/i2.1/oracle/201507151028_IDEMPIERE-2672.sql | 11 +++++++++++ .../i2.1/postgresql/201507151028_IDEMPIERE-2672.sql | 8 ++++++++ 2 files changed, 19 insertions(+) create mode 100644 migration/i2.1/oracle/201507151028_IDEMPIERE-2672.sql create mode 100644 migration/i2.1/postgresql/201507151028_IDEMPIERE-2672.sql diff --git a/migration/i2.1/oracle/201507151028_IDEMPIERE-2672.sql b/migration/i2.1/oracle/201507151028_IDEMPIERE-2672.sql new file mode 100644 index 0000000000..5b3a94078d --- /dev/null +++ b/migration/i2.1/oracle/201507151028_IDEMPIERE-2672.sql @@ -0,0 +1,11 @@ +SET SQLBLANKLINES ON +SET DEFINE OFF + +-- IDEMPIERE-2672 +-- Jul 15, 2015 10:28:04 AM COT +UPDATE AD_Column SET AD_Reference_ID=30, IsUpdateable='N',Updated=TO_DATE('2015-07-15 10:28:04','YYYY-MM-DD HH24:MI:SS'),UpdatedBy=100 WHERE AD_Column_ID=1809 +; + +SELECT register_migration_script('201507151028_IDEMPIERE-2672.sql') FROM dual +; + diff --git a/migration/i2.1/postgresql/201507151028_IDEMPIERE-2672.sql b/migration/i2.1/postgresql/201507151028_IDEMPIERE-2672.sql new file mode 100644 index 0000000000..856077b2b0 --- /dev/null +++ b/migration/i2.1/postgresql/201507151028_IDEMPIERE-2672.sql @@ -0,0 +1,8 @@ +-- IDEMPIERE-2672 +-- Jul 15, 2015 10:28:04 AM COT +UPDATE AD_Column SET AD_Reference_ID=30, IsUpdateable='N',Updated=TO_TIMESTAMP('2015-07-15 10:28:04','YYYY-MM-DD HH24:MI:SS'),UpdatedBy=100 WHERE AD_Column_ID=1809 +; + +SELECT register_migration_script('201507151028_IDEMPIERE-2672.sql') FROM dual +; + From 1d982987e5aa4a7a05b40d68141fefd2e56c8414 Mon Sep 17 00:00:00 2001 From: Carlos Ruiz Date: Wed, 29 Jul 2015 11:26:32 -0500 Subject: [PATCH 11/11] IDEMPIERE-2745 2Pack is not creating foreign keys --- .../src/org/compiere/process/ColumnSync.java | 146 +----------------- .../src/org/compiere/model/MColumn.java | 145 ++++++++++++++++- .../pipo2/handler/ColumnElementHandler.java | 23 +++ 3 files changed, 168 insertions(+), 146 deletions(-) diff --git a/org.adempiere.base.process/src/org/compiere/process/ColumnSync.java b/org.adempiere.base.process/src/org/compiere/process/ColumnSync.java index 5ba2df5619..2c2d9b88eb 100644 --- a/org.adempiere.base.process/src/org/compiere/process/ColumnSync.java +++ b/org.adempiere.base.process/src/org/compiere/process/ColumnSync.java @@ -20,18 +20,13 @@ import java.math.BigDecimal; import java.sql.Connection; import java.sql.DatabaseMetaData; import java.sql.ResultSet; -import java.util.Enumeration; -import java.util.Hashtable; import java.util.logging.Level; -import org.compiere.model.DatabaseKey; import org.compiere.model.MColumn; import org.compiere.model.MTable; -import org.compiere.model.PO; import org.compiere.util.AdempiereUserError; import org.compiere.util.CLogger; import org.compiere.util.DB; -import org.compiere.util.DisplayType; import org.compiere.util.ValueNamePair; /** @@ -133,14 +128,14 @@ public class ColumnSync extends SvrProcess MColumn[] cols = table.getColumns(false); for (MColumn col : cols) { - String fkConstraintSql = getForeignKeyConstraintSql(md, catalog, schema, tableName, table, col); + String fkConstraintSql = MColumn.getForeignKeyConstraintSql(md, catalog, schema, tableName, table, col); if (fkConstraintSql != null && fkConstraintSql.length() > 0) sql += fkConstraintSql; } } else { - String fkConstraintSql = getForeignKeyConstraintSql(md, catalog, schema, tableName, table, column); + String fkConstraintSql = MColumn.getForeignKeyConstraintSql(md, catalog, schema, tableName, table, column); if (fkConstraintSql != null && fkConstraintSql.length() > 0) sql += fkConstraintSql; } @@ -183,141 +178,4 @@ public class ColumnSync extends SvrProcess } } // doIt - private String getForeignKeyConstraintSql(DatabaseMetaData md, String catalog, String schema, String tableName, MTable table, MColumn column) throws Exception - { - StringBuilder fkConstraintSql = new StringBuilder(); - - if (!column.isKey() && !column.getColumnName().equals(PO.getUUIDColumnName(table.getTableName()))) - { - int refid = column.getAD_Reference_ID(); - if (refid != DisplayType.List && refid != DisplayType.Payment) - { - String referenceTableName = column.getReferenceTableName(); - if (referenceTableName != null) - { - Hashtable htForeignKeys = new Hashtable(); - - if (md.storesUpperCaseIdentifiers()) - referenceTableName = referenceTableName.toUpperCase(); - else if (md.storesLowerCaseIdentifiers()) - referenceTableName = referenceTableName.toLowerCase(); - - ResultSet rs = md.getCrossReference(catalog, schema, referenceTableName, catalog, schema, tableName); - while (rs.next()) - { - String dbFKName = rs.getString("FK_NAME"); - if (dbFKName == null) - continue; - - String dbFKTable = rs.getString("FKTABLE_NAME"); - short deleteRule = rs.getShort("DELETE_RULE"); - - String key = dbFKName.toLowerCase(); - DatabaseKey dbForeignKey = htForeignKeys.get(key); - if (dbForeignKey == null) - dbForeignKey = new DatabaseKey(dbFKName, dbFKTable, new String[30], deleteRule); - - String columnName = rs.getString("FKCOLUMN_NAME"); - int pos = (rs.getShort("KEY_SEQ")); - if (pos > 0) - dbForeignKey.getKeyColumns()[pos-1] = columnName; - - htForeignKeys.put(key, dbForeignKey); - } - rs.close(); - - Enumeration en = htForeignKeys.keys(); - while (en.hasMoreElements()) - { - String key = en.nextElement(); - DatabaseKey dbForeignKey = htForeignKeys.get(key); - if (dbForeignKey.getKeyColumns()[1] != null) - htForeignKeys.remove(key); - } - - boolean modified = false; - en = htForeignKeys.keys(); - while (en.hasMoreElements()) - { - String key = en.nextElement(); - DatabaseKey dbForeignKey = htForeignKeys.get(key); - if (dbForeignKey.getKeyColumns()[0].equalsIgnoreCase(column.getColumnName())) - { - DatabaseKey primaryKey = CreateForeignKey.getPrimaryKey(md, referenceTableName); - if (primaryKey != null) - { - fkConstraintSql.append(DB.SQLSTATEMENT_SEPARATOR); - fkConstraintSql.append("ALTER TABLE ").append(table.getTableName()); - fkConstraintSql.append(" DROP CONSTRAINT ").append(dbForeignKey.getKeyName()); - - String dbDeleteRule = MColumn.FKCONSTRAINTTYPE_NoAction; - if (dbForeignKey.getDeleteRule() == DatabaseMetaData.importedKeyCascade) - dbDeleteRule = MColumn.FKCONSTRAINTTYPE_Cascade; - else if (dbForeignKey.getDeleteRule() == DatabaseMetaData.importedKeySetNull) - dbDeleteRule = MColumn.FKCONSTRAINTTYPE_SetNull; - - String fkConstraintType = column.getFKConstraintType(); - if (fkConstraintType == null) - fkConstraintType = dbDeleteRule; - if (fkConstraintType == null) - fkConstraintType = MColumn.FKCONSTRAINTTYPE_NoAction; - if (!fkConstraintType.equals(MColumn.FKCONSTRAINTTYPE_DoNotCreate)) - { - String fkConstraintName = column.getFKConstraintName(); - if (fkConstraintName == null || fkConstraintName.trim().length() == 0) - fkConstraintName = dbForeignKey.getKeyName(); - - StringBuilder fkConstraint = new StringBuilder(); - fkConstraint.append("CONSTRAINT ").append(fkConstraintName); - fkConstraint.append(" FOREIGN KEY (").append(column.getColumnName()).append(") REFERENCES "); - fkConstraint.append(primaryKey.getKeyTable()).append("(").append(primaryKey.getKeyColumns()[0]); - for (int i = 1; i < primaryKey.getKeyColumns().length; i++) - { - if (primaryKey.getKeyColumns()[i] == null) - break; - fkConstraint.append(", ").append(primaryKey.getKeyColumns()[i]); - } - fkConstraint.append(")"); - - if (fkConstraintType.equals(MColumn.FKCONSTRAINTTYPE_NoAction)) - ; - else if (fkConstraintType.equals(MColumn.FKCONSTRAINTTYPE_Cascade)) - fkConstraint.append(" ON DELETE CASCADE"); - else if (fkConstraintType.equals(MColumn.FKCONSTRAINTTYPE_SetNull)) - fkConstraint.append(" ON DELETE SET NULL"); - - fkConstraint.append(" DEFERRABLE INITIALLY DEFERRED"); - - fkConstraintSql.append(DB.SQLSTATEMENT_SEPARATOR); - fkConstraintSql.append("ALTER TABLE ").append(table.getTableName()); - fkConstraintSql.append(" ADD "); - fkConstraintSql.append(fkConstraint); - - column.setFKConstraintName(fkConstraintName); - column.setFKConstraintType(fkConstraintType); - column.saveEx(); - } - } - modified = true; - break; - } - } - - if (!modified) - { - String fkConstraint = CreateForeignKey.getForeignKeyConstraint(md, table, column); - if (fkConstraint != null && fkConstraint.length() > 0) - { - fkConstraintSql.append(DB.SQLSTATEMENT_SEPARATOR); - fkConstraintSql.append("ALTER TABLE ").append(table.getTableName()); - fkConstraintSql.append(" ADD "); - fkConstraintSql.append(fkConstraint); - } - } - } - } - } - return fkConstraintSql.toString(); - } - } // ColumnSync diff --git a/org.adempiere.base/src/org/compiere/model/MColumn.java b/org.adempiere.base/src/org/compiere/model/MColumn.java index 8e9338a3b5..10c95e5986 100644 --- a/org.adempiere.base/src/org/compiere/model/MColumn.java +++ b/org.adempiere.base/src/org/compiere/model/MColumn.java @@ -17,6 +17,7 @@ package org.compiere.model; import java.math.BigDecimal; +import java.sql.DatabaseMetaData; import java.sql.PreparedStatement; import java.sql.ResultSet; import java.sql.SQLException; @@ -24,11 +25,14 @@ import java.text.DateFormat; import java.text.DecimalFormat; import java.text.NumberFormat; import java.text.SimpleDateFormat; +import java.util.Enumeration; +import java.util.Hashtable; import java.util.Locale; import java.util.Properties; import java.util.logging.Level; import org.adempiere.exceptions.DBException; +import org.compiere.process.CreateForeignKey; import org.compiere.util.CCache; import org.compiere.util.CLogger; import org.compiere.util.DB; @@ -48,7 +52,7 @@ public class MColumn extends X_AD_Column /** * */ - private static final long serialVersionUID = -7470893214933465732L; + private static final long serialVersionUID = -3735608010271317406L; /** * Get MColumn from Cache @@ -835,5 +839,142 @@ public class MColumn extends X_AD_Column MTable table = MTable.get(getCtx(), getAD_Table_ID()); return table; } - + + public static String getForeignKeyConstraintSql(DatabaseMetaData md, String catalog, String schema, String tableName, MTable table, MColumn column) throws Exception + { + StringBuilder fkConstraintSql = new StringBuilder(); + + if (!column.isKey() && !column.getColumnName().equals(PO.getUUIDColumnName(table.getTableName()))) + { + int refid = column.getAD_Reference_ID(); + if (refid != DisplayType.List && refid != DisplayType.Payment) + { + String referenceTableName = column.getReferenceTableName(); + if (referenceTableName != null) + { + Hashtable htForeignKeys = new Hashtable(); + + if (md.storesUpperCaseIdentifiers()) + referenceTableName = referenceTableName.toUpperCase(); + else if (md.storesLowerCaseIdentifiers()) + referenceTableName = referenceTableName.toLowerCase(); + + ResultSet rs = md.getCrossReference(catalog, schema, referenceTableName, catalog, schema, tableName); + while (rs.next()) + { + String dbFKName = rs.getString("FK_NAME"); + if (dbFKName == null) + continue; + + String dbFKTable = rs.getString("FKTABLE_NAME"); + short deleteRule = rs.getShort("DELETE_RULE"); + + String key = dbFKName.toLowerCase(); + DatabaseKey dbForeignKey = htForeignKeys.get(key); + if (dbForeignKey == null) + dbForeignKey = new DatabaseKey(dbFKName, dbFKTable, new String[30], deleteRule); + + String columnName = rs.getString("FKCOLUMN_NAME"); + int pos = (rs.getShort("KEY_SEQ")); + if (pos > 0) + dbForeignKey.getKeyColumns()[pos-1] = columnName; + + htForeignKeys.put(key, dbForeignKey); + } + rs.close(); + + Enumeration en = htForeignKeys.keys(); + while (en.hasMoreElements()) + { + String key = en.nextElement(); + DatabaseKey dbForeignKey = htForeignKeys.get(key); + if (dbForeignKey.getKeyColumns()[1] != null) + htForeignKeys.remove(key); + } + + boolean modified = false; + en = htForeignKeys.keys(); + while (en.hasMoreElements()) + { + String key = en.nextElement(); + DatabaseKey dbForeignKey = htForeignKeys.get(key); + if (dbForeignKey.getKeyColumns()[0].equalsIgnoreCase(column.getColumnName())) + { + DatabaseKey primaryKey = CreateForeignKey.getPrimaryKey(md, referenceTableName); + if (primaryKey != null) + { + fkConstraintSql.append(DB.SQLSTATEMENT_SEPARATOR); + fkConstraintSql.append("ALTER TABLE ").append(table.getTableName()); + fkConstraintSql.append(" DROP CONSTRAINT ").append(dbForeignKey.getKeyName()); + + String dbDeleteRule = MColumn.FKCONSTRAINTTYPE_NoAction; + if (dbForeignKey.getDeleteRule() == DatabaseMetaData.importedKeyCascade) + dbDeleteRule = MColumn.FKCONSTRAINTTYPE_Cascade; + else if (dbForeignKey.getDeleteRule() == DatabaseMetaData.importedKeySetNull) + dbDeleteRule = MColumn.FKCONSTRAINTTYPE_SetNull; + + String fkConstraintType = column.getFKConstraintType(); + if (fkConstraintType == null) + fkConstraintType = dbDeleteRule; + if (fkConstraintType == null) + fkConstraintType = MColumn.FKCONSTRAINTTYPE_NoAction; + if (!fkConstraintType.equals(MColumn.FKCONSTRAINTTYPE_DoNotCreate)) + { + String fkConstraintName = column.getFKConstraintName(); + if (fkConstraintName == null || fkConstraintName.trim().length() == 0) + fkConstraintName = dbForeignKey.getKeyName(); + + StringBuilder fkConstraint = new StringBuilder(); + fkConstraint.append("CONSTRAINT ").append(fkConstraintName); + fkConstraint.append(" FOREIGN KEY (").append(column.getColumnName()).append(") REFERENCES "); + fkConstraint.append(primaryKey.getKeyTable()).append("(").append(primaryKey.getKeyColumns()[0]); + for (int i = 1; i < primaryKey.getKeyColumns().length; i++) + { + if (primaryKey.getKeyColumns()[i] == null) + break; + fkConstraint.append(", ").append(primaryKey.getKeyColumns()[i]); + } + fkConstraint.append(")"); + + if (fkConstraintType.equals(MColumn.FKCONSTRAINTTYPE_NoAction)) + ; + else if (fkConstraintType.equals(MColumn.FKCONSTRAINTTYPE_Cascade)) + fkConstraint.append(" ON DELETE CASCADE"); + else if (fkConstraintType.equals(MColumn.FKCONSTRAINTTYPE_SetNull)) + fkConstraint.append(" ON DELETE SET NULL"); + + fkConstraint.append(" DEFERRABLE INITIALLY DEFERRED"); + + fkConstraintSql.append(DB.SQLSTATEMENT_SEPARATOR); + fkConstraintSql.append("ALTER TABLE ").append(table.getTableName()); + fkConstraintSql.append(" ADD "); + fkConstraintSql.append(fkConstraint); + + column.setFKConstraintName(fkConstraintName); + column.setFKConstraintType(fkConstraintType); + column.saveEx(); + } + } + modified = true; + break; + } + } + + if (!modified) + { + String fkConstraint = CreateForeignKey.getForeignKeyConstraint(md, table, column); + if (fkConstraint != null && fkConstraint.length() > 0) + { + fkConstraintSql.append(DB.SQLSTATEMENT_SEPARATOR); + fkConstraintSql.append("ALTER TABLE ").append(table.getTableName()); + fkConstraintSql.append(" ADD "); + fkConstraintSql.append(fkConstraint); + } + } + } + } + } + return fkConstraintSql.toString(); + } + } // MColumn diff --git a/org.adempiere.pipo.handlers/src/org/adempiere/pipo2/handler/ColumnElementHandler.java b/org.adempiere.pipo.handlers/src/org/adempiere/pipo2/handler/ColumnElementHandler.java index c2b33416d4..22bb37f791 100644 --- a/org.adempiere.pipo.handlers/src/org/adempiere/pipo2/handler/ColumnElementHandler.java +++ b/org.adempiere.pipo.handlers/src/org/adempiere/pipo2/handler/ColumnElementHandler.java @@ -25,6 +25,7 @@ import java.util.logging.Level; import javax.xml.transform.sax.TransformerHandler; +import org.adempiere.exceptions.AdempiereException; import org.adempiere.pipo2.AbstractElementHandler; import org.adempiere.pipo2.Element; import org.adempiere.pipo2.PIPOContext; @@ -228,6 +229,18 @@ public class ColumnElementHandler extends AbstractElementHandler { if (!rst.next()) { // table doesn't exist sql = table.getSQLCreate(); + MColumn[] cols = table.getColumns(false); + for (MColumn col : cols) + { + String fkConstraintSql; + try { + fkConstraintSql = MColumn.getForeignKeyConstraintSql(md, catalog, schema, tableName, table, col); + } catch (Exception e) { + throw new AdempiereException(e); + } + if (fkConstraintSql != null && fkConstraintSql.length() > 0) + sql += fkConstraintSql; + } } else { // rsc = md.getColumns(catalog, schema, tableName, columnName); @@ -243,6 +256,14 @@ public class ColumnElementHandler extends AbstractElementHandler { // No existing column sql = column.getSQLAdd(table); } + String fkConstraintSql; + try { + fkConstraintSql = MColumn.getForeignKeyConstraintSql(md, catalog, schema, tableName, table, column); + } catch (Exception e) { + throw new AdempiereException(e); + } + if (fkConstraintSql != null && fkConstraintSql.length() > 0) + sql += fkConstraintSql; } //execute modify or add if needed @@ -260,6 +281,8 @@ public class ColumnElementHandler extends AbstractElementHandler { } else { String statements[] = sql.split(DB.SQLSTATEMENT_SEPARATOR); for (int i = 0; i < statements.length; i++) { + if ("null".equals(statements[i])) + continue; int ret = DB.executeUpdate(statements[i], false, trx.getTrxName()); if (ret == -1) {