private void Add(string path, NodeCache nodeCache) { if (_data == null) { throw new ObjectDisposedException("Database"); } if (nodeCache != null) { FDoc doc = new FDoc(nodeCache, path.Token()); Updates.Do(new DBAdd(Data, null, doc, path, Context)); } }
//Many of the following are ported from FNDb.java to eliminate the overhead of the XQuery function evaluation /// <summary> /// Deletes the document at the specified path. /// </summary> /// <param name="path">The path of the document to delete.</param> public void Delete(string path) { if (_data == null) { throw new ObjectDisposedException("Database"); } IntList docs = Data.resources.docs(path); using (new Updates()) { for (int i = docs.size() - 1; i >= 0; i--) { Updates.Do(new DeleteNode(docs.get(i), Data, null)); } } }
private void Replace(string path, NodeCache nodeCache) { if (_data == null) { throw new ObjectDisposedException("Database"); } int pre = Data.resources.doc(path); if (pre != -1) { if (Data.resources.docs(path).size() != 1) { throw new ArgumentException("Simple document expected as replacement target"); } using (new Updates()) { Updates.Do(new DeleteNode(pre, Data, null)); Add(path, nodeCache); } } }
/// <summary> /// Renames the document at the specified path. /// </summary> /// <param name="path">The path of the document to rename.</param> /// <param name="newName">The new name of the document.</param> public void Rename(string path, string newName) { if (_data == null) { throw new ObjectDisposedException("Database"); } IntList docs = Data.resources.docs(path); using (new Updates()) { for (int i = 0, s = docs.size(); i < s; i++) { int pre = docs.get(i); string target = org.basex.core.cmd.Rename.target(Data, pre, path, newName); if (!String.IsNullOrEmpty(target)) { Updates.Do(new ReplaceValue(pre, Data, null, target.Token())); } } } }
public IEnumerable <object> Eval(string expression) { if (expression == null) { throw new ArgumentNullException("expression"); } if (expression == String.Empty) { throw new ArgumentException("expression"); } // Create the query context QueryContext queryContext = new QueryContext(Database.Context); // Add variables foreach (KeyValuePair <string, Value> kvp in _variables) { queryContext.bind(kvp.Key, kvp.Value); } // Add default collection queryContext.resource.addCollection(_defaultCollection ?? Empty.SEQ, String.Empty); // Add named collections foreach (KeyValuePair <string, Value> kvp in _namedCollections) { queryContext.resource.addCollection(kvp.Value, kvp.Key); } // Set the initial context item queryContext.ctxItem = _context; // Add external namespaces foreach (KeyValuePair <string, string> kvp in _externals) { queryContext.sc.@namespace(kvp.Key, "java:" + kvp.Value); } // Reset the update collection to the common one in our update operation queryContext.updates = Updates.QueryUpdates; // Parse the expression queryContext.parse(expression); // Compile the query queryContext.compile(); // Reset the updating flag (so they aren't applied here) queryContext.updating(false); // Get the iterator and return the results Iter iter = queryContext.iter(); IterEnum iterEnum = new IterEnum(iter); // Apply updates if allowed if (AllowUpdates) { Updates.Apply(); } else { Updates.Forget(); } return(iterEnum); }