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; package org.adempiere.process.rpl.exp;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException; import java.sql.SQLException;
import java.sql.Timestamp; import java.sql.Timestamp;
import java.text.SimpleDateFormat; import java.text.SimpleDateFormat;
@ -45,22 +43,21 @@ import javax.xml.parsers.ParserConfigurationException;
import org.adempiere.process.rpl.IExportProcessor; import org.adempiere.process.rpl.IExportProcessor;
import org.compiere.model.MClient; import org.compiere.model.MClient;
import org.compiere.model.MColumn; 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.MReplicationStrategy;
import org.compiere.model.MTable; import org.compiere.model.MTable;
import org.compiere.model.PO; import org.compiere.model.PO;
import org.compiere.model.Query; import org.compiere.model.Query;
import org.compiere.model.X_EXP_FormatLine; import org.compiere.model.X_EXP_FormatLine;
import org.compiere.util.CLogger; import org.compiere.util.CLogger;
import org.compiere.util.DB;
import org.compiere.util.DisplayType; import org.compiere.util.DisplayType;
import org.compiere.util.Env; import org.compiere.util.Env;
import org.compiere.util.Language; import org.compiere.util.Language;
import org.compiere.util.Msg; import org.compiere.util.Msg;
import org.compiere.util.Trx; 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.Document;
import org.w3c.dom.Element; import org.w3c.dom.Element;
import org.w3c.dom.Text; import org.w3c.dom.Text;
@ -74,6 +71,8 @@ import org.w3c.dom.Text;
* @author victor.perez@e-evolution.com, e-Evolution * @author victor.perez@e-evolution.com, e-Evolution
* <li>[ 2195090 ] Stabilization of replication * <li>[ 2195090 ] Stabilization of replication
* <li>https://sourceforge.net/tracker/?func=detail&atid=879332&aid=2936561&group_id=176962 * <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 { public class ExportHelper {
@ -157,29 +156,11 @@ public class ExportHelper {
outDocument = createNewDocument(); outDocument = createNewDocument();
StringBuffer sql = new StringBuffer("SELECT * ")
.append("FROM ").append(po.get_TableName()).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
{
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>(); HashMap<String, Integer> variableMap = new HashMap<String, Integer>();
//variableMap.put(TOTAL_SEGMENTS, new Integer(1));
Element rootElement = outDocument.createElement(exportFormat.getValue()); Element rootElement = outDocument.createElement(exportFormat.getValue());
if (exportFormat.getDescription() != null && !"".equals(exportFormat.getDescription())) { if (exportFormat.getDescription() != null && !"".equals(exportFormat.getDescription()))
{
rootElement.appendChild(outDocument.createComment(exportFormat.getDescription())); rootElement.appendChild(outDocument.createComment(exportFormat.getDescription()));
} }
rootElement.setAttribute("AD_Client_Value", client.getValue()); rootElement.setAttribute("AD_Client_Value", client.getValue());
@ -188,17 +169,7 @@ public class ExportHelper {
rootElement.setAttribute("ReplicationType", ReplicationType); rootElement.setAttribute("ReplicationType", ReplicationType);
rootElement.setAttribute("ReplicationEvent", ReplicationEvent.toString()); rootElement.setAttribute("ReplicationEvent", ReplicationEvent.toString());
outDocument.appendChild(rootElement); outDocument.appendChild(rootElement);
generateExportFormat(rootElement, exportFormat, rs, po, po.get_ID(), variableMap); generateExportFormat(rootElement, exportFormat, 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;
}
MEXPProcessor mExportProcessor = null; MEXPProcessor mExportProcessor = null;
mExportProcessor = new MEXPProcessor (po.getCtx(), m_rplStrategy.getEXP_Processor_ID(), po.get_TrxName() ); 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()); MTable table = MTable.get(exportFormat.getCtx(), exportFormat.getAD_Table_ID());
log.info("Table = " + table); 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) .setOnlyActiveRecords(true)
.list(); .list();
for (PO po : datas) for (PO po : records)
{ {
log.info("Client = " + client.toString()); log.info("Client = " + client.toString());
log.finest("po.getAD_Org_ID() = " + po.getAD_Org_ID()); log.finest("po.getAD_Org_ID() = " + po.getAD_Org_ID());
@ -257,29 +228,11 @@ public class ExportHelper {
String version = "3.2.0"; String version = "3.2.0";
outDocument = createNewDocument(); 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
{
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>(); HashMap<String, Integer> variableMap = new HashMap<String, Integer>();
//variableMap.put(TOTAL_SEGMENTS, new Integer(1));
Element rootElement = outDocument.createElement(exportFormat.getValue()); Element rootElement = outDocument.createElement(exportFormat.getValue());
if (exportFormat.getDescription() != null && !"".equals(exportFormat.getDescription())) { if (exportFormat.getDescription() != null && !"".equals(exportFormat.getDescription()))
{
rootElement.appendChild(outDocument.createComment(exportFormat.getDescription())); rootElement.appendChild(outDocument.createComment(exportFormat.getDescription()));
} }
rootElement.setAttribute("AD_Client_Value", client.getValue()); rootElement.setAttribute("AD_Client_Value", client.getValue());
@ -288,17 +241,7 @@ public class ExportHelper {
rootElement.setAttribute("ReplicationType", ReplicationType); rootElement.setAttribute("ReplicationType", ReplicationType);
rootElement.setAttribute("ReplicationEvent", ReplicationEvent.toString()); rootElement.setAttribute("ReplicationEvent", ReplicationEvent.toString());
outDocument.appendChild(rootElement); outDocument.appendChild(rootElement);
generateExportFormat(rootElement, exportFormat, rs, po, po.get_ID(), variableMap); generateExportFormat(rootElement, exportFormat, 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;
}
}// finish record read }// finish record read
return outDocument; return outDocument;
} }
@ -310,7 +253,7 @@ public class ExportHelper {
* <DocumentNo>101</DocumentNo> * <DocumentNo>101</DocumentNo>
* </C_Invoice> * </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(); Collection<MEXPFormatLine> formatLines = exportFormat.getFormatLines();
@SuppressWarnings("unused") @SuppressWarnings("unused")
@ -323,7 +266,7 @@ public class ExportHelper {
// process single XML Attribute // process single XML Attribute
// Create new element // Create new element
Element newElement = outDocument.createElement(formatLine.getValue()); Element newElement = outDocument.createElement(formatLine.getValue());
log.info("Format Line Seach key"+ formatLine.getValue());
if (formatLine.getAD_Column_ID() == 0) { if (formatLine.getAD_Column_ID() == 0) {
throw new Exception(Msg.getMsg (masterPO.getCtx(), "EXPColumnMandatory")); throw new Exception(Msg.getMsg (masterPO.getCtx(), "EXPColumnMandatory"));
} }
@ -336,7 +279,7 @@ public class ExportHelper {
} else { } } else { }
//log.info("["+column.getColumnName()+"]"); //log.info("["+column.getColumnName()+"]");
Object value = rs.getObject(column.getColumnName()); Object value = masterPO.get_Value(column.getColumnName());
String valueString = null; String valueString = null;
if (value != null) { if (value != null) {
valueString = value.toString(); valueString = value.toString();
@ -350,13 +293,11 @@ public class ExportHelper {
if (valueString != null) { if (valueString != null) {
if (formatLine.getDateFormat() != null && !"".equals(formatLine.getDateFormat())) { if (formatLine.getDateFormat() != null && !"".equals(formatLine.getDateFormat())) {
m_customDateFormat = new SimpleDateFormat( formatLine.getDateFormat() ); // "MM/dd/yyyy" m_customDateFormat = new SimpleDateFormat( formatLine.getDateFormat() ); // "MM/dd/yyyy"
//Date date = m_customDateFormat.parse ( valueString );
valueString = m_customDateFormat.format(Timestamp.valueOf (valueString)); valueString = m_customDateFormat.format(Timestamp.valueOf (valueString));
newElement.setAttribute("DateFormat", m_customDateFormat.toPattern()); // Add "DateForamt attribute" newElement.setAttribute("DateFormat", m_customDateFormat.toPattern()); // Add "DateForamt attribute"
} else { } 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); newElement.setAttribute("DateFormat", valueString);
} }
@ -365,13 +306,9 @@ public class ExportHelper {
if (valueString != null) { if (valueString != null) {
if (formatLine.getDateFormat() != null && !"".equals(formatLine.getDateFormat())) { if (formatLine.getDateFormat() != null && !"".equals(formatLine.getDateFormat())) {
m_customDateFormat = new SimpleDateFormat( formatLine.getDateFormat() ); // "MM/dd/yyyy" m_customDateFormat = new SimpleDateFormat( formatLine.getDateFormat() ); // "MM/dd/yyyy"
//Date date = m_customDateFormat.parse ( valueString );
valueString = m_customDateFormat.format(Timestamp.valueOf (valueString)); valueString = m_customDateFormat.format(Timestamp.valueOf (valueString));
newElement.setAttribute("DateFormat", m_customDateFormat.toPattern()); // Add "DateForamt attribute" newElement.setAttribute("DateFormat", m_customDateFormat.toPattern()); // Add "DateForamt attribute"
} else { } 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); newElement.setAttribute("DateFormat", valueString);
} }
} }
@ -382,8 +319,6 @@ public class ExportHelper {
newElement.appendChild(newText); newElement.appendChild(newText);
rootElement.appendChild(newElement); rootElement.appendChild(newElement);
elementHasValue = true; elementHasValue = true;
//increaseVariable(variableMap, formatLines[i].getVariableName()); // Increase value of Variable if any Variable
//increaseVariable(variableMap, TOTAL_SEGMENTS);
} else { } else {
// Empty field. // Empty field.
if (formatLine.isMandatory()) { if (formatLine.isMandatory()) {
@ -407,7 +342,7 @@ public class ExportHelper {
} else { } } else { }
//log.info("["+column.getColumnName()+"]"); //log.info("["+column.getColumnName()+"]");
Object value = rs.getObject(column.getColumnName()); Object value = masterPO.get_Value(column.getColumnName());
String valueString = null; String valueString = null;
if (value != null) { if (value != null) {
valueString = value.toString(); valueString = value.toString();
@ -442,8 +377,7 @@ public class ExportHelper {
if (valueString != null && !"".equals(valueString) && !"null".equals(valueString)) { if (valueString != null && !"".equals(valueString) && !"null".equals(valueString)) {
rootElement.setAttribute(formatLine.getValue(), valueString); rootElement.setAttribute(formatLine.getValue(), valueString);
elementHasValue = true; elementHasValue = true;
//increaseVariable(variableMap, formatLines[i].getVariableName()); // Increase value of Variable if any Variable
//increaseVariable(variableMap, TOTAL_SEGMENTS);
} else { } else {
// Empty field. // Empty field.
} }
@ -458,44 +392,30 @@ public class ExportHelper {
MTable tableEmbedded = MTable.get(masterPO.getCtx(), embeddedFormat.getAD_Table_ID()); MTable tableEmbedded = MTable.get(masterPO.getCtx(), embeddedFormat.getAD_Table_ID());
log.info("Table Embedded = " + tableEmbedded); 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
{
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());
final StringBuffer whereClause = new StringBuffer(masterPO.get_KeyColumns()[0] +"=?");
if (embeddedFormat.getWhereClause() != null & !"".equals(embeddedFormat.getWhereClause()))
{
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()); Element embeddedElement = outDocument.createElement(formatLine.getValue());
if (formatLine.getDescription() != null && !"".equals(formatLine.getDescription())) { if (formatLine.getDescription() != null && !"".equals(formatLine.getDescription()))
{
embeddedElement.appendChild(outDocument.createComment(formatLine.getDescription())); embeddedElement.appendChild(outDocument.createComment(formatLine.getDescription()));
} }
generateExportFormat(embeddedElement, embeddedFormat, rsEmbedded, poEmbedded, embeddedID, variableMap);
generateExportFormat(embeddedElement, embeddedFormat, instance, instance.get_ID(), variableMap);
rootElement.appendChild(embeddedElement); rootElement.appendChild(embeddedElement);
} }
} finally {
try {
if (rsEmbedded != null) rsEmbedded.close();
if (pstmt != null) pstmt.close();
} catch (SQLException ex) { }
rsEmbedded = null;
pstmt = null;
}
} }
else if ( formatLine.getType().equals(X_EXP_FormatLine.TYPE_ReferencedEXPFormat) ) 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()); MTable tableEmbedded = MTable.get(masterPO.getCtx(), embeddedFormat.getAD_Table_ID());
log.info("Table Embedded = " + tableEmbedded); 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
{
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());
final StringBuffer whereClause = new StringBuffer(tableEmbedded.getTableName() + "_ID =?");
if (embeddedFormat.getWhereClause() != null & !"".equals(embeddedFormat.getWhereClause()))
{
whereClause.append(" AND ").append(embeddedFormat.getWhereClause());
}
Object value = masterPO.get_Value(tableEmbedded.getTableName() + "_ID");
if (value == null)
{
continue;
}
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()); Element embeddedElement = outDocument.createElement(formatLine.getValue());
if (formatLine.getDescription() != null && !"".equals(formatLine.getDescription())) { if (formatLine.getDescription() != null && !"".equals(formatLine.getDescription()))
{
embeddedElement.appendChild(outDocument.createComment(formatLine.getDescription())); embeddedElement.appendChild(outDocument.createComment(formatLine.getDescription()));
} }
generateExportFormat(embeddedElement, embeddedFormat, rsEmbedded, poEmbedded, embeddedID, variableMap);
rootElement.appendChild(embeddedElement);
}
} finally { generateExportFormat(embeddedElement, embeddedFormat, instance, instance.get_ID(), variableMap);
try { rootElement.appendChild(embeddedElement);
if (rsEmbedded != null) rsEmbedded.close();
if (pstmt != null) pstmt.close();
} catch (SQLException ex) { }
rsEmbedded = null;
pstmt = null;
} }
} }

View File

@ -40,8 +40,8 @@ import java.util.Properties;
import javax.xml.xpath.XPathExpressionException; import javax.xml.xpath.XPathExpressionException;
import org.adempiere.exceptions.AdempiereException; import org.adempiere.exceptions.AdempiereException;
import org.adempiere.process.rpl.exp.ExportHelper;
import org.adempiere.process.rpl.XMLHelper; import org.adempiere.process.rpl.XMLHelper;
import org.adempiere.process.rpl.exp.ExportHelper;
import org.compiere.model.I_AD_Client; import org.compiere.model.I_AD_Client;
import org.compiere.model.MClient; import org.compiere.model.MClient;
import org.compiere.model.MColumn; import org.compiere.model.MColumn;
@ -52,7 +52,9 @@ import org.compiere.model.MTable;
import org.compiere.model.ModelValidator; import org.compiere.model.ModelValidator;
import org.compiere.model.PO; import org.compiere.model.PO;
import org.compiere.model.Query; import org.compiere.model.Query;
import org.compiere.model.X_AD_ReplicationDocument;
import org.compiere.model.X_AD_ReplicationTable; import org.compiere.model.X_AD_ReplicationTable;
import org.compiere.process.DocAction;
import org.compiere.util.CLogger; import org.compiere.util.CLogger;
import org.compiere.util.DisplayType; import org.compiere.util.DisplayType;
import org.compiere.util.Env; import org.compiere.util.Env;
@ -69,6 +71,8 @@ import org.w3c.dom.NodeList;
* @author victor.perez@e-evolution.com, e-Evolution * @author victor.perez@e-evolution.com, e-Evolution
* <li>[ 2195090 ] Stabilization of replication * <li>[ 2195090 ] Stabilization of replication
* <li>https://sourceforge.net/tracker/?func=detail&atid=879332&aid=2936561&group_id=176962 * <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 { public class ImportHelper {
@ -170,6 +174,8 @@ public class ImportHelper {
PO po = importElement(ctx, result, rootElement, expFormat, ReplicationType, trxName); PO po = importElement(ctx, result, rootElement, expFormat, ReplicationType, trxName);
if(po != null) if(po != null)
{
if(MReplicationStrategy.REPLICATION_TABLE==ReplicationMode)
{ {
// Here must invoke other method else we get cycle... // Here must invoke other method else we get cycle...
if ( ModelValidator.TYPE_BEFORE_DELETE == ReplicationEvent if ( ModelValidator.TYPE_BEFORE_DELETE == ReplicationEvent
@ -189,12 +195,16 @@ public class ImportHelper {
MReplicationStrategy.REPLICATION_TABLE, MReplicationStrategy.REPLICATION_TABLE,
X_AD_ReplicationTable.REPLICATIONTYPE_Merge, X_AD_ReplicationTable.REPLICATIONTYPE_Merge,
ModelValidator.TYPE_AFTER_CHANGE); ModelValidator.TYPE_AFTER_CHANGE);
} }
else if(X_AD_ReplicationTable.REPLICATIONTYPE_Merge.equals(ReplicationType) else if(X_AD_ReplicationTable.REPLICATIONTYPE_Merge.equals(ReplicationType)
|| X_AD_ReplicationTable.REPLICATIONTYPE_Reference.equals(ReplicationType)) || X_AD_ReplicationTable.REPLICATIONTYPE_Reference.equals(ReplicationType))
{
if(po.is_Changed())
{ {
po.saveReplica(true); po.saveReplica(true);
} }
}
/*else if (X_AD_ReplicationTable.REPLICATIONTYPE_Reference.equals(ReplicationType)) /*else if (X_AD_ReplicationTable.REPLICATIONTYPE_Reference.equals(ReplicationType))
{ {
//Do nothing?? //Do nothing??
@ -208,28 +218,19 @@ public class ImportHelper {
// Replication Type is not one of the possible values...ERROR // Replication Type is not one of the possible values...ERROR
throw new Exception(Msg.getMsg(ctx, "EXPReplicationTypeNonValidType")); 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 ;"); 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("=================== Beginnig of Format Line ===============================");
log.info("formatLine: [" + formatLine.toString() + "]"); log.info("formatLine: [" + formatLine.toString() + "]");
//Get the value //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("")) if (value == null || value.toString().equals(""))
continue; continue;
//Set the value //Set the value
@ -300,7 +301,7 @@ public class ImportHelper {
* @throws Exception * @throws Exception
*/ */
private Object getValueFromFormat(MEXPFormatLine line,PO po,Element rootElement, 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; Object value = null;
@ -315,7 +316,7 @@ public class ImportHelper {
{ {
// Referenced Export Format // Referenced Export Format
//get from cache //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); log.info("referencedExpFormat = " + referencedExpFormat);
int refRecord_ID = 0; int refRecord_ID = 0;
@ -329,7 +330,7 @@ public class ImportHelper {
log.info("referencedNode = " + referencedNode); log.info("referencedNode = " + referencedNode);
if(referencedNode!=null) 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); log.info("refRecord_ID = " + refRecord_ID);
value = new Integer(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 // Embedded Export Format It is used for Parent-Son records like Order&OrderLine
//get from cache //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); log.info("embeddedExpFormat = " + referencedExpFormat);
NodeList nodeList = XMLHelper.getNodeList("/"+rootElement.getNodeName() + "/" + line.getValue(), rootElement); NodeList nodeList = XMLHelper.getNodeList("/"+rootElement.getNodeName() + "/" + line.getValue(), rootElement);
@ -361,7 +362,7 @@ public class ImportHelper {
PO embeddedPo = null; PO embeddedPo = null;
// Import embedded PO // Import embedded PO
log.info("=== BEGIN RECURSION CALL ==="); 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); log.info("embeddedPo = " + embeddedPo);
embeddedPo.saveReplica(true); embeddedPo.saveReplica(true);
result.append(" Embedded Save Successful ; "); 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 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 (value !=null)
{ {
if (!MEXPFormatLine.TYPE_EmbeddedEXPFormat.equals(line.getType()) ) if (!MEXPFormatLine.TYPE_EmbeddedEXPFormat.equals(line.getType()) )
{ {
MColumn column = MColumn.get(ctx, line.getAD_Column_ID());
log.info("column=[" + column + "]");
// Clazz // Clazz
Class clazz = DisplayType.getClass(column.getAD_Reference_ID(), true); Class clazz = DisplayType.getClass(column.getAD_Reference_ID(), true);
@ -481,7 +483,11 @@ public class ImportHelper {
} }
else if(DisplayType.YesNo == column.getAD_Reference_ID()) 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 else
{ {
@ -491,7 +497,8 @@ public class ImportHelper {
if(clazz == Boolean.class) 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 else
{ {
@ -565,6 +572,7 @@ public class ImportHelper {
throw new AdempiereException(Msg.getMsg(ctx, "EXPFormatLineNoUniqueColumns")); throw new AdempiereException(Msg.getMsg(ctx, "EXPFormatLineNoUniqueColumns"));
} }
int replication_id = 0;
Object[] cols = new Object[uniqueFormatLines.size()]; Object[] cols = new Object[uniqueFormatLines.size()];
Object[] params = new Object[uniqueFormatLines.size()]; Object[] params = new Object[uniqueFormatLines.size()];
StringBuffer whereClause= new StringBuffer(""); StringBuffer whereClause= new StringBuffer("");
@ -634,6 +642,10 @@ public class ImportHelper {
{ {
//double doubleValue = Double.parseDouble(value.toString()); //double doubleValue = Double.parseDouble(value.toString());
value = new Integer(value.toString()); value = new Integer(value.toString());
if (DisplayType.ID == column.getAD_Reference_ID())
{
replication_id = (Integer) value;
}
} }
else else
{ {
@ -671,7 +683,14 @@ public class ImportHelper {
if(values.size()<=0)//Means that is a new record 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. 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 * @author Victor Perez, e-Evolution SC
* <li>[ 2195894 ] Improve performance in PO engine * <li>[ 2195894 ] Improve performance in PO engine
* <li>http://sourceforge.net/tracker/index.php?func=detail&aid=2195894&group_id=176962&atid=879335 * <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 public abstract class PO
implements Serializable, Comparator, Evaluatee implements Serializable, Comparator, Evaluatee
@ -2512,6 +2514,14 @@ public abstract class PO
int no = saveNew_getID(); int no = saveNew_getID();
if (no <= 0) if (no <= 0)
no = DB.getNextID(getAD_Client_ID(), p_info.getTableName(), m_trxName); 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) if (no <= 0)
{ {
log.severe("No NextID (" + no + ")"); log.severe("No NextID (" + no + ")");