Esempio n. 1
0
        public SyncSource(int id, String name, String strSyncType, DBAdapter db, SyncEngine syncEngine)
        {
            m_syncEngine  = syncEngine;
            m_dbAdapter   = db;
            m_nID         = id;
            m_strName     = name;
            m_strSyncType = strSyncType;

            m_nCurPageCount      = 0;
            m_nInserted          = 0;
            m_nDeleted           = 0;
            m_nTotalCount        = 0;
            m_bGetAtLeastOnePage = false;

            m_nErrCode = RhoAppAdapter.ERR_NONE;

            IDBResult res = db.executeSQL("SELECT token,associations from sources WHERE source_id=?", m_nID);

            if (!res.isEnd())
            {
                m_token        = res.getLongByIdx(0);
                m_bTokenFromDB = true;
            }
            else
            {
                m_token        = 0;
                m_bTokenFromDB = true;
            }

            m_bSchemaSource = db.isTableExist(m_strName);
            parseAssociations(res.getStringByIdx(1));
        }
Esempio n. 2
0
        private boolean doRegister(SyncEngine oSync)
        {
            String session = oSync.loadSession();

            if (session == null || session.length() == 0)
            {
                m_nPollInterval = POLL_INTERVAL_INFINITE;
                return(false);
            }
            m_nPollInterval = POLL_INTERVAL_SECONDS;

            String client_id = oSync.loadClientID();

            if (client_id == null || client_id.length() == 0)
            {
                return(false);
            }

            IDBResult res = DBAdapter.getUserDB().executeSQL("SELECT token,token_sent from client_info");

            if (!res.isEnd())
            {
                String  token      = res.getStringByIdx(0);
                boolean token_sent = res.getIntByIdx(1) > 0 && !RHOCONF().getBool("register_push_at_startup");
                if (m_strDevicePin.equals(token) && token_sent)
                {
                    //token in db same as new one and it was already send to the server
                    //so we do nothing
                    return(true);
                }
            }

            String      strBody = getRegisterBody(client_id);
            NetResponse resp    = getNet().pushData(oSync.getProtocol().getClientRegisterUrl(), strBody, oSync);

            if (resp.isOK())
            {
                try {
                    DBAdapter.getUserDB().executeSQL("UPDATE client_info SET token_sent=?, token=?", 1, m_strDevicePin);
                } catch (Exception ex) {
                    LOG.ERROR("Error saving token_sent to the DB...", ex);
                }
                LOG.INFO("Registered client sucessfully...");
                return(true);
            }
            else
            {
                LOG.INFO("Network error POST-ing device pin to the server...");
            }

            return(false);
        }
Esempio n. 3
0
        public SyncSource(SyncEngine syncEngine, DBAdapter db)
        {
            m_syncEngine = syncEngine;
            m_dbAdapter  = db;

            m_nID = 0;

            m_bTokenFromDB = true;

            m_nCurPageCount      = 0;
            m_nInserted          = 0;
            m_nDeleted           = 0;
            m_nTotalCount        = 0;
            m_bGetAtLeastOnePage = false;

            m_nErrCode      = RhoAppAdapter.ERR_NONE;
            m_bSchemaSource = db.isTableExist(m_strName);
        }
Esempio n. 4
0
        SyncThread()
        {
            CThreadQueue.setLogCategory(LOG.getLogCategory());

            if (RhoConf.getInstance().isExist("sync_poll_interval"))
            {
                setPollInterval(RhoConf.getInstance().getInt("sync_poll_interval"));
            }

            m_oSyncEngine = new SyncEngine();
            m_oSyncEngine.setFactory();

            LOG.INFO("sync_poll_interval: " + RhoConf.getInstance().getInt("sync_poll_interval"));
            LOG.INFO("syncserver: " + RhoConf.getInstance().getString("syncserver"));
            LOG.INFO("bulksync_state: " + RhoConf.getInstance().getInt("bulksync_state"));

            //ClientRegister.Create();

            if (RhoConf.getInstance().getString("syncserver").length() > 0)
            {
                start(epLow);
            }
        }
Esempio n. 5
0
        public SyncSource(int id, String name, String strSyncType, DBAdapter db, SyncEngine syncEngine )
        {
    	    m_syncEngine = syncEngine;
    	    m_dbAdapter = db;
            m_nID = id;
            m_strName = name;
            m_strSyncType = strSyncType;
        
            m_nCurPageCount = 0;
            m_nInserted = 0;
            m_nDeleted = 0;
            m_nTotalCount = 0;
            m_bGetAtLeastOnePage = false;

            m_nErrCode = RhoAppAdapter.ERR_NONE;

            IDBResult res = db.executeSQL("SELECT token,associations from sources WHERE source_id=?", m_nID);
            if ( !res.isEnd() )
            {
        	    m_token = res.getLongByIdx(0);
                m_bTokenFromDB = true;
            }else
            {
        	    m_token = 0;
                m_bTokenFromDB = true;
            }
        
            m_bSchemaSource = db.isTableExist(m_strName);
            parseAssociations(res.getStringByIdx(1));
        }
Esempio n. 6
0
        public SyncSource(SyncEngine syncEngine, DBAdapter db)
        {
    	    m_syncEngine = syncEngine;
    	    m_dbAdapter = db;
    	
            m_nID = 0;
        
            m_bTokenFromDB = true;

            m_nCurPageCount = 0;
            m_nInserted = 0;
            m_nDeleted = 0;
            m_nTotalCount = 0;
            m_bGetAtLeastOnePage = false;

            m_nErrCode = RhoAppAdapter.ERR_NONE;
            m_bSchemaSource = db.isTableExist(m_strName);
        }
Esempio n. 7
0
     public SyncNotify( SyncEngine syncEngine ) 
     {
 	    m_syncEngine = syncEngine;
     }
Esempio n. 8
0
        private boolean doRegister(	SyncEngine oSync )
        {
    	    String session = oSync.loadSession();
    	    if ( session == null || session.length() == 0 )
    	    {
    		    m_nPollInterval = POLL_INTERVAL_INFINITE;    		
    		    return false;
    	    }
		    m_nPollInterval = POLL_INTERVAL_SECONDS;    		
    	
		    String client_id = oSync.loadClientID();
		    if ( client_id == null || client_id.length() == 0 )
			    return false;
    	
		    IDBResult res = DBAdapter.getUserDB().executeSQL("SELECT token,token_sent from client_info");
            if ( !res.isEnd() ) {
			    String token = res.getStringByIdx(0); 
			    int token_sent = res.getIntByIdx(1);
			    if ( m_strDevicePin.equals(token) && token_sent > 0 ) 
			    {
				    //token in db same as new one and it was already send to the server
				    //so we do nothing
				    return true; 
			    }
            }

	        String strBody = getRegisterBody(client_id);
            NetResponse resp = getNet().pushData( oSync.getProtocol().getClientRegisterUrl(), strBody, oSync );
		    if( resp.isOK() ) 
		    {
			    try {
				    DBAdapter.getUserDB().executeSQL("UPDATE client_info SET token_sent=?, token=?", 1, m_strDevicePin );
			    } catch(Exception ex) {
				    LOG.ERROR("Error saving token_sent to the DB...", ex);
			    }	
			    LOG.INFO("Registered client sucessfully...");
			    return true;
		    } else {
			    LOG.INFO("Network error POST-ing device pin to the server...");
		    }
		
		    return false;
        }
Esempio n. 9
0
 public SyncNotify(SyncEngine syncEngine)
 {
     m_syncEngine = syncEngine;
 }
Esempio n. 10
0
        public void processServerResponse_ver3(JSONArrayIterator oJsonArr)
        {
            PROF.START("Data1");

            int nVersion = 0;

            if (!oJsonArr.isEnd() && oJsonArr.getCurItem().hasName("version"))
            {
                nVersion = oJsonArr.getCurItem().getInt("version");
                oJsonArr.next();
            }

            if (nVersion != getProtocol().getVersion())
            {
                LOG.ERROR("Sync server send data with incompatible version. Client version: " + getProtocol().getVersion() +
                          "; Server response version: " + nVersion + ". Source name: " + getName());
                getSync().stopSync();
                m_nErrCode = RhoAppAdapter.ERR_UNEXPECTEDSERVERRESPONSE;
                return;
            }

            if (!oJsonArr.isEnd() && oJsonArr.getCurItem().hasName("token"))
            {
                processToken(oJsonArr.getCurItem().getUInt64("token"));
                oJsonArr.next();
            }

            if (!oJsonArr.isEnd() && oJsonArr.getCurItem().hasName("source"))
            {
                //skip it. it uses in search only
                oJsonArr.next();
            }

            if (!oJsonArr.isEnd() && oJsonArr.getCurItem().hasName("count"))
            {
                setCurPageCount(oJsonArr.getCurItem().getInt("count"));
                oJsonArr.next();
            }

            if (!oJsonArr.isEnd() && oJsonArr.getCurItem().hasName("refresh_time"))
            {
                setRefreshTime(oJsonArr.getCurItem().getInt("refresh_time"));
                oJsonArr.next();
            }

            if (!oJsonArr.isEnd() && oJsonArr.getCurItem().hasName("progress_count"))
            {
                //TODO: progress_count
                //setTotalCount(oJsonArr.getCurItem().getInt("progress_count"));
                oJsonArr.next();
            }

            if (!oJsonArr.isEnd() && oJsonArr.getCurItem().hasName("total_count"))
            {
                setTotalCount(oJsonArr.getCurItem().getInt("total_count"));
                oJsonArr.next();
            }

            //if ( getServerObjectsCount() == 0 )
            //    getNotify().fireSyncNotification(this, false, RhoAppAdapter.ERR_NONE, "");

            if (getToken() == 0)
            {
                //oo conflicts
                getDB().executeSQL("DELETE FROM changed_values where source_id=? and sent>=3", getID());
                //
            }

            LOG.INFO("Got " + getCurPageCount() + "(Processed: " + getServerObjectsCount() + ") records of " + getTotalCount() + " from server. Source: " + getName()
                     + ". Version: " + nVersion);

            PROF.STOP("Data1");
            if (!oJsonArr.isEnd() && getSync().isContinueSync())
            {
                JSONEntry oCmds = oJsonArr.getCurItem();
                PROF.START("Data");

                if (oCmds.hasName("schema-changed"))
                {
                    getSync().setSchemaChanged(true);
                }
                else if (!processServerErrors(oCmds))
                {
                    getDB().startTransaction();

                    if (SyncEngine.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());
                    }
                    if (oCmds.hasName("links") && getSync().isContinueSync())
                    {
                        processSyncCommand("links", oCmds.getEntry("links"), true);
                    }
                    if (oCmds.hasName("delete") && getSync().isContinueSync())
                    {
                        processSyncCommand("delete", oCmds.getEntry("delete"), true);
                    }
                    if (oCmds.hasName("insert") && getSync().isContinueSync())
                    {
                        processSyncCommand("insert", oCmds.getEntry("insert"), true);
                    }

                    PROF.STOP("Data");

                    PROF.START("DB");
                    getDB().endTransaction();
                    PROF.STOP("DB");

                    getNotify().fireObjectsNotification();
                }
            }

            PROF.START("Data1");
            if (getCurPageCount() > 0)
            {
                getNotify().fireSyncNotification(this, false, RhoAppAdapter.ERR_NONE, "");
            }
            PROF.STOP("Data1");
        }
Esempio n. 11
0
        void syncServerChanges()
        {
            LOG.INFO("Sync server changes source ID :" + getID());

            while (getSync().isContinueSync())
            {
                setCurPageCount(0);
                String strUrl   = getProtocol().getServerQueryUrl("");
                String strQuery = getProtocol().getServerQueryBody(getName(), getSync().getClientID(), getSync().getSyncPageSize());

                if (!m_bTokenFromDB && getToken() > 1)
                {
                    strQuery += "&token=" + getToken();
                }

                LOG.INFO("Pull changes from server. Url: " + (strUrl + strQuery));

                NetResponse resp = null;
                try{
                    PROF.START("Net");
                    resp = getNet().pullData(strUrl + strQuery, getSync());
                    PROF.STOP("Net");

                    if (!resp.isOK())
                    {
                        getSync().stopSync();
                        m_nErrCode = RhoAppAdapter.getErrorFromResponse(resp);
                        m_strError = resp.getCharData();
                        continue;
                    }
                }catch (Exception exc)
                {
                    m_nErrCode = RhoAppAdapter.getNetErrorCode(exc);
                    throw exc;
                }

                String szData      = null;
                String strTestResp = SyncEngine.getSourceOptions().getProperty(getID(), "rho_server_response");
                if (strTestResp != null && strTestResp.length() > 0)
                {
                    szData = strTestResp;
                }
                else
                {
                    szData = resp.getCharData();
                }

                PROF.START("Parse");
                JSONArrayIterator oJsonArr = new JSONArrayIterator(szData);
                PROF.STOP("Parse");

                processServerResponse_ver3(oJsonArr);

                if (SyncEngine.getSourceOptions().getBoolProperty(getID(), "pass_through"))
                {
                    processToken(0);
                }

                if (getToken() == 0)
                {
                    break;
                }
            }

            if (getSync().isSchemaChanged())
            {
                getSync().stopSync();
            }
        }
Esempio n. 12
0
	    SyncThread()
	    {
		    CThreadQueue.setLogCategory(LOG.getLogCategory());
		
		    if( RhoConf.getInstance().isExist("sync_poll_interval") )
			    setPollInterval(RhoConf.getInstance().getInt("sync_poll_interval"));

		    m_oSyncEngine = new SyncEngine();
		    m_oSyncEngine.setFactory();

	        LOG.INFO("sync_poll_interval: " + RhoConf.getInstance().getInt("sync_poll_interval"));
	        LOG.INFO("syncserver: " + RhoConf.getInstance().getString("syncserver"));
	        LOG.INFO("bulksync_state: " + RhoConf.getInstance().getInt("bulksync_state"));
	    
	        //ClientRegister.Create();
	    
		    if ( RhoConf.getInstance().getString("syncserver").length() > 0 )
			    start(epLow);
	    }