platform/bb/RubyVM/src/com/rho/sync/SyncSource.java in rhodes-3.0.2 vs platform/bb/RubyVM/src/com/rho/sync/SyncSource.java in rhodes-3.1.0.beta.1

- old
+ new

@@ -1,26 +1,35 @@ -/* - * rhodes - * - * Copyright (C) 2008 Rhomobile, Inc. All rights reserved. - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see <http://www.gnu.org/licenses/>. - */ +/*------------------------------------------------------------------------ +* (The MIT License) +* +* Copyright (c) 2008-2011 Rhomobile, Inc. +* +* Permission is hereby granted, free of charge, to any person obtaining a copy +* of this software and associated documentation files (the "Software"), to deal +* in the Software without restriction, including without limitation the rights +* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +* copies of the Software, and to permit persons to whom the Software is +* furnished to do so, subject to the following conditions: +* +* The above copyright notice and this permission notice shall be included in +* all copies or substantial portions of the Software. +* +* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +* THE SOFTWARE. +* +* http://rhomobile.com +*------------------------------------------------------------------------*/ + package com.rho.sync; import com.rho.RhoClassFactory; +import com.rho.RhoConf; import com.rho.RhoEmptyLogger; import com.rho.RhoEmptyProfiler; import com.rho.RhoLogger; import com.rho.RhoProfiler; import com.rho.RhodesApp; @@ -42,11 +51,13 @@ private static final RhoLogger LOG = RhoLogger.RHO_STRIP_LOG ? new RhoEmptyLogger() : new RhoLogger("Sync"); private static final RhoProfiler PROF = RhoProfiler.RHO_STRIP_PROFILER ? new RhoEmptyProfiler() : new RhoProfiler(); - + + RhoConf RHOCONF(){ return RhoConf.getInstance(); } + static class CAttrValue { String m_strAttrib = ""; String m_strValue = ""; String m_strBlobSuffix = ""; @@ -405,11 +416,12 @@ } if ( bSend && getSync().isContinueSync() ) { LOG.INFO( "Push client changes to server. Source: " + getName() + "Size :" + strBody.length() ); - LOG.TRACE("Push body: " + strBody); + if ( !RHOCONF().getBool("log_skip_post") ) + LOG.TRACE("Push body: " + strBody); try{ if ( m_arMultipartItems.size() > 0 ) { MultipartItem oItem = new MultipartItem(); @@ -438,24 +450,24 @@ }catch(Exception exc) { m_nErrCode = RhoAppAdapter.getNetErrorCode(exc); throw exc; } - - } - for( i = 0; i < 3 && m_nErrCode == RhoAppAdapter.ERR_NONE; i++ ) - { - if ( arUpdateSent[i] ) - { - //oo conflicts - if ( i < 1 && !getSync().getSourceOptions().getBoolProperty(getID(), "pass_through") ) //create - getDB().executeSQL("UPDATE changed_values SET sent=2 WHERE source_id=? and update_type=? and sent=1", getID(), arUpdateTypes[i] ); - else - // - getDB().executeSQL("DELETE FROM changed_values WHERE source_id=? and update_type=? and sent=1", getID(), arUpdateTypes[i] ); - } + for( i = 0; i < 3 && m_nErrCode == RhoAppAdapter.ERR_NONE; i++ ) + { + if ( arUpdateSent[i] ) + { + //oo conflicts + if ( i < 1 && !getSync().getSourceOptions().getBoolProperty(getID(), "pass_through") ) //create + getDB().executeSQL("UPDATE changed_values SET sent=2 WHERE source_id=? and update_type=? and sent=1", getID(), arUpdateTypes[i] ); + else + // + getDB().executeSQL("DELETE FROM changed_values WHERE source_id=? and update_type=? and sent=1", getID(), arUpdateTypes[i] ); + } + } + } m_arMultipartItems.removeAllElements(); m_arBlobAttrs.removeAllElements(); } @@ -489,14 +501,14 @@ String strAttrib = res.getStringByIdx(0); String strObject = res.getStringByIdx(1); String value = res.getStringByIdx(2); String attribType = res.getStringByIdx(3); - if ( m_hashIgnorePushObjects.containsKey(strObject) ) + if ( m_hashIgnorePushObjects.containsKey(strObject) || strObject.length() == 0 ) continue; - if ( attribType.compareTo("blob.file") == 0 ) + if ( attribType.compareTo("blob.file") == 0 && value.length() > 0 ) { MultipartItem oItem = new MultipartItem(); oItem.m_strFilePath = RhodesApp.getInstance().resolveDBFilesPath(value); oItem.m_strContentType = "application/octet-stream"; oItem.m_strName = strAttrib + "-" + strObject; @@ -640,11 +652,11 @@ } //{"create-error":{"0_broken_object_id":{"name":"wrongname","an_attribute":"error create"},"0_broken_object_id-error":{"message":"error create"}}} boolean processServerErrors(JSONEntry oCmds)throws Exception { - String arErrTypes[] = {"source-error", "search-error", "create-error", "update-error", "delete-error", null}; + String arErrTypes[] = {"source-error", "search-error", "create-error", "update-error", "delete-error", "update-rollback", null}; boolean bRes = false; for( int i = 0; ; i++ ) { if ( arErrTypes[i] == null ) break; @@ -670,10 +682,10 @@ m_strServerError += "server_errors[" + URI.urlEncode(strKey) + "][message]=" + URI.urlEncode(errIter.getCurValue().getString("message")); } } else { - //"create-error", "update-error", "delete-error" + //"create-error", "update-error", "delete-error", "update-rollback" String strObject = strKey; if ( strObject.endsWith("-error") ) { strObject = strObject.substring(0, strKey.length()-6);