IDEMPIERE-6035 Use saveCrossTenantSafe instead of PO.setCrossTenantSafe (#2235)

This commit is contained in:
hengsin 2024-02-08 02:39:49 +08:00 committed by Carlos Ruiz
parent 3ac70045f1
commit 61e3e48c9a
8 changed files with 55 additions and 82 deletions

View File

@ -405,12 +405,11 @@ public class MSession extends X_AD_Session implements ImmutablePOSupport
+ ": " + OldValue + " -> " + NewValue); + ": " + OldValue + " -> " + NewValue);
try try
{ {
PO.setCrossTenantSafe();
MChangeLog cl = new MChangeLog(getCtx(), MChangeLog cl = new MChangeLog(getCtx(),
AD_ChangeLog_ID, TrxName, getAD_Session_ID(), AD_ChangeLog_ID, TrxName, getAD_Session_ID(),
AD_Table_ID, AD_Column_ID, Record_ID, Record_UU, AD_Client_ID, AD_Org_ID, AD_Table_ID, AD_Column_ID, Record_ID, Record_UU, AD_Client_ID, AD_Org_ID,
OldValue, NewValue, event); OldValue, NewValue, event);
if (cl.save()) if (cl.saveCrossTenantSafe())
return cl; return cl;
} }
catch (Exception e) catch (Exception e)
@ -420,10 +419,6 @@ public class MSession extends X_AD_Session implements ImmutablePOSupport
+ ", AD_Table_ID=" + AD_Table_ID + ", AD_Column_ID=" + AD_Column_ID, e); + ", AD_Table_ID=" + AD_Table_ID + ", AD_Column_ID=" + AD_Column_ID, e);
return null; return null;
} }
finally
{
PO.clearCrossTenantSafe();
}
log.log(Level.SEVERE, "AD_ChangeLog_ID=" + AD_ChangeLog_ID log.log(Level.SEVERE, "AD_ChangeLog_ID=" + AD_ChangeLog_ID
+ ", AD_Session_ID=" + getAD_Session_ID() + ", AD_Session_ID=" + getAD_Session_ID()
+ ", AD_Table_ID=" + AD_Table_ID + ", AD_Column_ID=" + AD_Column_ID); + ", AD_Table_ID=" + AD_Table_ID + ", AD_Column_ID=" + AD_Column_ID);

View File

@ -2591,7 +2591,24 @@ public abstract class PO
/** /**
* Update Value or create new record, used when writing a cross tenant record * Update Value or create new record, used when writing a cross tenant record
* @throws AdempiereException * @throws AdempiereException
* @see #saveEx(String) * @see #save()
*/
public boolean saveCrossTenantSafe() {
boolean crossTenantSet = isSafeCrossTenant.get();
try {
if (!crossTenantSet)
PO.setCrossTenantSafe();
return save();
} finally {
if (!crossTenantSet)
PO.clearCrossTenantSafe();
}
}
/**
* Update Value or create new record, used when writing a cross tenant record
* @throws AdempiereException
* @see #saveEx()
*/ */
public void saveCrossTenantSafeEx() { public void saveCrossTenantSafeEx() {
boolean crossTenantSet = isSafeCrossTenant.get(); boolean crossTenantSet = isSafeCrossTenant.get();

View File

@ -81,7 +81,6 @@ import org.compiere.model.MRole;
import org.compiere.model.MStatusLine; import org.compiere.model.MStatusLine;
import org.compiere.model.MSysConfig; import org.compiere.model.MSysConfig;
import org.compiere.model.MTable; import org.compiere.model.MTable;
import org.compiere.model.PO;
import org.compiere.print.ReportEngine; import org.compiere.print.ReportEngine;
import org.compiere.process.ProcessInfo; import org.compiere.process.ProcessInfo;
import org.compiere.process.ServerProcessCtl; import org.compiere.process.ServerProcessCtl;
@ -1240,13 +1239,8 @@ public class DashboardController implements EventListener<Event> {
int PA_DashboardPreference_ID = Integer.parseInt(value.toString()); int PA_DashboardPreference_ID = Integer.parseInt(value.toString());
MDashboardPreference preference = new MDashboardPreference(Env.getCtx(), PA_DashboardPreference_ID, null); MDashboardPreference preference = new MDashboardPreference(Env.getCtx(), PA_DashboardPreference_ID, null);
preference.setIsCollapsedByDefault(!panel.isOpen()); preference.setIsCollapsedByDefault(!panel.isOpen());
try { if (!preference.saveCrossTenantSafe())
PO.setCrossTenantSafe();
if (!preference.save())
logger.log(Level.SEVERE, "Failed to save dashboard preference " + preference.toString()); logger.log(Level.SEVERE, "Failed to save dashboard preference " + preference.toString());
} finally {
PO.clearCrossTenantSafe();
}
} }
//notify panel content component //notify panel content component

View File

@ -76,13 +76,8 @@ public class FavouriteController
vTree.setAD_Org_ID(user.getAD_Org_ID()); vTree.setAD_Org_ID(user.getAD_Org_ID());
// Support for System user // Support for System user
vTree.set_ValueNoCheck(MTreeFavorite.COLUMNNAME_AD_User_ID, Integer.valueOf(AD_User_ID)); vTree.set_ValueNoCheck(MTreeFavorite.COLUMNNAME_AD_User_ID, Integer.valueOf(AD_User_ID));
try { if (!vTree.saveCrossTenantSafe())
PO.setCrossTenantSafe();
if (!vTree.save())
throw new AdempiereException(Msg.getMsg(Env.getCtx(), "FavTreeNotCreate")); throw new AdempiereException(Msg.getMsg(Env.getCtx(), "FavTreeNotCreate"));
} finally {
PO.clearCrossTenantSafe();
}
m_AD_Tree_Favorite_ID = vTree.getAD_Tree_Favorite_ID(); m_AD_Tree_Favorite_ID = vTree.getAD_Tree_Favorite_ID();
} }

View File

@ -37,7 +37,6 @@ import org.compiere.model.MPasswordHistory;
import org.compiere.model.MPasswordRule; import org.compiere.model.MPasswordRule;
import org.compiere.model.MSysConfig; import org.compiere.model.MSysConfig;
import org.compiere.model.MUser; import org.compiere.model.MUser;
import org.compiere.model.PO;
import org.compiere.util.CLogger; import org.compiere.util.CLogger;
import org.compiere.util.Env; import org.compiere.util.Env;
import org.compiere.util.KeyNamePair; import org.compiere.util.KeyNamePair;
@ -375,15 +374,10 @@ public class ChangePasswordPanel extends Window implements EventListener<Event>
user.setIsExpired(false); user.setIsExpired(false);
user.setSecurityQuestion(securityQuestion); user.setSecurityQuestion(securityQuestion);
user.setAnswer(answer); user.setAnswer(answer);
try { user.saveCrossTenantSafeEx(trx.getTrxName());
PO.setCrossTenantSafe();
user.saveEx(trx.getTrxName());
if (tenantsChanged.length() > 0) if (tenantsChanged.length() > 0)
tenantsChanged.append(", "); tenantsChanged.append(", ");
tenantsChanged.append(clientKNPair.getName()); tenantsChanged.append(clientKNPair.getName());
} finally {
PO.clearCrossTenantSafe();
}
} }
trx.commit(); trx.commit();

View File

@ -19,7 +19,6 @@ import java.util.Properties;
import org.compiere.model.I_AD_Preference; import org.compiere.model.I_AD_Preference;
import org.compiere.model.MPreference; import org.compiere.model.MPreference;
import org.compiere.model.MUser; import org.compiere.model.MUser;
import org.compiere.model.PO;
import org.compiere.model.Query; import org.compiere.model.Query;
import org.compiere.util.CLogger; import org.compiere.util.CLogger;
import org.compiere.util.Env; import org.compiere.util.Env;
@ -126,13 +125,8 @@ public final class UserPreference implements Serializable {
} }
String oldValue = preference.getValue(); String oldValue = preference.getValue();
if (! value.equals(oldValue)) { if (! value.equals(oldValue)) {
try {
PO.setCrossTenantSafe();
preference.setValue(value); preference.setValue(value);
preference.saveEx(); preference.saveCrossTenantSafeEx();
} finally {
PO.clearCrossTenantSafe();
}
} }
} }
} }

View File

@ -64,7 +64,6 @@ import org.compiere.model.MProduct;
import org.compiere.model.MSysConfig; import org.compiere.model.MSysConfig;
import org.compiere.model.ModelValidationEngine; import org.compiere.model.ModelValidationEngine;
import org.compiere.model.ModelValidator; import org.compiere.model.ModelValidator;
import org.compiere.model.PO;
import org.compiere.model.X_I_BPartner; import org.compiere.model.X_I_BPartner;
import org.compiere.model.X_I_Product; import org.compiere.model.X_I_Product;
import org.compiere.process.DocAction; import org.compiere.process.DocAction;
@ -331,13 +330,8 @@ public class EventHandlerTest extends AbstractTestCase {
MSysConfig sysconfig = new MSysConfig(Env.getCtx(), addressValidationSysConfigId, null); MSysConfig sysconfig = new MSysConfig(Env.getCtx(), addressValidationSysConfigId, null);
String currentValue = sysconfig.getValue(); String currentValue = sysconfig.getValue();
try { try {
try {
PO.setCrossTenantSafe();
sysconfig.setValue("US"); sysconfig.setValue("US");
sysconfig.saveEx(); sysconfig.saveCrossTenantSafeEx();
} finally {
PO.clearCrossTenantSafe();
}
CacheMgt.get().reset(); CacheMgt.get().reset();
@ -357,13 +351,8 @@ public class EventHandlerTest extends AbstractTestCase {
EventManager.getInstance().sendEvent(event); EventManager.getInstance().sendEvent(event);
assertTrue(count.get()==1, "AddressValidationEventDelegate not call for MLocation Before Change Event"); assertTrue(count.get()==1, "AddressValidationEventDelegate not call for MLocation Before Change Event");
} finally { } finally {
try {
PO.setCrossTenantSafe();
sysconfig.setValue(currentValue); sysconfig.setValue(currentValue);
sysconfig.saveEx(); sysconfig.saveCrossTenantSafeEx();
} finally {
PO.clearCrossTenantSafe();
}
} }
} }

View File

@ -56,12 +56,10 @@ public class MInfoWindowTest extends AbstractTestCase {
MInfoWindow infoWindow = new MInfoWindow(Env.getCtx(), 0, getTrxName()); MInfoWindow infoWindow = new MInfoWindow(Env.getCtx(), 0, getTrxName());
MInfoColumn infoColumn1 = new MInfoColumn(Env.getCtx(), 0, getTrxName()); MInfoColumn infoColumn1 = new MInfoColumn(Env.getCtx(), 0, getTrxName());
MInfoColumn infoColumn2 = new MInfoColumn(Env.getCtx(), 0, getTrxName()); MInfoColumn infoColumn2 = new MInfoColumn(Env.getCtx(), 0, getTrxName());
try {
PO.setCrossTenantSafe();
infoWindow.setAD_Table_ID(MTest.Table_ID); infoWindow.setAD_Table_ID(MTest.Table_ID);
infoWindow.setName("testColumnAccess"); infoWindow.setName("testColumnAccess");
infoWindow.setFromClause("Test t"); infoWindow.setFromClause("Test t");
infoWindow.saveEx(); infoWindow.saveCrossTenantSafeEx();
infoColumn1.setAD_InfoWindow_ID(infoWindow.get_ID()); infoColumn1.setAD_InfoWindow_ID(infoWindow.get_ID());
infoColumn1.setName(MTest.COLUMNNAME_T_Amount); infoColumn1.setName(MTest.COLUMNNAME_T_Amount);
@ -70,7 +68,7 @@ public class MInfoWindowTest extends AbstractTestCase {
infoColumn1.setSeqNo(10); infoColumn1.setSeqNo(10);
infoColumn1.setAD_Reference_ID(DisplayType.Amount); infoColumn1.setAD_Reference_ID(DisplayType.Amount);
infoColumn1.setColumnName(MTest.COLUMNNAME_T_Amount); infoColumn1.setColumnName(MTest.COLUMNNAME_T_Amount);
infoColumn1.saveEx(); infoColumn1.saveCrossTenantSafeEx();
infoColumn2.setAD_InfoWindow_ID(infoWindow.get_ID()); infoColumn2.setAD_InfoWindow_ID(infoWindow.get_ID());
infoColumn2.setName(MTest.COLUMNNAME_T_DateTime); infoColumn2.setName(MTest.COLUMNNAME_T_DateTime);
@ -79,10 +77,7 @@ public class MInfoWindowTest extends AbstractTestCase {
infoColumn2.setSeqNo(10); infoColumn2.setSeqNo(10);
infoColumn2.setAD_Reference_ID(DisplayType.DateTime); infoColumn2.setAD_Reference_ID(DisplayType.DateTime);
infoColumn2.setColumnName(MTest.COLUMNNAME_T_DateTime); infoColumn2.setColumnName(MTest.COLUMNNAME_T_DateTime);
infoColumn2.saveEx(); infoColumn2.saveCrossTenantSafeEx();
} finally {
PO.clearCrossTenantSafe();
}
infoWindow.getInfoColumns(true, true); infoWindow.getInfoColumns(true, true);
TableInfo[] tableInfos = infoWindow.getTableInfos(); TableInfo[] tableInfos = infoWindow.getTableInfos();