use of org.compiere.model.MReplicationLog in project adempiere by adempiere.
the class ReplicationLocal method sendUpdatesTable.
// sendUpdates
/**
* Send UPdates to Remote
* @param AD_Table_ID table id
* @param TableName table
* @param AD_ReplicationTable_ID id
* @return true if success
* @throws Exception
*/
private boolean sendUpdatesTable(int AD_Table_ID, String TableName, int AD_ReplicationTable_ID) throws Exception {
RemoteUpdateVO data = new RemoteUpdateVO();
data.Test = m_test;
data.TableName = TableName;
// Create SQL
StringBuffer sql = new StringBuffer("SELECT * FROM ").append(TableName).append(" WHERE AD_Client_ID=").append(m_replication.getRemote_Client_ID());
if (m_replication.getRemote_Org_ID() != 0)
sql.append(" AND AD_Org_ID IN (0,").append(m_replication.getRemote_Org_ID()).append(")");
if (m_replication.getDateLastRun() != null)
sql.append(" AND Updated >= ").append(DB.TO_DATE(m_replication.getDateLastRun(), false));
sql.append(" ORDER BY ");
data.KeyColumns = getKeyColumns(AD_Table_ID);
if (data.KeyColumns == null || data.KeyColumns.length == 0) {
log.log(Level.SEVERE, "sendUpdatesTable - No KeyColumns for " + TableName);
m_replicated = false;
return false;
}
for (int i = 0; i < data.KeyColumns.length; i++) {
if (i > 0)
sql.append(",");
sql.append(data.KeyColumns[i]);
}
data.Sql = sql.toString();
// New Data
data.CentralData = getRowSet(data.Sql, null);
if (data.CentralData == null) {
log.fine("sendUpdatesTable - Null - " + TableName);
m_replicated = false;
return false;
}
int rows = 0;
try {
if (data.CentralData.last())
rows = data.CentralData.getRow();
// rewind
data.CentralData.beforeFirst();
} catch (SQLException ex) {
log.fine("RowCheck " + ex);
m_replicated = false;
return false;
}
if (rows == 0) {
log.fine("No Rows - " + TableName);
return true;
} else
log.fine(TableName + " #" + rows);
// Process Info
ProcessInfo pi = new ProcessInfo("SendUpdates", 0);
pi.setClassName(REMOTE);
pi.setSerializableObject(data);
// send it
pi = m_serverRemote.process(new Properties(), pi);
log.info("sendUpdatesTable - " + pi);
ProcessInfoLog[] logs = pi.getLogs();
String msg = "> ";
if (logs != null && logs.length > 0)
// Remote Message
msg += logs[0].getP_Msg();
//
MReplicationLog rLog = new MReplicationLog(getCtx(), m_replicationRun.getAD_Replication_Run_ID(), AD_ReplicationTable_ID, msg, get_TrxName());
if (pi.isError())
m_replicated = false;
rLog.setIsReplicated(!pi.isError());
rLog.saveEx();
return !pi.isError();
}
use of org.compiere.model.MReplicationLog in project adempiere by adempiere.
the class ReplicationLocal method mergeDataTable.
// mergeData
/**
* Receive New Data from Remote (and send local updates)
* @param AD_Table_ID table id
* @param TableName table name
* @param AD_ReplicationTable_ID id
* @return true if success
* @throws java.lang.Exception
*/
private boolean mergeDataTable(int AD_Table_ID, String TableName, int AD_ReplicationTable_ID) throws Exception {
RemoteMergeDataVO data = new RemoteMergeDataVO();
data.Test = m_test;
data.TableName = TableName;
// Create SQL
StringBuffer sql = new StringBuffer("SELECT * FROM ").append(TableName).append(" WHERE AD_Client_ID=").append(m_replication.getRemote_Client_ID());
if (m_replication.getRemote_Org_ID() != 0)
sql.append(" AND AD_Org_ID IN (0,").append(m_replication.getRemote_Org_ID()).append(")");
if (m_replication.getDateLastRun() != null)
sql.append(" AND Updated >= ").append(DB.TO_DATE(m_replication.getDateLastRun(), false));
sql.append(" ORDER BY ");
data.KeyColumns = getKeyColumns(AD_Table_ID);
if (data.KeyColumns == null || data.KeyColumns.length == 0) {
log.log(Level.SEVERE, "mergeDataTable - No KeyColumns for " + TableName);
m_replicated = false;
return false;
}
for (int i = 0; i < data.KeyColumns.length; i++) {
if (i > 0)
sql.append(",");
sql.append(data.KeyColumns[i]);
}
data.Sql = sql.toString();
// New Central Data
data.CentralData = getRowSet(data.Sql, null);
if (data.CentralData == null) {
log.fine("mergeDataTable - CentralData is Null - " + TableName);
m_replicated = false;
return false;
}
// Process Info
ProcessInfo pi = new ProcessInfo("MergeData", 0);
pi.setClassName(REMOTE);
pi.setSerializableObject(data);
// send it
pi = m_serverRemote.process(new Properties(), pi);
ProcessInfoLog[] logs = pi.getLogs();
String msg = "< ";
if (logs != null && logs.length > 0)
// Remote Message
msg += logs[0].getP_Msg();
log.info("mergeDataTable - " + pi);
//
MReplicationLog rLog = new MReplicationLog(getCtx(), m_replicationRun.getAD_Replication_Run_ID(), AD_ReplicationTable_ID, msg, get_TrxName());
if (pi.isError()) {
log.severe("mergeDataTable Error - " + pi);
m_replicated = false;
rLog.setIsReplicated(false);
} else // import data fom remote
{
RowSet sourceRS = (RowSet) pi.getSerializableObject();
RowSet targetRS = getRowSet(data.Sql, null);
Object result = doIt(START, "sync", new // Merge
Object[] { data.TableName, data.KeyColumns, sourceRS, targetRS, m_test, Boolean.TRUE });
boolean replicated = isReplicated(result);
if (replicated)
log.fine("mergeDataTable -> " + TableName + " - " + result);
else {
m_replicated = false;
log.severe("mergeDataTable -> " + TableName + " - " + result);
}
rLog.setIsReplicated(replicated);
if (result != null)
rLog.setP_Msg("< " + result.toString());
sourceRS.close();
sourceRS = null;
targetRS.close();
targetRS = null;
}
rLog.saveEx();
return !pi.isError();
}
Aggregations