The replication ID (Primary Key) is not working

1.- Fix the ID replication, now is possible replicate IDs
2.- Fix the Replication event for Tables and Documents
3.- Fix the Boolean replication cast
4.- replace the sql statement by collections
5.- remove unnecessary parameters


kind regards
Victor Perez
www.e-evolution.com
Link to SF Tracker: http://sourceforge.net/support/tracker.php?aid=2947622
This commit is contained in:
vpj-cd 2010-02-08 01:32:57 +00:00
parent 6da7726327
commit 4830d4c749
3 changed files with 193 additions and 273 deletions

View File

@ -29,8 +29,6 @@
**********************************************************************/
package org.adempiere.process.rpl.exp;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Timestamp;
import java.text.SimpleDateFormat;
@ -45,22 +43,21 @@ import javax.xml.parsers.ParserConfigurationException;
import org.adempiere.process.rpl.IExportProcessor;
import org.compiere.model.MClient;
import org.compiere.model.MColumn;
import org.compiere.model.MEXPFormat;
import org.compiere.model.MEXPFormatLine;
import org.compiere.model.MEXPProcessor;
import org.compiere.model.MEXPProcessorType;
import org.compiere.model.MReplicationStrategy;
import org.compiere.model.MTable;
import org.compiere.model.PO;
import org.compiere.model.Query;
import org.compiere.model.X_EXP_FormatLine;
import org.compiere.util.CLogger;
import org.compiere.util.DB;
import org.compiere.util.DisplayType;
import org.compiere.util.Env;
import org.compiere.util.Language;
import org.compiere.util.Msg;
import org.compiere.util.Trx;
import org.compiere.model.MEXPFormat;
import org.compiere.model.MEXPFormatLine;
import org.compiere.model.MEXPProcessor;
import org.compiere.model.MEXPProcessorType;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.Text;
@ -74,6 +71,8 @@ import org.w3c.dom.Text;
* @author victor.perez@e-evolution.com, e-Evolution
* <li>[ 2195090 ] Stabilization of replication
* <li>https://sourceforge.net/tracker/?func=detail&atid=879332&aid=2936561&group_id=176962
* <li>BF [2947622] The replication ID (Primary Key) is not working
* <li>https://sourceforge.net/tracker/?func=detail&aid=2947622&group_id=176962&atid=879332
*
*/
public class ExportHelper {
@ -157,48 +156,20 @@ public class ExportHelper {
outDocument = createNewDocument();
StringBuffer sql = new StringBuffer("SELECT * ")
.append("FROM ").append(po.get_TableName()).append(" ")
.append("WHERE ").append(po.get_KeyColumns()[0]).append("=?")
;
HashMap<String, Integer> variableMap = new HashMap<String, Integer>();
if (exportFormat.getWhereClause() != null & !"".equals(exportFormat.getWhereClause())) {
sql.append(" AND ").append(exportFormat.getWhereClause());
}
ResultSet rs = null;
PreparedStatement pstmt = null;
try
Element rootElement = outDocument.createElement(exportFormat.getValue());
if (exportFormat.getDescription() != null && !"".equals(exportFormat.getDescription()))
{
pstmt = DB.prepareStatement(sql.toString(), po.get_TrxName());
pstmt.setInt(1, po.get_ID());
rs = pstmt.executeQuery();
if (rs.next())
{
HashMap<String, Integer> variableMap = new HashMap<String, Integer>();
//variableMap.put(TOTAL_SEGMENTS, new Integer(1));
Element rootElement = outDocument.createElement(exportFormat.getValue());
if (exportFormat.getDescription() != null && !"".equals(exportFormat.getDescription())) {
rootElement.appendChild(outDocument.createComment(exportFormat.getDescription()));
}
rootElement.setAttribute("AD_Client_Value", client.getValue());
rootElement.setAttribute("Version", exportFormat.getVersion());
rootElement.setAttribute("ReplicationMode", ReplicationMode.toString());
rootElement.setAttribute("ReplicationType", ReplicationType);
rootElement.setAttribute("ReplicationEvent", ReplicationEvent.toString());
outDocument.appendChild(rootElement);
generateExportFormat(rootElement, exportFormat, rs, po, po.get_ID(), variableMap);
}
} finally {
try {
if (rs != null) rs.close();
if (pstmt != null) pstmt.close();
} catch (SQLException ex) {/*ignored*/}
rs = null;
pstmt = null;
rootElement.appendChild(outDocument.createComment(exportFormat.getDescription()));
}
rootElement.setAttribute("AD_Client_Value", client.getValue());
rootElement.setAttribute("Version", exportFormat.getVersion());
rootElement.setAttribute("ReplicationMode", ReplicationMode.toString());
rootElement.setAttribute("ReplicationType", ReplicationType);
rootElement.setAttribute("ReplicationEvent", ReplicationEvent.toString());
outDocument.appendChild(rootElement);
generateExportFormat(rootElement, exportFormat, po, po.get_ID(), variableMap);
MEXPProcessor mExportProcessor = null;
mExportProcessor = new MEXPProcessor (po.getCtx(), m_rplStrategy.getEXP_Processor_ID(), po.get_TrxName() );
@ -236,11 +207,11 @@ public class ExportHelper {
MTable table = MTable.get(exportFormat.getCtx(), exportFormat.getAD_Table_ID());
log.info("Table = " + table);
Collection<PO> datas = new Query(exportFormat.getCtx(),table.getTableName(), exportFormat.getWhereClause(), exportFormat.get_TrxName())
Collection<PO> records = new Query(exportFormat.getCtx(),table.getTableName(), exportFormat.getWhereClause(), exportFormat.get_TrxName())
.setOnlyActiveRecords(true)
.list();
for (PO po : datas)
for (PO po : records)
{
log.info("Client = " + client.toString());
log.finest("po.getAD_Org_ID() = " + po.getAD_Org_ID());
@ -257,48 +228,20 @@ public class ExportHelper {
String version = "3.2.0";
outDocument = createNewDocument();
StringBuffer sql = new StringBuffer("SELECT * ")
.append("FROM ").append(table.getTableName()).append(" ")
.append("WHERE ").append(po.get_KeyColumns()[0]).append("=?")
;
if (exportFormat.getWhereClause() != null & !"".equals(exportFormat.getWhereClause())) {
sql.append(" AND ").append(exportFormat.getWhereClause());
}
ResultSet rs = null;
PreparedStatement pstmt = null;
try
HashMap<String, Integer> variableMap = new HashMap<String, Integer>();
Element rootElement = outDocument.createElement(exportFormat.getValue());
if (exportFormat.getDescription() != null && !"".equals(exportFormat.getDescription()))
{
pstmt = DB.prepareStatement(sql.toString(), po.get_TrxName());
pstmt.setInt(1, po.get_ID());
rs = pstmt.executeQuery();
if (rs.next())
{
HashMap<String, Integer> variableMap = new HashMap<String, Integer>();
//variableMap.put(TOTAL_SEGMENTS, new Integer(1));
Element rootElement = outDocument.createElement(exportFormat.getValue());
if (exportFormat.getDescription() != null && !"".equals(exportFormat.getDescription())) {
rootElement.appendChild(outDocument.createComment(exportFormat.getDescription()));
}
rootElement.setAttribute("AD_Client_Value", client.getValue());
rootElement.setAttribute("Version", exportFormat.getVersion());
rootElement.setAttribute("ReplicationMode", ReplicationMode.toString());
rootElement.setAttribute("ReplicationType", ReplicationType);
rootElement.setAttribute("ReplicationEvent", ReplicationEvent.toString());
outDocument.appendChild(rootElement);
generateExportFormat(rootElement, exportFormat, rs, po, po.get_ID(), variableMap);
}
} finally {
try {
if (rs != null) rs.close();
if (pstmt != null) pstmt.close();
} catch (SQLException ex) {/*ignored*/}
rs = null;
pstmt = null;
rootElement.appendChild(outDocument.createComment(exportFormat.getDescription()));
}
rootElement.setAttribute("AD_Client_Value", client.getValue());
rootElement.setAttribute("Version", exportFormat.getVersion());
rootElement.setAttribute("ReplicationMode", ReplicationMode.toString());
rootElement.setAttribute("ReplicationType", ReplicationType);
rootElement.setAttribute("ReplicationEvent", ReplicationEvent.toString());
outDocument.appendChild(rootElement);
generateExportFormat(rootElement, exportFormat, po, po.get_ID(), variableMap);
}// finish record read
return outDocument;
}
@ -310,7 +253,7 @@ public class ExportHelper {
* <DocumentNo>101</DocumentNo>
* </C_Invoice>
*/
private void generateExportFormat(Element rootElement, MEXPFormat exportFormat, ResultSet rs, PO masterPO, int masterID, HashMap<String, Integer> variableMap) throws SQLException, Exception
private void generateExportFormat(Element rootElement, MEXPFormat exportFormat, PO masterPO, int masterID, HashMap<String, Integer> variableMap) throws SQLException, Exception
{
Collection<MEXPFormatLine> formatLines = exportFormat.getFormatLines();
@SuppressWarnings("unused")
@ -323,7 +266,7 @@ public class ExportHelper {
// process single XML Attribute
// Create new element
Element newElement = outDocument.createElement(formatLine.getValue());
log.info("Format Line Seach key"+ formatLine.getValue());
if (formatLine.getAD_Column_ID() == 0) {
throw new Exception(Msg.getMsg (masterPO.getCtx(), "EXPColumnMandatory"));
}
@ -336,7 +279,7 @@ public class ExportHelper {
} else { }
//log.info("["+column.getColumnName()+"]");
Object value = rs.getObject(column.getColumnName());
Object value = masterPO.get_Value(column.getColumnName());
String valueString = null;
if (value != null) {
valueString = value.toString();
@ -350,14 +293,12 @@ public class ExportHelper {
if (valueString != null) {
if (formatLine.getDateFormat() != null && !"".equals(formatLine.getDateFormat())) {
m_customDateFormat = new SimpleDateFormat( formatLine.getDateFormat() ); // "MM/dd/yyyy"
//Date date = m_customDateFormat.parse ( valueString );
valueString = m_customDateFormat.format(Timestamp.valueOf (valueString));
newElement.setAttribute("DateFormat", m_customDateFormat.toPattern()); // Add "DateForamt attribute"
} else {
//valueString = m_dateFormat.format (Timestamp.valueOf (valueString));
//newElement.setAttribute("DateFormat", m_dateTimeFormat.toPattern()); // Add "DateForamt attribute
//Standard Japanese Format (default) works better (yyyy-mm-dd)
newElement.setAttribute("DateFormat", valueString);
} else
{
newElement.setAttribute("DateFormat", valueString);
}
}
@ -365,13 +306,9 @@ public class ExportHelper {
if (valueString != null) {
if (formatLine.getDateFormat() != null && !"".equals(formatLine.getDateFormat())) {
m_customDateFormat = new SimpleDateFormat( formatLine.getDateFormat() ); // "MM/dd/yyyy"
//Date date = m_customDateFormat.parse ( valueString );
valueString = m_customDateFormat.format(Timestamp.valueOf (valueString));
newElement.setAttribute("DateFormat", m_customDateFormat.toPattern()); // Add "DateForamt attribute"
} else {
//valueString = m_dateTimeFormat.format (Timestamp.valueOf (valueString));
//newElement.setAttribute("DateFormat", m_dateTimeFormat.toPattern()); // Add "DateForamt attribute
//Standard Japanese Format (default) works better (yyyy-mm-dd hh:mm:ss m.mm)
newElement.setAttribute("DateFormat", valueString);
}
}
@ -382,8 +319,6 @@ public class ExportHelper {
newElement.appendChild(newText);
rootElement.appendChild(newElement);
elementHasValue = true;
//increaseVariable(variableMap, formatLines[i].getVariableName()); // Increase value of Variable if any Variable
//increaseVariable(variableMap, TOTAL_SEGMENTS);
} else {
// Empty field.
if (formatLine.isMandatory()) {
@ -407,7 +342,7 @@ public class ExportHelper {
} else { }
//log.info("["+column.getColumnName()+"]");
Object value = rs.getObject(column.getColumnName());
Object value = masterPO.get_Value(column.getColumnName());
String valueString = null;
if (value != null) {
valueString = value.toString();
@ -442,8 +377,7 @@ public class ExportHelper {
if (valueString != null && !"".equals(valueString) && !"null".equals(valueString)) {
rootElement.setAttribute(formatLine.getValue(), valueString);
elementHasValue = true;
//increaseVariable(variableMap, formatLines[i].getVariableName()); // Increase value of Variable if any Variable
//increaseVariable(variableMap, TOTAL_SEGMENTS);
} else {
// Empty field.
}
@ -458,44 +392,30 @@ public class ExportHelper {
MTable tableEmbedded = MTable.get(masterPO.getCtx(), embeddedFormat.getAD_Table_ID());
log.info("Table Embedded = " + tableEmbedded);
StringBuffer sql = new StringBuffer("SELECT * ")
.append("FROM ").append(tableEmbedded.getTableName()).append(" ")
.append("WHERE ").append(masterPO.get_KeyColumns()[0]).append("=?")
//+ "WHERE " + po.get_WhereClause(false)
;
if (embeddedFormat.getWhereClause() != null & !"".equals(embeddedFormat.getWhereClause())) {
sql.append(" AND ").append(embeddedFormat.getWhereClause());
}
log.info(sql.toString());
ResultSet rsEmbedded = null;
PreparedStatement pstmt = null;
try
final StringBuffer whereClause = new StringBuffer(masterPO.get_KeyColumns()[0] +"=?");
if (embeddedFormat.getWhereClause() != null & !"".equals(embeddedFormat.getWhereClause()))
{
pstmt = DB.prepareStatement(sql.toString(), masterPO.get_TrxName());
pstmt.setInt(1, masterID);
rsEmbedded = pstmt.executeQuery();
while (rsEmbedded.next())
{
//System.out.println("Trifon - tableEmbedded.getTableName()_ID = "+ tableEmbedded.getTableName() + "_ID");
int embeddedID = rsEmbedded.getInt(tableEmbedded.getTableName() + "_ID");
PO poEmbedded = tableEmbedded.getPO (embeddedID, masterPO.get_TrxName());
Element embeddedElement = outDocument.createElement(formatLine.getValue());
if (formatLine.getDescription() != null && !"".equals(formatLine.getDescription())) {
embeddedElement.appendChild(outDocument.createComment(formatLine.getDescription()));
}
generateExportFormat(embeddedElement, embeddedFormat, rsEmbedded, poEmbedded, embeddedID, variableMap);
rootElement.appendChild(embeddedElement);
}
} finally {
try {
if (rsEmbedded != null) rsEmbedded.close();
if (pstmt != null) pstmt.close();
} catch (SQLException ex) { }
rsEmbedded = null;
pstmt = null;
whereClause.append(" AND ").append(embeddedFormat.getWhereClause());
}
Collection<PO> instances = new Query(masterPO.getCtx(),
tableEmbedded.getTableName(), whereClause.toString(),
masterPO.get_TrxName()).setClient_ID().setParameters(
new Object[] { masterID }).list();
for (PO instance : instances)
{
Element embeddedElement = outDocument.createElement(formatLine.getValue());
if (formatLine.getDescription() != null && !"".equals(formatLine.getDescription()))
{
embeddedElement.appendChild(outDocument.createComment(formatLine.getDescription()));
}
generateExportFormat(embeddedElement, embeddedFormat, instance, instance.get_ID(), variableMap);
rootElement.appendChild(embeddedElement);
}
}
else if ( formatLine.getType().equals(X_EXP_FormatLine.TYPE_ReferencedEXPFormat) )
@ -508,63 +428,34 @@ public class ExportHelper {
MTable tableEmbedded = MTable.get(masterPO.getCtx(), embeddedFormat.getAD_Table_ID());
log.info("Table Embedded = " + tableEmbedded);
StringBuffer sql = new StringBuffer("SELECT * ")
.append("FROM ").append(tableEmbedded.getTableName()).append(" ")
.append("WHERE ").append(tableEmbedded.getTableName() + "_ID").append("=?")
//+ "WHERE " + po.get_WhereClause(false)
;
if (embeddedFormat.getWhereClause() != null & !"".equals(embeddedFormat.getWhereClause())) {
sql.append(" AND ").append(embeddedFormat.getWhereClause());
}
log.info(sql.toString());
if (formatLine.getAD_Column_ID() == 0) {
throw new Exception(Msg.getMsg (masterPO.getCtx(), "EXPColumnMandatory"));
}
MColumn column = MColumn.get(masterPO.getCtx(), formatLine.getAD_Column_ID());
if (column == null) {
throw new Exception(Msg.getMsg (masterPO.getCtx(), "EXPColumnMandatory"));
}
if ( column.isVirtualColumn() ) {
log.info("This is Virtual Column!");
} else { }
//log.info("["+column.getColumnName()+"]");
Object value = rs.getObject(column.getColumnName());
/* String valueString = null;
if (value != null) {
valueString = value.toString();
} else {
throw new Exception(Msg.getMsg (masterPO.getCtx(), "EXPFieldMandatory"));
}
*/
log.info(sql.toString());
ResultSet rsEmbedded = null;
PreparedStatement pstmt = null;
try
final StringBuffer whereClause = new StringBuffer(tableEmbedded.getTableName() + "_ID =?");
if (embeddedFormat.getWhereClause() != null & !"".equals(embeddedFormat.getWhereClause()))
{
pstmt = DB.prepareStatement(sql.toString(), masterPO.get_TrxName());
pstmt.setObject(1, value);
rsEmbedded = pstmt.executeQuery();
while (rsEmbedded.next())
{
//System.out.println("Trifon - tableEmbedded.getTableName()_ID = "+ tableEmbedded.getTableName() + "_ID");
int embeddedID = rsEmbedded.getInt(tableEmbedded.getTableName() + "_ID");
PO poEmbedded = tableEmbedded.getPO (embeddedID, masterPO.get_TrxName());
whereClause.append(" AND ").append(embeddedFormat.getWhereClause());
}
Element embeddedElement = outDocument.createElement(formatLine.getValue());
if (formatLine.getDescription() != null && !"".equals(formatLine.getDescription())) {
embeddedElement.appendChild(outDocument.createComment(formatLine.getDescription()));
}
generateExportFormat(embeddedElement, embeddedFormat, rsEmbedded, poEmbedded, embeddedID, variableMap);
rootElement.appendChild(embeddedElement);
}
Object value = masterPO.get_Value(tableEmbedded.getTableName() + "_ID");
if (value == null)
{
continue;
}
} finally {
try {
if (rsEmbedded != null) rsEmbedded.close();
if (pstmt != null) pstmt.close();
} catch (SQLException ex) { }
rsEmbedded = null;
pstmt = null;
Collection<PO> instances = new Query(masterPO.getCtx(),tableEmbedded.getTableName(), whereClause.toString(),masterPO.get_TrxName())
.setClient_ID()
.setParameters(new Object[] { value })
.list();
for (PO instance : instances)
{
Element embeddedElement = outDocument.createElement(formatLine.getValue());
if (formatLine.getDescription() != null && !"".equals(formatLine.getDescription()))
{
embeddedElement.appendChild(outDocument.createComment(formatLine.getDescription()));
}
generateExportFormat(embeddedElement, embeddedFormat, instance, instance.get_ID(), variableMap);
rootElement.appendChild(embeddedElement);
}
}

View File

@ -40,8 +40,8 @@ import java.util.Properties;
import javax.xml.xpath.XPathExpressionException;
import org.adempiere.exceptions.AdempiereException;
import org.adempiere.process.rpl.exp.ExportHelper;
import org.adempiere.process.rpl.XMLHelper;
import org.adempiere.process.rpl.exp.ExportHelper;
import org.compiere.model.I_AD_Client;
import org.compiere.model.MClient;
import org.compiere.model.MColumn;
@ -52,7 +52,9 @@ import org.compiere.model.MTable;
import org.compiere.model.ModelValidator;
import org.compiere.model.PO;
import org.compiere.model.Query;
import org.compiere.model.X_AD_ReplicationDocument;
import org.compiere.model.X_AD_ReplicationTable;
import org.compiere.process.DocAction;
import org.compiere.util.CLogger;
import org.compiere.util.DisplayType;
import org.compiere.util.Env;
@ -69,6 +71,8 @@ import org.w3c.dom.NodeList;
* @author victor.perez@e-evolution.com, e-Evolution
* <li>[ 2195090 ] Stabilization of replication
* <li>https://sourceforge.net/tracker/?func=detail&atid=879332&aid=2936561&group_id=176962
* <li>BF [2947622] The replication ID (Primary Key) is not working
* <li>https://sourceforge.net/tracker/?func=detail&aid=2947622&group_id=176962&atid=879332
*
*/
public class ImportHelper {
@ -171,65 +175,62 @@ public class ImportHelper {
if(po != null)
{
// Here must invoke other method else we get cycle...
if (ModelValidator.TYPE_BEFORE_DELETE == ReplicationEvent
|| ModelValidator.TYPE_BEFORE_DELETE_REPLICATION == ReplicationEvent
|| ModelValidator.TYPE_DELETE == ReplicationEvent)
{
po.deleteEx(true);
}
else
{
if(X_AD_ReplicationTable.REPLICATIONTYPE_Broadcast.equals(ReplicationType))
{
po.saveReplica(true);
MReplicationStrategy rplStrategy = new MReplicationStrategy(client.getCtx(), client.getAD_ReplicationStrategy_ID(), null);
ExportHelper expHelper = new ExportHelper(client, rplStrategy);
expHelper.exportRecord( po,
MReplicationStrategy.REPLICATION_TABLE,
X_AD_ReplicationTable.REPLICATIONTYPE_Merge,
ModelValidator.TYPE_AFTER_CHANGE);
}
else if(X_AD_ReplicationTable.REPLICATIONTYPE_Merge.equals(ReplicationType)
|| X_AD_ReplicationTable.REPLICATIONTYPE_Reference.equals(ReplicationType))
{
po.saveReplica(true);
}
/*else if (X_AD_ReplicationTable.REPLICATIONTYPE_Reference.equals(ReplicationType))
{
//Do nothing??
}*/
else if(X_AD_ReplicationTable.REPLICATIONTYPE_Local.equals(ReplicationType))
{
//Do nothing??
}
else
{
// Replication Type is not one of the possible values...ERROR
throw new Exception(Msg.getMsg(ctx, "EXPReplicationTypeNonValidType"));
}
if(MReplicationStrategy.REPLICATION_TABLE==ReplicationMode)
{
// Here must invoke other method else we get cycle...
if ( ModelValidator.TYPE_BEFORE_DELETE == ReplicationEvent
|| ModelValidator.TYPE_BEFORE_DELETE_REPLICATION == ReplicationEvent
|| ModelValidator.TYPE_DELETE == ReplicationEvent)
{
po.deleteEx(true);
}
else
{
if(X_AD_ReplicationTable.REPLICATIONTYPE_Broadcast.equals(ReplicationType))
{
po.saveReplica(true);
MReplicationStrategy rplStrategy = new MReplicationStrategy(client.getCtx(), client.getAD_ReplicationStrategy_ID(), null);
ExportHelper expHelper = new ExportHelper(client, rplStrategy);
expHelper.exportRecord( po,
MReplicationStrategy.REPLICATION_TABLE,
X_AD_ReplicationTable.REPLICATIONTYPE_Merge,
ModelValidator.TYPE_AFTER_CHANGE);
}
}
else if(X_AD_ReplicationTable.REPLICATIONTYPE_Merge.equals(ReplicationType)
|| X_AD_ReplicationTable.REPLICATIONTYPE_Reference.equals(ReplicationType))
{
if(po.is_Changed())
{
po.saveReplica(true);
}
}
/*else if (X_AD_ReplicationTable.REPLICATIONTYPE_Reference.equals(ReplicationType))
{
//Do nothing??
}*/
else if(X_AD_ReplicationTable.REPLICATIONTYPE_Local.equals(ReplicationType))
{
//Do nothing??
}
else
{
// Replication Type is not one of the possible values...ERROR
throw new Exception(Msg.getMsg(ctx, "EXPReplicationTypeNonValidType"));
}
}
}
else if(MReplicationStrategy.REPLICATION_DOCUMENT == ReplicationMode
&& X_AD_ReplicationDocument.REPLICATIONTYPE_Merge.equals(ReplicationType)
&& po instanceof DocAction)
{
Env.setContext(Env.getCtx(), "#AD_Client_ID", po.getAD_Client_ID());
DocAction document = (DocAction)po;
document.processIt(document.getDocAction());
po.saveEx();
}
}
result.append("Save Successful ;");
/*if (resultSave)
{
if(ReplicationMode == MReplicationStrategy.REPLICATION_DOCUMENT &&
ReplicationType == X_AD_ReplicationDocument.REPLICATIONTYPE_Merge)
{
String status = po.get_ValueAsString("DocStatus");
String action = po.get_ValueAsString("DocAction");
DocAction m_document;
m_document=(DocAction) po;
DocumentEngine engine = new DocumentEngine (m_document, status);
engine.processIt (action);
}
// Success in save
} else {
// Failed in save
throw new Exception(Msg.getMsg(ctx, "EXPFormatFailedSave"));
}*/
}
/**
@ -279,7 +280,7 @@ public class ImportHelper {
log.info("=================== Beginnig of Format Line ===============================");
log.info("formatLine: [" + formatLine.toString() + "]");
//Get the value
Object value = getValueFromFormat(formatLine,po,rootElement,result,ReplicationType,trxName);
Object value = getValueFromFormat(formatLine,po,rootElement,result,ReplicationType);
if (value == null || value.toString().equals(""))
continue;
//Set the value
@ -300,7 +301,7 @@ public class ImportHelper {
* @throws Exception
*/
private Object getValueFromFormat(MEXPFormatLine line,PO po,Element rootElement,
StringBuffer result, String ReplicationType, String trxName) throws Exception
StringBuffer result, String ReplicationType) throws Exception
{
Object value = null;
@ -315,7 +316,7 @@ public class ImportHelper {
{
// Referenced Export Format
//get from cache
MEXPFormat referencedExpFormat = MEXPFormat.get(ctx, line.getEXP_EmbeddedFormat_ID(), trxName);
MEXPFormat referencedExpFormat = MEXPFormat.get(ctx, line.getEXP_EmbeddedFormat_ID(), po.get_TrxName());
log.info("referencedExpFormat = " + referencedExpFormat);
int refRecord_ID = 0;
@ -329,7 +330,7 @@ public class ImportHelper {
log.info("referencedNode = " + referencedNode);
if(referencedNode!=null)
{
refRecord_ID = getID(ctx, referencedExpFormat, referencedNode, line.getValue(), trxName);
refRecord_ID = getID(ctx, referencedExpFormat, referencedNode, line.getValue(), po.get_TrxName());
log.info("refRecord_ID = " + refRecord_ID);
value = new Integer(refRecord_ID);
}
@ -349,7 +350,7 @@ public class ImportHelper {
// Embedded Export Format It is used for Parent-Son records like Order&OrderLine
//get from cache
MEXPFormat referencedExpFormat = MEXPFormat.get(ctx, line.getEXP_EmbeddedFormat_ID(), trxName);
MEXPFormat referencedExpFormat = MEXPFormat.get(ctx, line.getEXP_EmbeddedFormat_ID(), po.get_TrxName());
log.info("embeddedExpFormat = " + referencedExpFormat);
NodeList nodeList = XMLHelper.getNodeList("/"+rootElement.getNodeName() + "/" + line.getValue(), rootElement);
@ -361,7 +362,7 @@ public class ImportHelper {
PO embeddedPo = null;
// Import embedded PO
log.info("=== BEGIN RECURSION CALL ===");
embeddedPo = importElement(ctx, result, referencedElement, referencedExpFormat,ReplicationType, trxName);
embeddedPo = importElement(ctx, result, referencedElement, referencedExpFormat,ReplicationType, po.get_TrxName());
log.info("embeddedPo = " + embeddedPo);
embeddedPo.saveReplica(true);
result.append(" Embedded Save Successful ; ");
@ -394,12 +395,13 @@ public class ImportHelper {
*/
private void setReplicaValues(Object value,MEXPFormatLine line,PO po,StringBuffer result)throws Exception
{
MColumn column = MColumn.get(ctx, line.getAD_Column_ID());
log.info("column=[" + column + "]");
if (value !=null)
{
if (!MEXPFormatLine.TYPE_EmbeddedEXPFormat.equals(line.getType()) )
{
MColumn column = MColumn.get(ctx, line.getAD_Column_ID());
log.info("column=[" + column + "]");
// Clazz
Class clazz = DisplayType.getClass(column.getAD_Reference_ID(), true);
@ -481,7 +483,11 @@ public class ImportHelper {
}
else if(DisplayType.YesNo == column.getAD_Reference_ID())
{
po.set_ValueOfColumn(line.getAD_Column_ID(), value);
if(clazz == Boolean.class)
{
String v = value.toString().equals("true") ? "Y" : "N";
po.set_ValueOfColumn(line.getAD_Column_ID(), v);
}
}
else
{
@ -491,7 +497,8 @@ public class ImportHelper {
if(clazz == Boolean.class)
{
po.set_ValueOfColumn(line.getAD_Column_ID(), value);
String v = value.toString().equals("true") ? "Y" : "N";
po.set_ValueOfColumn(line.getAD_Column_ID(), v);
}
else
{
@ -565,6 +572,7 @@ public class ImportHelper {
throw new AdempiereException(Msg.getMsg(ctx, "EXPFormatLineNoUniqueColumns"));
}
int replication_id = 0;
Object[] cols = new Object[uniqueFormatLines.size()];
Object[] params = new Object[uniqueFormatLines.size()];
StringBuffer whereClause= new StringBuffer("");
@ -634,6 +642,10 @@ public class ImportHelper {
{
//double doubleValue = Double.parseDouble(value.toString());
value = new Integer(value.toString());
if (DisplayType.ID == column.getAD_Reference_ID())
{
replication_id = (Integer) value;
}
}
else
{
@ -671,7 +683,14 @@ public class ImportHelper {
if(values.size()<=0)//Means that is a new record
{
return MTable.get(ctx, expFormat.getAD_Table_ID()).getPO(0,trxName);
PO po = po = MTable.get(ctx, expFormat.getAD_Table_ID()).getPO(0,trxName);
if (replication_id > 0 )
{
po.set_CustomColumn(po.get_KeyColumns()[0], replication_id);
}
return po;
}
return values.get(0);//Return the first (unique) record.

View File

@ -86,6 +86,8 @@ import org.w3c.dom.Element;
* @author Victor Perez, e-Evolution SC
* <li>[ 2195894 ] Improve performance in PO engine
* <li>http://sourceforge.net/tracker/index.php?func=detail&aid=2195894&group_id=176962&atid=879335
* <li>BF [2947622] The replication ID (Primary Key) is not working
* <li>https://sourceforge.net/tracker/?func=detail&aid=2947622&group_id=176962&atid=879332
*/
public abstract class PO
implements Serializable, Comparator, Evaluatee
@ -2512,6 +2514,14 @@ public abstract class PO
int no = saveNew_getID();
if (no <= 0)
no = DB.getNextID(getAD_Client_ID(), p_info.getTableName(), m_trxName);
// the primary key is not overwrite with the local sequence
if (isReplication())
{
if (get_ID() > 0)
{
no = get_ID();
}
}
if (no <= 0)
{
log.severe("No NextID (" + no + ")");