Beispiel #1
0
    static void loadAttrs(DBAdapter db, Hashtable< int, Hashtable<String,int> > mapAttrs, String strDBAttr,
        Hashtable<String, int> mapSrcNames)
    {
        mapAttrs.clear();
        String strSql = "SELECT source_id,";
        strSql += strDBAttr + ",name from sources";
    	
	    IDBResult res = db.executeSQL(strSql);
	    for ( ; !res.isEnd(); res.next() )
	    { 
	        int nSrcID = res.getIntByIdx(0);
	        String strAttribs = res.getStringByIdx(1);
	        if ( strAttribs.length() == 0 )
	            continue;
	
	        Tokenizer oTokenizer = new Tokenizer( strAttribs, "," );
	
	        Hashtable<String,int> mapAttr = new Hashtable<String,int>();
	        String strAttr = "";
			while (oTokenizer.hasMoreTokens()) 
	        {
				String tok = oTokenizer.nextToken();
				if (tok.length() == 0)
					continue;
	            
	            if ( strAttr.length() > 0 )
	            {
	                mapAttr.put(strAttr, int.Parse(tok) );
	                strAttr = "";
	            }else
	                strAttr = tok;
	        }
	
			mapAttrs.put( nSrcID, mapAttr );
			if ( mapSrcNames != null )
				mapSrcNames.put(res.getStringByIdx(2).toUpperCase(), nSrcID);
	    }
    }
Beispiel #2
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));
        }
Beispiel #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);
        }
Beispiel #4
0
    void copyChangedValues(DBAdapter db)
    {
    	updateAllAttribChanges();    	
        copyTable("changed_values", m_dbStorage, db.m_dbStorage );
        {
            Vector<int> arOldSrcs = new Vector<int>();
            {
                IDBResult resSrc = db.executeSQL( "SELECT DISTINCT(source_id) FROM changed_values" );
                for ( ; !resSrc.isEnd(); resSrc.next() )
                    arOldSrcs.addElement( resSrc.getIntByIdx(0) );
            }
            for( int i = 0; i < arOldSrcs.size(); i++)
            {
                int nOldSrcID = arOldSrcs.elementAt(i);

                IDBResult res = executeSQL("SELECT name from sources WHERE source_id=?", nOldSrcID);
                if ( !res.isEnd() )
                {
                    String strSrcName = res.getStringByIdx(0);
                    IDBResult res2 = db.executeSQL("SELECT source_id from sources WHERE name=?", strSrcName );
                    if ( !res2.isEnd() )
                    {
                        if ( nOldSrcID != res2.getIntByIdx(0) )
                        {
                            db.executeSQL("UPDATE changed_values SET source_id=? WHERE source_id=?", res2.getIntByIdx(0), nOldSrcID);
                        }
                        continue;
                    }
                }

                //source not exist in new partition, remove this changes
                db.executeSQL("DELETE FROM changed_values WHERE source_id=?", nOldSrcID);
            }
        }
    }
Beispiel #5
0
		public DBCallback(DBAdapter db){ m_db = db; }
Beispiel #6
0
	    public void applyChangedValues(DBAdapter db)
	    {
	        IDBResult resSrc = db.executeSQL( "SELECT DISTINCT(source_id) FROM changed_values" );
	        for ( ; !resSrc.isEnd(); resSrc.next() )
	        {
	            int nSrcID = resSrc.getIntByIdx(0);
	            IDBResult res = db.executeSQL("SELECT source_id,sync_type,name, partition from sources WHERE source_id=?", nSrcID);
	            if ( res.isEnd() )
	                continue;

	            SyncSource src = new SyncSource( res.getIntByIdx(0), res.getStringByIdx(2), "none", db, this );

	            src.applyChangedValues();
	        }
	    }
Beispiel #7
0
 public void loadBlobAttrs(DBAdapter db)
 {
     loadAttrs(db, m_mapBlobAttrs, "blob_attribs", m_mapSrcNames);
     //TODO: update/delete trigger for schema sources
 }
Beispiel #8
0
    public void loadBlobAttrs(DBAdapter db)
    {
        loadAttrs(db, m_mapBlobAttrs, "blob_attribs", m_mapSrcNames);

        String strTriggerPrefix = "rhoSchemaTrigger_";
        IDBResult res = db.executeSQL("SELECT name FROM sqlite_master WHERE type='trigger'");
        Hashtable<String, int> mapTriggers = new Hashtable<String, int>();
        for (; !res.isEnd(); res.next())
        {
            String strName = res.getStringByIdx(0);
            if (!strName.startsWith(strTriggerPrefix))
                continue;

            mapTriggers[strName.Substring(strTriggerPrefix.length())] = 0;
        }

        foreach (KeyValuePair<int, Hashtable<String,int>> kvpBlobAttrs in m_mapBlobAttrs)
        {
            int nSrcID = kvpBlobAttrs.Key;

            res = db.executeSQL("SELECT name FROM sources WHERE source_id=?", nSrcID);
            if ( res.isEnd() )
                continue;

            String strName = res.getStringByIdx(0);
            if ( !db.isTableExist(strName) )
                continue;

            Hashtable<String,int> hashAttribs = kvpBlobAttrs.Value;
            foreach (KeyValuePair<String, int> kvpHashAttribs in hashAttribs)
            {
                String strTriggerName = strName + "_" + kvpHashAttribs.Key;
                if ( !mapTriggers.containsKey(strTriggerName + "_delete") )
                {
                    String strTrigger = "CREATE TRIGGER " + strTriggerPrefix + strTriggerName + "_delete BEFORE DELETE ON \"" + strName + "\" FOR EACH ROW \r\n"
                    +"   BEGIN \r\n"
                    + "       SELECT rhoOnDeleteSchemaRecord( OLD." + kvpHashAttribs.Key + ");\r\n"
                    +"   END;\r\n"
                    +";";

                    db.createTrigger(strTrigger);
                }else
                    mapTriggers[strTriggerName + "_delete"] = 1;

                if ( !mapTriggers.containsKey(strTriggerName + "_update") )
                {
                    String strTrigger = "CREATE TRIGGER " + strTriggerPrefix + strTriggerName + "_update BEFORE UPDATE ON \"" + strName + "\" FOR EACH ROW\r\n"
                    +"   BEGIN \r\n"
                    + "       SELECT rhoOnUpdateSchemaRecord( OLD." + kvpHashAttribs.Key + ", NEW." + kvpHashAttribs.Key + ");\r\n"
                    +"   END;\r\n"
                    +";";

                    db.createTrigger(strTrigger);
                }else
                    mapTriggers[strTriggerName + "_update"] = 1;

                }
        }

        //Remove outdated triggers
        foreach (KeyValuePair<string, int> kvp in mapTriggers)
        {
            if(kvp.Value != 0)
                db.dropTrigger(strTriggerPrefix+kvp.Key.ToString());
        }
    }