コード例 #1
0
        public void TestUpsertManyEntries()
        {
            Debug.WriteLine("SmartStoreLoadTest", "In testUpsertManyEntries");
            for (int k = 1; k < MAX_NUMBER_ENTRIES; k *= 2)
            {
                UpsertManyEntriesWithManyFields(k);
            }
            JArray result =
                Store.Query(
                    QuerySpec.BuildSmartQuerySpec(
                        "select {test_soup:key} from {" + TEST_SOUP + "} WHERE {test_soup:key} = 'k_100'", 1), 0);
            JArray compare = JArray.Parse("[[\"k_100\"]]");

            Assert.AreEqual(compare.ToString(), result.ToString());
        }
コード例 #2
0
        public void TestSmartQueryWithPaging()
        {
            QuerySpec query =
                QuerySpec.BuildSmartQuerySpec(
                    "select {employees:firstName} from {employees} order by {employees:firstName}", 1);

            Assert.AreEqual(7, Store.CountQuery(query), "Expected 7 employees");

            String[] expectedResults = { "Christine", "Eileen", "Eva", "Irving", "John", "Michael", "Sally" };
            for (int i = 0; i < 7; i++)
            {
                JArray result = Store.Query(query, i);
                Assert.AreEqual(JArray.Parse("[[\"" + expectedResults[i] + "\"]]").ToString(), result.ToString(),
                                "Wrong result at page " + i);
            }
        }
コード例 #3
0
        public async Task TestSyncUpWithLocallyUpdatedRecordsWithoutOverwrite()
        {
            TrySyncDown(SyncState.MergeModeOptions.LeaveIfChanged);

            Dictionary <string, string> idToNamesLocallyUpdated = MakeSomeLocalChanges();

            var idToNamesRemotelyUpdated = new Dictionary <string, string>();

            foreach (string id in idToNamesLocallyUpdated.Keys)
            {
                idToNamesRemotelyUpdated[id] = idToNamesLocallyUpdated[id] + "_updated_again";
            }
            await UpdateAccountsOnServer(idToNamesRemotelyUpdated);

            // sync up
            TrySyncUp(3, SyncState.MergeModeOptions.LeaveIfChanged);

            String    idsClause       = "('" + String.Join("', '", idToNamesRemotelyUpdated.Keys) + "')";
            QuerySpec smartStoreQuery =
                QuerySpec.BuildSmartQuerySpec(
                    "SELECT {accounts:_soup} FROM {accounts} WHERE {accounts:Id} IN " + idsClause,
                    idToNamesRemotelyUpdated.Keys.Count);
            JArray accountsFromDb = _smartStore.Query(smartStoreQuery, 0);

            foreach (JToken token in accountsFromDb)
            {
                var row     = token.ToObject <JArray>();
                var soupElt = row[0].ToObject <JObject>();
                Assert.IsTrue(soupElt.ExtractValue <bool>(SyncManager.Local), "Wrong local flag");
                Assert.IsTrue(soupElt.ExtractValue <bool>(SyncManager.LocallyUpdated), "Wrong local flag");
            }

            // check server
            String      soql                = "SELECT Id, Name FROM Account WHERE Id IN " + idsClause;
            RestRequest request             = RestRequest.GetRequestForQuery(ApiVersionStrings.VersionNumber, soql);
            var         idToNamesFromServer = new JObject();
            var         response            = await _restClient.SendAsync(request);

            var records = response.AsJObject.ExtractValue <JArray>(RecordsStr);

            foreach (JToken token in records)
            {
                var row = token.ToObject <JObject>();
                idToNamesFromServer[row.ExtractValue <string>(Constants.Id)] = row.ExtractValue <string>(Constants.Name);
            }
            Assert.IsTrue(JToken.DeepEquals(JObject.FromObject(idToNamesRemotelyUpdated), idToNamesFromServer));
        }
コード例 #4
0
        private void CheckDb(Dictionary <string, string> expectedIdToNames)
        {
            string    idsClause       = "('" + String.Join("', '", expectedIdToNames.Keys) + "')";
            QuerySpec smartStoreQuery =
                QuerySpec.BuildSmartQuerySpec(
                    "SELECT {accounts:Id}, {accounts:Name} FROM {accounts} WHERE {accounts:Id} IN " + idsClause,
                    CountTestAccounts);
            JArray accountsFromDb  = _smartStore.Query(smartStoreQuery, 0);
            var    idToNamesFromDb = new JObject();

            foreach (JToken t in accountsFromDb)
            {
                var row = t.ToObject <JArray>();
                idToNamesFromDb[row[0].ToObject <string>()] = row[1].ToObject <string>();
            }
            Assert.IsTrue(JToken.DeepEquals(JObject.FromObject(expectedIdToNames), idToNamesFromDb));
        }
コード例 #5
0
        public void TestSmartQueryWithSpecialFields()
        {
            var christineJson =
                Store.Query(QuerySpec.BuildExactQuerySpec(EMPLOYEES_SOUP, "employeeId", "00010", 1), 0)[0] as JObject;

            Assert.AreEqual("Christine", christineJson.GetValue(FIRST_NAME), "Wrong elt");

            JArray result =
                Store.Query(
                    QuerySpec.BuildSmartQuerySpec(
                        "select {employees:_soup}, {employees:_soupEntryId}, {employees:_soupLastModifiedDate}, {employees:salary} from {employees} where {employees:lastName} = 'Haas'",
                        1), 0);

            Assert.AreEqual(1, result.Count, "Expected one row");
            Assert.AreEqual(christineJson.ToString(), result[0][0].ToString(), "Wrong soup");
            Assert.AreEqual(christineJson.GetValue(SoupEntryId), result[0][1], "Wrong soupEntryId");
            Assert.AreEqual(christineJson.GetValue(SoupLastModifiedDate), result[0][2], "Wrong soupLastModifiedDate");
        }
コード例 #6
0
        public void TestSmartQueryReturningSoupStringAndInteger()
        {
            JArray query         = Store.Query(QuerySpec.BuildExactQuerySpec(EMPLOYEES_SOUP, "employeeId", "00010", 1), 0);
            var    christineJson = query[0] as JObject;

            Assert.AreEqual("Christine", christineJson.GetValue(FIRST_NAME).ToString(), "Wrong elt");

            JArray result =
                Store.Query(
                    QuerySpec.BuildSmartQuerySpec(
                        "select {employees:_soup}, {employees:firstName}, {employees:salary} from {employees} where {employees:lastName} = 'Haas'",
                        1), 0);

            Assert.AreEqual(1, result.Count(), "Expected one row");
            Assert.AreEqual(christineJson.ToString(), result[0][0].ToString(), "Wrong soup");
            Assert.AreEqual("Christine", result[0][1].ToString(), "Wrong first name");
            Assert.AreEqual(200000, (int)(result[0][2]), "Wrong salary");
        }
コード例 #7
0
        public async Task TestSyncUpWithLocallyUpdatedRecords()
        {
            // first sync down
            TrySyncDown(SyncState.MergeModeOptions.Overwrite);

            // make local changes
            Dictionary <string, string> idToNamesLocallyUpdated = MakeSomeLocalChanges();

            // sync up
            TrySyncUp(3);

            // check that the db doesn't show entries as locally modified anymore
            Dictionary <string, string> .KeyCollection ids = idToNamesLocallyUpdated.Keys;
            string    idsClause       = "('" + String.Join("', '", ids) + "')";
            QuerySpec smartStoreQuery =
                QuerySpec.BuildSmartQuerySpec(
                    "SELECT {accounts:_soup} FROM {accounts} WHERE {accounts:Id} IN " + idsClause, ids.Count);
            JArray accountsFromDb = _smartStore.Query(smartStoreQuery, 0);

            foreach (JArray row in accountsFromDb.Select(row => row.ToObject <JArray>()))
            {
                var soupElt = row[0].ToObject <JObject>();
                Assert.AreEqual(false, soupElt.ExtractValue <bool>(SyncManager.Local), "Wrong local flag");
                Assert.AreEqual(false, soupElt.ExtractValue <bool>(SyncManager.LocallyUpdated), "Wrong local flag");
            }
            string soql     = "SELECT Id, Name FROM Account WHERE Id IN " + idsClause;
            var    request  = RestRequest.GetRequestForQuery(ApiVersionStrings.VersionNumber, soql);
            var    response = await _restClient.SendAsync(request);

            var records             = response.AsJObject.ExtractValue <JArray>(RecordsStr);
            var idToNamesFromServer = new JObject();

            foreach (JToken rowToken in records)
            {
                var row = rowToken.ToObject <JObject>();
                idToNamesFromServer[row.ExtractValue <string>(Constants.Id)] = row.ExtractValue <string>(Constants.Name);
            }
            Assert.IsTrue(JToken.DeepEquals(JObject.FromObject(idToNamesLocallyUpdated), idToNamesFromServer));
        }
コード例 #8
0
        /// <summary>
        ///     Run a query given by its query spec, only returning results from the selected page.
        /// </summary>
        /// <param name="querySpec"></param>
        /// <param name="pageIndex"></param>
        /// <returns></returns>
        public JArray Query(QuerySpec querySpec, int pageIndex)
        {
            lock (smartlock)
            {
                QuerySpec.SmartQueryType qt = querySpec.QueryType;
                var    results = new JArray();
                string sql     = ConvertSmartSql(querySpec.SmartSql);
                if (String.IsNullOrEmpty(sql))
                {
                    return(new JArray());
                }

                int    offsetRows = querySpec.PageSize * pageIndex;
                int    numberRows = querySpec.PageSize;
                string limit      = offsetRows + "," + numberRows;

                using (SQLiteStatement statement = DBHelper.GetInstance(DatabasePath)
                                                   .LimitRawQuery(sql, limit, querySpec.getArgs()))
                {
                    if (statement.DataCount > 0)
                    {
                        do
                        {
                            if (qt == QuerySpec.SmartQueryType.Smart)
                            {
                                results.Add(GetDataFromRow(statement));
                            }
                            else
                            {
                                results.Add(JObject.Parse(GetObject(statement, 0).ToString()));
                            }
                        } while (statement.Step() == SQLiteResult.ROW);
                    }
                    statement.ResetAndClearBindings();
                }
                return(results);
            }
        }
コード例 #9
0
 /// <summary>
 ///     count of results for a "smart" query
 /// </summary>
 /// <param name="querySpec"></param>
 /// <returns></returns>
 public long CountQuery(QuerySpec querySpec)
 {
     lock (smartlock)
     {
         String countSql = ConvertSmartSql(querySpec.CountSmartSql);
         return DBHelper.GetInstance(DatabasePath).CountRawCountQuery(countSql, querySpec.getArgs());
     }
 }
コード例 #10
0
        /// <summary>
        ///     Run a query given by its query spec, only returning results from the selected page.
        /// </summary>
        /// <param name="querySpec"></param>
        /// <param name="pageIndex"></param>
        /// <returns></returns>
        public JArray Query(QuerySpec querySpec, int pageIndex)
        {
            lock (smartlock)
            {
                QuerySpec.SmartQueryType qt = querySpec.QueryType;
                var results = new JArray();
                string sql = ConvertSmartSql(querySpec.SmartSql);
                int offsetRows = querySpec.PageSize * pageIndex;
                int numberRows = querySpec.PageSize;
                string limit = offsetRows + "," + numberRows;

                using (ISQLiteStatement statement = DBHelper.GetInstance(DatabasePath)
                    .LimitRawQuery(sql, limit, querySpec.getArgs()))
                {
                    if (statement.DataCount > 0)
                    {
                        do
                        {
                            if (qt == QuerySpec.SmartQueryType.Smart)
                            {
                                results.Add(GetDataFromRow(statement));
                            }
                            else
                            {
                                results.Add(JObject.Parse(GetObject(statement, 0).ToString()));
                            }
                        } while (statement.Step() == SQLiteResult.ROW);
                    }
                    statement.ResetAndClearBindings();
                }
                return results;
            }
        }