Skip to content

Commit

Permalink
IDEMPIERE-6112 New API to MSession to temporary disable update loggin…
Browse files Browse the repository at this point in the history
…g of a table for the current MSession (idempiere#2319)
  • Loading branch information
hengsin authored Apr 22, 2024
1 parent 27f979f commit 0bb5462
Show file tree
Hide file tree
Showing 3 changed files with 72 additions and 0 deletions.
31 changes: 31 additions & 0 deletions org.adempiere.base/src/org/compiere/model/MSession.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@
import java.net.UnknownHostException;
import java.sql.ResultSet;
import java.util.Properties;
import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;
import java.util.logging.Level;

import org.compiere.Adempiere;
Expand Down Expand Up @@ -440,5 +442,34 @@ public MSession markImmutable() {
makeImmutable();
return this;
}

/** Set of table name to disable capture of update change log */
private Set<String> skipChangeLogForUpdateSet = ConcurrentHashMap.newKeySet();

/**
* Add session flag to disable the capture of update change log for a table
* @param tableName table name, case insensitive
*/
public void addSkipChangeLogForUpdate(String tableName) {
skipChangeLogForUpdateSet.add(tableName.toUpperCase());
}

/**
* Remove the session flag that disable the capture of update change log for a table.<br/>
* After removal of the session flag, the logging decision is back to what have been configured at AD_Table and AD_Column level.
* @param tableName table name, case insensitive
*/
public void removeSkipChangeLogForUpdate(String tableName) {
skipChangeLogForUpdateSet.remove(tableName.toUpperCase());
}

/**
* Is skip the capture of update change log for this session
* @param tableName table name, case insensitive
* @return true if it is to skip the capture of update change log for this session
*/
public boolean isSkipChangeLogForUpdate(String tableName) {
return skipChangeLogForUpdateSet.contains(tableName.toUpperCase());
}
} // MSession

1 change: 1 addition & 0 deletions org.adempiere.base/src/org/compiere/model/PO.java
Original file line number Diff line number Diff line change
Expand Up @@ -3107,6 +3107,7 @@ else if (c == String.class)
&& !p_info.isEncrypted(i) // not encrypted
&& !p_info.isVirtualColumn(i) // no virtual column
&& !"Password".equals(columnName)
&& !session.isSkipChangeLogForUpdate(get_TableName())
)
{
Object oldV = m_oldValues[i];
Expand Down
40 changes: 40 additions & 0 deletions org.idempiere.test/src/org/idempiere/test/base/POTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertNull;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.junit.jupiter.api.Assertions.assertTrue;

Expand All @@ -42,15 +43,18 @@
import org.compiere.model.I_AD_UserPreference;
import org.compiere.model.MAcctSchema;
import org.compiere.model.MBPartner;
import org.compiere.model.MChangeLog;
import org.compiere.model.MClient;
import org.compiere.model.MColumn;
import org.compiere.model.MMessage;
import org.compiere.model.MProduct;
import org.compiere.model.MProductCategory;
import org.compiere.model.MProductCategoryAcct;
import org.compiere.model.MProductionLine;
import org.compiere.model.MSession;
import org.compiere.model.MTest;
import org.compiere.model.POInfo;
import org.compiere.model.Query;
import org.compiere.util.DB;
import org.compiere.util.Env;
import org.compiere.util.Ini;
Expand Down Expand Up @@ -586,4 +590,40 @@ public void testIsVirtualColumnMethods() {
assertTrue(column.isVirtualUIColumn(), "MColumn.isVirtualUIColumn() not working as expected for ColumnSQL="+column.getColumnSQL());
assertFalse(column.isVirtualSearchColumn(), "MColumn.isVirtualSearchColumn() not working as expected for ColumnSQL="+column.getColumnSQL());
}

@Test
public void testChangeLog() {
MSession.create(Env.getCtx());
MSession session = MSession.get(Env.getCtx());
MProduct product = new MProduct(Env.getCtx(), DictionaryIDs.M_Product.AZALEA_BUSH.id, null);
String description = product.getDescription();
try {
product.setDescription(description != null ? description + "+1" : "+1");
product.saveEx();

Query query = new Query(Env.getCtx(), MChangeLog.Table_Name, "AD_Session_ID=? AND AD_Table_ID=? AND Record_ID=? AND AD_Column_ID=? AND NewValue=?", null);
MColumn column = MColumn.get(Env.getCtx(), MProduct.Table_Name, MProduct.COLUMNNAME_Description);
MChangeLog changeLog = query.setParameters(session.get_ID(), MProduct.Table_ID, product.get_ID(), column.get_ID(), product.getDescription()).first();
assertNotNull(changeLog);
assertTrue(changeLog.getAD_ChangeLog_ID() > 0);

session.addSkipChangeLogForUpdate(MProduct.Table_Name);
product.setDescription(description != null ? description + "+2" : "+2");
product.saveEx();

changeLog = query.setParameters(session.get_ID(), MProduct.Table_ID, product.get_ID(), column.get_ID(), product.getDescription()).first();
assertNull(changeLog);

session.removeSkipChangeLogForUpdate(MProduct.Table_Name);
product.setDescription(description != null ? description + "+3" : "+3");
product.saveEx();

changeLog = query.setParameters(session.get_ID(), MProduct.Table_ID, product.get_ID(), column.get_ID(), product.getDescription()).first();
assertNotNull(changeLog);
assertTrue(changeLog.getAD_ChangeLog_ID() > 0);
} finally {
product.setDescription(description);
product.saveEx();
}
}
}

0 comments on commit 0bb5462

Please sign in to comment.