Beispiel #1
0
        public void updateAllAttribChanges()
        {
            //Check for attrib = object
            IDBResult res = executeSQL("SELECT object, source_id, update_type " +
                                       "FROM changed_values where attrib = 'object' and sent=0");

            if (res.isEnd())
            {
                return;
            }

            startTransaction();

            Vector <String> arObj = new Vector <String>(), arUpdateType = new Vector <String>();
            Vector <int>    arSrcID = new Vector <int>();

            for ( ; !res.isEnd(); res.next())
            {
                arObj.addElement(res.getStringByIdx(0));
                arSrcID.addElement(res.getIntByIdx(1));
                arUpdateType.addElement(res.getStringByIdx(2));
            }

            for (int i = 0; i < (int)arObj.size(); i++)
            {
                IDBResult resSrc        = executeSQL("SELECT name, schema FROM sources where source_id=?", arSrcID.elementAt(i));
                boolean   bSchemaSource = false;
                String    strTableName  = "object_values";
                if (!resSrc.isEnd())
                {
                    bSchemaSource = resSrc.getStringByIdx(1).length() > 0;
                    if (bSchemaSource)
                    {
                        strTableName = resSrc.getStringByIdx(0);
                    }
                }

                if (bSchemaSource)
                {
                    IDBResult res2 = executeSQL("SELECT * FROM " + strTableName + " where object=?", arObj.elementAt(i));
                    for (int j = 0; j < res2.getColCount(); j++)
                    {
                        if (res2.isNullByIdx(j))
                        {
                            continue;
                        }

                        String strAttrib  = res2.getColName(j);
                        String value      = res2.getStringByIdx(j);
                        String attribType = getAttrMgr().isBlobAttr(arSrcID.elementAt(i), strAttrib) ? "blob.file" : "";

                        executeSQLReportNonUnique("INSERT INTO changed_values (source_id,object,attrib,value,update_type,attrib_type,sent) VALUES(?,?,?,?,?,?,?)",
                                                  arSrcID.elementAt(i), arObj.elementAt(i), strAttrib, value, arUpdateType.elementAt(i), attribType, 0);
                    }
                }
                else
                {
                    IDBResult res2 = executeSQL("SELECT attrib, value FROM " + strTableName + " where object=? and source_id=?",
                                                arObj.elementAt(i), arSrcID.elementAt(i));

                    for ( ; !res2.isEnd(); res2.next())
                    {
                        if (res2.isNullByIdx(1))
                        {
                            continue;
                        }

                        String strAttrib  = res2.getStringByIdx(0);
                        String value      = res2.getStringByIdx(1);
                        String attribType = getAttrMgr().isBlobAttr(arSrcID.elementAt(i), strAttrib) ? "blob.file" : "";

                        executeSQLReportNonUnique("INSERT INTO changed_values (source_id,object,attrib,value,update_type,attrib_type,sent) VALUES(?,?,?,?,?,?,?)",
                                                  arSrcID.elementAt(i), arObj.elementAt(i), strAttrib, value, arUpdateType.elementAt(i), attribType, 0);
                    }
                }
            }

            executeSQL("DELETE FROM changed_values WHERE attrib='object'");

            endTransaction();
        }
Beispiel #2
0
        void processServerCmd_Ver3_Schema(String strCmd, String strObject, JSONStructIterator attrIter)
        {
            if (strCmd.compareTo("insert") == 0)
            {
                Vector <String> vecValues = new 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);
            }
        }