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);
try
{
PO.setCrossTenantSafe();
MChangeLog cl = new MChangeLog(getCtx(),
AD_ChangeLog_ID, TrxName, getAD_Session_ID(),
AD_Table_ID, AD_Column_ID, Record_ID, Record_UU, AD_Client_ID, AD_Org_ID,
OldValue, NewValue, event);
if (cl.save())
if (cl.saveCrossTenantSafe())
return cl;
}
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);
return null;
}
finally
{
PO.clearCrossTenantSafe();
}
log.log(Level.SEVERE, "AD_ChangeLog_ID=" + AD_ChangeLog_ID
+ ", AD_Session_ID=" + getAD_Session_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
* @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() {
boolean crossTenantSet = isSafeCrossTenant.get();

View File

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

View File

@ -76,13 +76,8 @@ public class FavouriteController
vTree.setAD_Org_ID(user.getAD_Org_ID());
// Support for System user
vTree.set_ValueNoCheck(MTreeFavorite.COLUMNNAME_AD_User_ID, Integer.valueOf(AD_User_ID));
try {
PO.setCrossTenantSafe();
if (!vTree.save())
throw new AdempiereException(Msg.getMsg(Env.getCtx(), "FavTreeNotCreate"));
} finally {
PO.clearCrossTenantSafe();
}
if (!vTree.saveCrossTenantSafe())
throw new AdempiereException(Msg.getMsg(Env.getCtx(), "FavTreeNotCreate"));
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.MSysConfig;
import org.compiere.model.MUser;
import org.compiere.model.PO;
import org.compiere.util.CLogger;
import org.compiere.util.Env;
import org.compiere.util.KeyNamePair;
@ -375,15 +374,10 @@ public class ChangePasswordPanel extends Window implements EventListener<Event>
user.setIsExpired(false);
user.setSecurityQuestion(securityQuestion);
user.setAnswer(answer);
try {
PO.setCrossTenantSafe();
user.saveEx(trx.getTrxName());
if (tenantsChanged.length() > 0)
tenantsChanged.append(", ");
tenantsChanged.append(clientKNPair.getName());
} finally {
PO.clearCrossTenantSafe();
}
user.saveCrossTenantSafeEx(trx.getTrxName());
if (tenantsChanged.length() > 0)
tenantsChanged.append(", ");
tenantsChanged.append(clientKNPair.getName());
}
trx.commit();

View File

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

View File

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

View File

@ -56,33 +56,28 @@ public class MInfoWindowTest extends AbstractTestCase {
MInfoWindow infoWindow = new MInfoWindow(Env.getCtx(), 0, getTrxName());
MInfoColumn infoColumn1 = 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.setName("testColumnAccess");
infoWindow.setFromClause("Test t");
infoWindow.saveEx();
infoColumn1.setAD_InfoWindow_ID(infoWindow.get_ID());
infoColumn1.setName(MTest.COLUMNNAME_T_Amount);
infoColumn1.setEntityType("U");
infoColumn1.setSelectClause("t."+MTest.COLUMNNAME_T_Amount);
infoColumn1.setSeqNo(10);
infoColumn1.setAD_Reference_ID(DisplayType.Amount);
infoColumn1.setColumnName(MTest.COLUMNNAME_T_Amount);
infoColumn1.saveEx();
infoColumn2.setAD_InfoWindow_ID(infoWindow.get_ID());
infoColumn2.setName(MTest.COLUMNNAME_T_DateTime);
infoColumn2.setEntityType("U");
infoColumn2.setSelectClause("t."+MTest.COLUMNNAME_T_DateTime);
infoColumn2.setSeqNo(10);
infoColumn2.setAD_Reference_ID(DisplayType.DateTime);
infoColumn2.setColumnName(MTest.COLUMNNAME_T_DateTime);
infoColumn2.saveEx();
} finally {
PO.clearCrossTenantSafe();
}
infoWindow.setAD_Table_ID(MTest.Table_ID);
infoWindow.setName("testColumnAccess");
infoWindow.setFromClause("Test t");
infoWindow.saveCrossTenantSafeEx();
infoColumn1.setAD_InfoWindow_ID(infoWindow.get_ID());
infoColumn1.setName(MTest.COLUMNNAME_T_Amount);
infoColumn1.setEntityType("U");
infoColumn1.setSelectClause("t."+MTest.COLUMNNAME_T_Amount);
infoColumn1.setSeqNo(10);
infoColumn1.setAD_Reference_ID(DisplayType.Amount);
infoColumn1.setColumnName(MTest.COLUMNNAME_T_Amount);
infoColumn1.saveCrossTenantSafeEx();
infoColumn2.setAD_InfoWindow_ID(infoWindow.get_ID());
infoColumn2.setName(MTest.COLUMNNAME_T_DateTime);
infoColumn2.setEntityType("U");
infoColumn2.setSelectClause("t."+MTest.COLUMNNAME_T_DateTime);
infoColumn2.setSeqNo(10);
infoColumn2.setAD_Reference_ID(DisplayType.DateTime);
infoColumn2.setColumnName(MTest.COLUMNNAME_T_DateTime);
infoColumn2.saveCrossTenantSafeEx();
infoWindow.getInfoColumns(true, true);
TableInfo[] tableInfos = infoWindow.getTableInfos();