platform/bb/RubyVM/src/com/rho/sync/SyncSource.java in rhodes-2.2.4.beta.1 vs platform/bb/RubyVM/src/com/rho/sync/SyncSource.java in rhodes-2.2.5.beta.1
- old
+ new
@@ -75,10 +75,11 @@
int m_nCurPageCount, m_nInserted, m_nDeleted, m_nTotalCount, m_nAttribCounter=0;
boolean m_bGetAtLeastOnePage = false;
int m_nErrCode = RhoAppAdapter.ERR_NONE;
String m_strError = "";
+ String m_strErrorType = "";
//String m_strPushBody = "";
Vector/*Ptr<CSyncBlob*>*/ m_arSyncBlobs = new Vector();
int m_nRefreshTime = 0;
@@ -208,11 +209,11 @@
TimeInterval startTime = TimeInterval.getCurrentTime();
//m_bIsSearch = false;
try{
- if ( isTokenFromDB() && !isEmptyToken() )
+ if ( isTokenFromDB() && getToken() > 1 )
syncServerChanges(); //sync only server changes, which was paused before
else
{
if ( isEmptyToken() )
processToken(1);
@@ -312,33 +313,40 @@
if ( bSend )
{
LOG.INFO( "Push client changes to server. Source: " + getName() + "Size :" + strBody.length() );
LOG.TRACE("Push body: " + strBody);
- if ( m_arMultipartItems.size() > 0 )
- {
- MultipartItem oItem = new MultipartItem();
- oItem.m_strBody = strBody;
- //oItem.m_strContentType = getProtocol().getContentType();
- oItem.m_strName = "cud";
- m_arMultipartItems.addElement(oItem);
-
- NetResponse resp = getNet().pushMultipartData( getProtocol().getClientChangesUrl(), m_arMultipartItems, getSync(), null );
- if ( !resp.isOK() )
- {
- getSync().setState(SyncEngine.esStop);
- m_nErrCode = RhoAppAdapter.ERR_REMOTESERVER;
- }
- }else
- {
- NetResponse resp = getNet().pushData( getProtocol().getClientChangesUrl(), strBody, getSync());
- if ( !resp.isOK() )
- {
- getSync().setState(SyncEngine.esStop);
- m_nErrCode = RhoAppAdapter.ERR_REMOTESERVER;
- }
- }
+ try{
+ if ( m_arMultipartItems.size() > 0 )
+ {
+ MultipartItem oItem = new MultipartItem();
+ oItem.m_strBody = strBody;
+ //oItem.m_strContentType = getProtocol().getContentType();
+ oItem.m_strName = "cud";
+ m_arMultipartItems.addElement(oItem);
+
+ NetResponse resp = getNet().pushMultipartData( getProtocol().getClientChangesUrl(), m_arMultipartItems, getSync(), null );
+ if ( !resp.isOK() )
+ {
+ getSync().setState(SyncEngine.esStop);
+ m_nErrCode = RhoAppAdapter.ERR_REMOTESERVER;
+ }
+ }else
+ {
+ NetResponse resp = getNet().pushData( getProtocol().getClientChangesUrl(), strBody, getSync());
+ if ( !resp.isOK() )
+ {
+ getSync().setState(SyncEngine.esStop);
+ m_nErrCode = RhoAppAdapter.ERR_REMOTESERVER;
+ }
+ }
+ }catch(Exception exc)
+ {
+ m_nErrCode = RhoAppAdapter.getNetErrorCode(exc);
+ throw exc;
+ }
+
}
for( i = 0; i < 3 && getSync().isContinueSync(); i++ )
{
if ( arUpdateSent[i] )
@@ -501,20 +509,29 @@
m_nErrCode = RhoAppAdapter.getNetErrorCode(exc);
throw exc;
}
String szData = resp.getCharData();
+ //String szData = "[{\"version\":3},{\"token\":\"\"},{\"count\":0},{\"progress_count\":28},{\"total_count\":28},{\"source-error\":{\"login-error\":{\"message\":\"s currently connected from another machine\"}}}]";
+ //String szData = "[{\"version\":3},{\"token\":\"\"},{\"count\":0},{\"progress_count\":0},{\"total_count\":0},{\"create-error\":{\"0_broken_object_id\":{\"name\":\"wrongname\",\"an_attribute\":\"error create\"},\"0_broken_object_id-error\":{\"message\":\"error create\"}}}]";
+ //String szData = "[{\"version\":3},{\"token\":\"35639160294387\"},{\"count\":3},{\"progress_count\":0},{\"total_count\":3},{\"metadata\":\"{\\\"foo\\\":\\\"bar\\\"}\",\"insert\":{\"1\":{\"price\":\"199.99\",\"brand\":\"Apple\",\"name\":\"iPhone\"}}}]";
PROF.START("Parse");
JSONArrayIterator oJsonArr = new JSONArrayIterator(szData);
PROF.STOP("Parse");
processServerResponse_ver3(oJsonArr);
+ if (getSync().getSourceOptions().getBoolProperty(getID(), "pass_through"))
+ processToken(0);
+
if ( getToken() == 0 )
break;
}
+
+ if ( getSync().isSchemaChanged() )
+ getSync().stopSync();
}
void processServerResponse_ver3(JSONArrayIterator oJsonArr)throws Exception
{
PROF.START("Data1");
@@ -569,18 +586,10 @@
if ( !oJsonArr.isEnd() && oJsonArr.getCurItem().hasName("total_count") )
{
setTotalCount(oJsonArr.getCurItem().getInt("total_count"));
oJsonArr.next();
}
- /* if ( !oJsonArr.isEnd() && oJsonArr.getCurItem().hasName("source-error") )
- {
- CJSONEntry oJsonErr = oJsonArr.getCurItem().getEntry("source-error");
- m_strError = oJsonErr.getString("message");
- m_nErrCode = RhoAppAdapter.ERR_CUSTOMSYNCSERVER;
- getSync().stopSync();
- return;
- }*/
//if ( getServerObjectsCount() == 0 )
// getNotify().fireSyncNotification(this, false, RhoAppAdapter.ERR_NONE, "");
if ( getToken() == 0 )
@@ -600,14 +609,54 @@
JSONEntry oCmds = oJsonArr.getCurItem();
PROF.START("Data");
if ( oCmds.hasName("schema-changed") )
{
- getSync().stopSync();
getSync().setSchemaChanged(true);
+ }else if ( oCmds.hasName("source-error") )
+ {
+ JSONEntry errSrc = oCmds.getEntry("source-error");
+ JSONStructIterator errIter = new JSONStructIterator(errSrc);
+ for( ; !errIter.isEnd(); errIter.next() )
+ {
+ m_nErrCode = RhoAppAdapter.ERR_CUSTOMSYNCSERVER;
+ m_strError = errIter.getCurValue().getString("message");
+ m_strErrorType = errIter.getCurKey();
+ }
+ }else if ( oCmds.hasName("search-error") )
+ {
+ JSONEntry errSrc = oCmds.getEntry("search-error");
+ JSONStructIterator errIter = new JSONStructIterator(errSrc);
+ for( ; !errIter.isEnd(); errIter.next() )
+ {
+ m_nErrCode = RhoAppAdapter.ERR_CUSTOMSYNCSERVER;
+ m_strError = errIter.getCurValue().getString("message");
+ m_strErrorType = errIter.getCurKey();
+ }
+ }else if ( oCmds.hasName("create-error") )
+ {
+ m_nErrCode = RhoAppAdapter.ERR_CUSTOMSYNCSERVER;
+ m_strErrorType = "create-error";
+ }else if ( oCmds.hasName("update-error") )
+ {
+ m_nErrCode = RhoAppAdapter.ERR_CUSTOMSYNCSERVER;
+ m_strErrorType = "update-error";
+ }else if ( oCmds.hasName("delete-error") )
+ {
+ m_nErrCode = RhoAppAdapter.ERR_CUSTOMSYNCSERVER;
+ m_strErrorType = "delete-error";
}else
{
getDB().startTransaction();
+
+ if (getSync().getSourceOptions().getBoolProperty(getID(), "pass_through"))
+ {
+ if ( m_bSchemaSource )
+ getDB().executeSQL( "DELETE FROM " + getName() );
+ else
+ getDB().executeSQL( "DELETE FROM object_values WHERE source_id=?", getID() );
+ }
+
if ( oCmds.hasName("metadata") && getSync().isContinueSync() )
{
String strMetadata = oCmds.getString("metadata");
getDB().executeSQL("UPDATE sources SET metadata=? WHERE source_id=?", strMetadata, getID() );
}