Exemplo n.º 1
0
	    void processSyncCommand(String strCmd, JSONEntry oCmdEntry, boolean bCheckUIRequest)
	    {
	        JSONStructIterator objIter = new JSONStructIterator(oCmdEntry);

	        for( ; !objIter.isEnd() && getSync().isContinueSync(); objIter.next() )
	        {
	            String strObject = objIter.getCurKey();
	            JSONStructIterator attrIter = new JSONStructIterator( objIter.getCurValue() );
	        
	            try
	            {
		            if ( m_bSchemaSource )
		                processServerCmd_Ver3_Schema(strCmd,strObject,attrIter);
		            else
		            {
		                for( ; !attrIter.isEnd() && getSync().isContinueSync(); attrIter.next() )
		                {
		                    String strAttrib = attrIter.getCurKey();
		                    String strValue = attrIter.getCurString();
	
		                    processServerCmd_Ver3(strCmd,strObject,strAttrib,strValue);
		                }
		            }
	            }catch(DBException exc)
		        {
		    	    LOG.ERROR("Sync of server changes failed for " + getName() + ";object: " + strObject, exc);
		        }
		    
	            if ( getSyncType().compareTo("none") == 0 )
	        	    continue;
	        
	            if ( bCheckUIRequest )
	            {
		            int nSyncObjectCount  = getNotify().incLastSyncObjectCount(getID());
		            if ( getProgressStep() > 0 && (nSyncObjectCount%getProgressStep() == 0) )
		                getNotify().fireSyncNotification(this, false, RhoAppAdapter.ERR_NONE, "");
		        
		            if ( getDB().isUIWaitDB() )
		            {
			            LOG.INFO("Commit transaction because of UI request.");
		                getDB().endTransaction();
		                SyncThread.sleep(1000);
		                getDB().startTransaction();
		            }
	            }
	        }
	    }
Exemplo n.º 2
0
	    void processServerCmd_Ver3_Schema(String strCmd, String strObject, JSONStructIterator attrIter)
	    {
	        if ( strCmd.compareTo("insert") == 0 )
	        {
	            Vector<Object> vecValues = new Vector<Object>();
                Vector<String> vecAttrs = new Vector<String>();
	            String strCols = "", strQuest = "", strSet = "";
	            for( ; !attrIter.isEnd() && getSync().isContinueSync(); attrIter.next() )
	            {
	                CAttrValue oAttrValue = new CAttrValue(attrIter.getCurKey(),attrIter.getCurString());
	                if ( !processBlob(strCmd,strObject,oAttrValue) )
	                    continue;
	        	
	                if ( strCols.length() > 0 )
	                    strCols += ",";
	                if ( strQuest.length() > 0)
	                    strQuest += ",";
	                if ( strSet.length() > 0)
	                    strSet += ",";

	                strCols += oAttrValue.m_strAttrib;
	                strQuest += "?";
	                strSet += oAttrValue.m_strAttrib + "=?";
	                vecAttrs.addElement(oAttrValue.m_strAttrib);
	                vecValues.addElement(oAttrValue.m_strValue);
	            }
	            vecValues.addElement(strObject);
	            if ( strCols.length() > 0 )
	                strCols += ",";
	            if ( strQuest.length() > 0)
	                strQuest += ",";
	        
	            strCols += "object";
	            strQuest += "?";

	            String strSqlInsert = "INSERT INTO ";
	            strSqlInsert += getName() + " (";
	            strSqlInsert += strCols + ") VALUES(" + strQuest + ")";

	            if ( !getSync().isContinueSync() )
	                return;

	            IDBResult resInsert = getDB().executeSQLReportNonUniqueEx(strSqlInsert, vecValues );
	            if ( resInsert.isNonUnique() )
	            {
	                String strSqlUpdate = "UPDATE ";
	                strSqlUpdate += getName() + " SET " + strSet + " WHERE object=?";
	                getDB().executeSQLEx(strSqlUpdate, vecValues);

	                if ( getSyncType().compareTo("none") != 0 )
	                {
		                // oo conflicts
		                for( int i = 0; i < (int)vecAttrs.size(); i++ )
		                {
		                    getDB().executeSQL("UPDATE changed_values SET sent=4 where object=? and attrib=? and source_id=? and sent>1", 
		                        strObject, vecAttrs.elementAt(i), getID() );
		                }
		                //
	                }
	            }

	            if ( getSyncType().compareTo("none") != 0 )	        
	        	    getNotify().onObjectChanged(getID(),strObject, SyncNotify.enUpdate);
	        
	            m_nInserted++;
	        }else if (strCmd.compareTo("delete") == 0)
	        {
	    	    Vector<String> vecAttrs = new Vector<String>();
	            String strSet = "";
	            for( ; !attrIter.isEnd() && getSync().isContinueSync(); attrIter.next() )
	            {
	        	    CAttrValue oAttrValue = new CAttrValue(attrIter.getCurKey(),attrIter.getCurString());
	        	
	                if ( strSet.length() > 0 )
	                    strSet += ",";

	                vecAttrs.addElement(oAttrValue.m_strAttrib);
	                strSet += oAttrValue.m_strAttrib + "=NULL";
	            }

	            String strSqlUpdate = "UPDATE ";
	            strSqlUpdate += getName() + " SET " + strSet + " WHERE object=?";
	        
	            if ( strSet.length() == 0 || !getSync().isContinueSync() )
	                return;
	        
	            getDB().executeSQL(strSqlUpdate, strObject);
	            //Remove item if all nulls
	            String strSelect = "SELECT * FROM " + getName() + " WHERE object=?";
	            IDBResult res = getDB().executeSQL( strSelect, strObject );
	            if ( !res.isEnd() )
	            {
	                boolean bAllNulls = true;
	                for( int i = 0; i < res.getColCount(); i ++)
	                {
	                    if ( !res.isNullByIdx(i) && res.getColName(i).compareTo("object")!=0 )
	                    {
	                        bAllNulls = false;
	                        break;
	                    }
	                }

	                if (bAllNulls)
	                {
	                    String strDelete = "DELETE FROM " + getName() + " WHERE object=?";
	                    getDB().executeSQL( strDelete, strObject);
	                }
	            }
	        
	            if ( getSyncType().compareTo("none") != 0 )
	            {
		            getNotify().onObjectChanged(getID(), strObject, SyncNotify.enDelete);
		            // oo conflicts
		            for( int i = 0; i < (int)vecAttrs.size(); i++ )
		            {
		                getDB().executeSQL("UPDATE changed_values SET sent=3 where object=? and attrib=? and source_id=?", 
		                    strObject, vecAttrs.elementAt(i), getID() );
		            }
		            //
	            }
	        
	            m_nDeleted++;
	        }else if ( strCmd.compareTo("links") == 0 )
	        {
	            String strValue = attrIter.getCurString();
	            processAssociations(strObject, strValue);
	        
	            String strSqlUpdate = "UPDATE ";
	            strSqlUpdate += getName() + " SET object=? WHERE object=?";
	            getDB().executeSQL(strSqlUpdate, strValue, strObject);

	            getDB().executeSQL("UPDATE changed_values SET object=?,sent=3 where object=? and source_id=?", strValue, strObject, getID() );
	            getNotify().onObjectChanged(getID(), strObject, SyncNotify.enCreate);
	        }

	    }
Exemplo n.º 3
0
	    //{"create-error":{"0_broken_object_id":{"name":"wrongname","an_attribute":"error create"},"0_broken_object_id-error":{"message":"error create"}}}
	    boolean processServerErrors(JSONEntry oCmds)
	    {
	        String[] arErrTypes = {"source-error", "search-error", "create-error", "update-error", "delete-error", null};
	        boolean bRes = false;
	        for( int i = 0; ; i++ )
	        {
	            if ( arErrTypes[i] == null )
	                break;
	            if ( !oCmds.hasName(arErrTypes[i]) )
	                continue;

	            bRes = true;
	            m_nErrCode = RhoAppAdapter.ERR_CUSTOMSYNCSERVER;

	            JSONEntry errSrc = oCmds.getEntry(arErrTypes[i]);
	            JSONStructIterator errIter = new JSONStructIterator(errSrc);
	            for( ; !errIter.isEnd(); errIter.next() )
	            {
	                String strKey = errIter.getCurKey();

	                if ( i == 0 || i == 1 )//"source-error", "search-error" 
	                {
	                    if ( errIter.getCurValue().hasName("message") )
	                    {
	                	    if ( m_strServerError.length() > 0 )
	                		    m_strServerError += "&";
	                	
	                        m_strServerError += "server_errors[" + URI.urlEncode(strKey) + "][message]=" + URI.urlEncode(errIter.getCurValue().getString("message"));
	                    }
	                }
	                else
	                {
	                    //"create-error", "update-error", "delete-error"
	                    String strObject = strKey;

	                    if ( strObject.endsWith("-error") )
	                    {
	                        strObject = strObject.substring(0, strKey.length()-6);
	                	    if ( m_strServerError.length() > 0 )
	                		    m_strServerError += "&";
	                    
	                        m_strServerError += "server_errors[" + arErrTypes[i] + "][" + URI.urlEncode(strObject) + "][message]=" + URI.urlEncode(errIter.getCurValue().getString("message"));
	                    }else
	                    {
		                    JSONStructIterator attrIter = new JSONStructIterator(errIter.getCurValue());
		                    for( ; !attrIter.isEnd(); attrIter.next() )
		                    {
			                    String strAttrName = attrIter.getCurKey();
			                    String strAttrValue = attrIter.getCurString();
			                
			                    if ( m_strServerError.length() > 0 )
			                	    m_strServerError += "&";
			                
			                    m_strServerError += "server_errors[" + arErrTypes[i] + "][" + URI.urlEncode(strObject) + "][attributes][" + URI.urlEncode(strAttrName) + "]=" + URI.urlEncode(strAttrValue);
		                    }
	                    }
	                }
	            }
	        }

	        return bRes;
	    }