コード例 #1
0
        /**
         * Locates documents inside a collection that matches the ids.
         */
        public JArray findWithIds(JArray ids)
        {
            JSONStoreQueryOptions options = new JSONStoreQueryOptions();

            options.exact = true;
            return(findWithQueries(ids, options));
        }
コード例 #2
0
        public JArray findWithAdvancedQuery(List <JSONStoreQuery> queryParts, JSONStoreQueryOptions options)
        {
            // the results
            JArray results = null;

            // get the shared store
            JSONStoreSQLLite store = JSONStoreSQLLite.sharedManager();

            if (store == null)
            {
                //JSONStoreLoggerError(@"Error: JSON_STORE_DATABASE_NOT_OPEN, code: %d", rc);
                throw new JSONStoreException(JSONStoreConstants.JSON_STORE_DATABASE_NOT_OPEN);
            }

            lock (JSONStore.lockThis)
            {
                results = store.findWithQueryParts(queryParts, collectionName, options);

                if (results == null)
                {
                    // JSONStoreLoggerError(@"Error: JSON_STORE_INVALID_SEARCH_FIELD, code: %d, collection name: %@, accessor username: %@, currentQuery: %@, JSONStoreQueryOptions: %@", rc, self.collectionName, accessor != nil ? accessor.username : @"nil", nil, options);

                    throw new JSONStoreException(JSONStoreConstants.JSON_STORE_INVALID_SEARCH_FIELD);
                }

                return(results);
            }
        }
コード例 #3
0
        public int changeData(JArray dataArray, JSONStoreReplaceOptions options)
        {
            int numUpdatedOrAdded = 0;

            JSONStoreSQLLite store = JSONStoreSQLLite.sharedManager();

            if (store == null)
            {
                //JSONStoreLoggerError(@"Error: JSON_STORE_DATABASE_NOT_OPEN, code: %d", rc);
                throw new JSONStoreException(JSONStoreConstants.JSON_STORE_DATABASE_NOT_OPEN);
            }

            foreach (JObject data in dataArray)
            {
                JArray query = new JArray();

                if (options.replaceCriteria != null)
                {
                    foreach (string sf in options.replaceCriteria)
                    {
                        JToken value;
                        if (data.TryGetValue(sf, out value))
                        {
                            JObject queryObject = new JObject();
                            queryObject.Add(sf, value);
                            query.Add(queryObject);
                        }
                    }
                }

                JArray results = null;
                if (query.Count > 0)
                {
                    JSONStoreQueryOptions queryOptions = new JSONStoreQueryOptions();
                    queryOptions.exact = true;
                    results            = findWithQueries(query, queryOptions);
                }

                if (results != null && results.Count > 0)
                {
                    JArray docsToReplace = new JArray();

                    foreach (JObject obj in results)
                    {
                        JObject doc = new JObject();
                        doc.Add(JSONStoreConstants.JSON_STORE_FIELD_ID, obj.GetValue(JSONStoreConstants.JSON_STORE_FIELD_ID));
                        doc.Add(JSONStoreConstants.JSON_STORE_FIELD_JSON, data);
                        docsToReplace.Add(doc);
                    }

                    int numReplaced = replaceDocuments(docsToReplace, options.markDirty);
                    if (numReplaced > 0)
                    {
                        numUpdatedOrAdded += numReplaced;
                    }
                }
                else
                {
                    if (options.addNew)
                    {
                        JArray addArray = new JArray();
                        addArray.Add(data);
                        int numAdded = addData(addArray, options.markDirty, new JSONStoreAddOptions());
                        numUpdatedOrAdded += numAdded;
                    }
                }
            }

            return(numUpdatedOrAdded);
        }
コード例 #4
0
        /**
         * Locates documents inside a collection that matches the query.
         */
        public JArray findWithQueries(JArray queries, JSONStoreQueryOptions options)
        {
            if (options.offset > 0 && options.limit <= 0)
            {
                //JSONStoreLoggerError(@"Error: JSON_STORE_INVALID_OFFSET, code: %d", rc);
                throw new JSONStoreException(JSONStoreConstants.JSON_STORE_INVALID_OFFSET);
            }

            JSONStoreSQLLite store = JSONStoreSQLLite.sharedManager();

            if (store == null)
            {
                throw new JSONStoreException(JSONStoreConstants.JSON_STORE_DATABASE_NOT_OPEN);
            }

            List <string> ids            = new List <string>();
            List <string> jObjectStrings = new List <string>();
            JArray        fullResults    = new JArray();

            lock (JSONStore.lockThis)
            {
                foreach (JToken currentQuery in queries)
                {
                    JArray results = store.find(currentQuery, collectionName, options);

                    if (results != null)
                    {
                        foreach (JObject result in results)
                        {
                            JToken value;
                            if (!result.TryGetValue("_id", out value))
                            {
                                if (!jObjectStrings.Contains(result.ToString()))
                                {
                                    fullResults.Add(result);
                                    jObjectStrings.Add(result.ToString());
                                }
                            }
                            else if (!ids.Contains(value.ToString()))
                            {
                                fullResults.Add(result);
                                ids.Add(value.ToString());
                            }
                        }
                    }
                    else
                    {
                        fullResults = null;

                        //A find failed, break and go to the error callback
                        break;
                    }
                }

                // If we get back a nil array, then the SQL statment was invalid or the database was closed.
                // If we just didn't find anything for a valid SQL statement, then we get back a non-nil empty array.
                if (fullResults == null)
                {
                    //JSONStoreLoggerError(@"Error: JSON_STORE_INVALID_SEARCH_FIELD, code: %d, collection name: %@, accessor username: %@, currentQuery: %@, JSONStoreQueryOptions: %@", rc, self.collectionName, accessor != nil ? accessor.username : @"nil", lastQuery, options);
                    throw new JSONStoreException(JSONStoreConstants.JSON_STORE_INVALID_SEARCH_FIELD);
                }

                return(fullResults);
            }
        }