Beispiel #1
0
 public Results Query(Transaction txn, string query, QueryContext context)
 {
     return Results.Create(this.mgr_.query(Transaction.ToInternal(txn), query, QueryContext.ToInternal(context)));
 }
Beispiel #2
0
 public Results Query(Transaction txn, string query, QueryContext context, DocumentConfig config)
 {
     return Results.Create(this.mgr_.query(Transaction.ToInternal(txn), query, QueryContext.ToInternal(context), config.Flags));
 }
Beispiel #3
0
    private static string getNewDocument(Manager mgr, Document document, 
		QueryContext context, string docString)
    {
        // Get the substring that we want to replace
        string inventory = getValue(mgr, document,
            "/*/inventory/inventory/text()", context);

        // Convert the String representation of the inventory level to an
        // integer, increment by 1, and then convert back to a String for
        // replacement on the document.
        int newInventory = System.Int32.Parse(inventory) + 1;
        string newVal = newInventory.ToString();

        // Perform the replace
        StringBuilder strbuff = new StringBuilder(docString);
        strbuff.Replace(inventory, newVal);
        System.Console.WriteLine("Inventory was " + inventory +
            ", it is now " + newVal + ".");
        return strbuff.ToString();
    }
Beispiel #4
0
 public QueryExpression Prepare(Transaction txn, string query, QueryContext context)
 {
     return QueryExpression.Create(this.mgr_.prepare(Transaction.ToInternal(txn), query, QueryContext.ToInternal(context)));
 }
Beispiel #5
0
    // Method that deletes all documents from a DB XML container that match a given
    // XQuery.
    private static void doDeleteDocument(Manager mgr, Container container, 
		string query, QueryContext context, Transaction txn)
    {
        System.Console.WriteLine("Deleting documents for expression: '" + query + "'.");
        System.Console.WriteLine("Return to continue: ");
        System.Console.ReadLine();

        // Perform our query. We'll delete any document contained in this result set.
        Results results = mgr.Query(txn, query, context, new DocumentConfig());
        System.Console.WriteLine("Found " + results.Size +
            " matching the expression '" + query + "'.");

        // Get an update context.
        using(UpdateContext updateContext = mgr.CreateUpdateContext())
        {
            while(results.MoveNext())
            {
                Document document = results.Current.ToDocument();

                string name = document.Name;
                System.Console.WriteLine("Deleting document: " + name + ".");

                // Peform the delete
                container.DeleteDocument(txn, document, updateContext);
                System.Console.WriteLine("Deleted document: " + name + ".");
            }
        }
    }
Beispiel #6
0
    // Modifies an XML document that is stored in a DB XML container
    private static void doUpdateDocument(Manager mgr, Container container, 
		string query, QueryContext context, Transaction txn)
    {
        System.Console.WriteLine("Updating documents for expression: '" + query + "'.");
        System.Console.WriteLine("Return to continue: ");
        System.Console.ReadLine();

        // query for all the documents that we want to update
        Results results = mgr.Query(txn, query, context, new DocumentConfig());
        System.Console.WriteLine("Found " + results.Size +
            " matching the expression '" + query + "'.");

        // Get an update context.
        using(UpdateContext updateContext = mgr.CreateUpdateContext())
        {
            while(results.MoveNext())
            {
                Document document = results.Current.ToDocument();

                // Retrieve the entire document as a single String object
                string docString = document.StringContent;
                System.Console.WriteLine("Updating document: ");
                System.Console.WriteLine(docString);

                // This next method just modifies the document string
                // in a small way.
                string newDocString = getNewDocument(mgr, document, context,
                    docString);

                System.Console.WriteLine("Updating document...");

                //Set the document's content to be the new document string
                document.StringContent = newDocString;

                // Now replace the document in the container
                container.UpdateDocument(txn, document, updateContext);
                System.Console.WriteLine("Document updated.");
            }
        }
    }
Beispiel #7
0
 public Results LookupIndex(Transaction txn, QueryContext context, IndexSpecification.Entry entry)
 {
     return this.LookupIndex(txn, context, entry, null, new DocumentConfig());
 }
Beispiel #8
0
    // Performs a query against a document using an QueryContext.
    private static void doContextQuery(Manager mgr, string query, 
		QueryContext context)
    {
        // Perform a single query against the referenced container using
        // the referenced context.
        System.Console.WriteLine("Exercising query: '" + query + "'.");
        System.Console.WriteLine("Return to continue: ");
        System.Console.ReadLine();

        // Perform the query
        Results results = mgr.Query(null, query, context, new DocumentConfig());
        // Iterate over the results
        while(results.MoveNext())
        {
            System.Console.WriteLine(results.Current);
        }
        System.Console.WriteLine(results.Size + " results returned for query '"
            + query + "'.");
    }
Beispiel #9
0
    // Method to add a "description" element after the query's target nodes
    private static void doModify(Manager mgr, Container container, QueryContext context,
		string query, Transaction txn)
    {
        using(QueryExpression expression = mgr.Prepare(txn, query, context))
        {

            System.Console.WriteLine("Updating document for the expression: '" +
                query + "' ");
            System.Console.WriteLine("Return to continue: ");
            System.Console.ReadLine();

            // Print the document(s) to be updated -- those that describe
            // Zapote Blanco (a fruit). The document strings are only being
            // printed to show before/after results.
            // Most modification programs would not perform the additional queries.
            using(Results results = expression.Execute(txn, context, new DocumentConfig()))
            {
                dumpDocuments(results);

                results.Reset();

                System.Console.WriteLine("About to update the document(s) above.");
                System.Console.WriteLine("Look for a new element after the target " +
                    "element, named 'description' ...");
                System.Console.WriteLine("Return to continue: ");
                System.Console.ReadLine();

                // The modification is a new element in the target node, called
                // "descripton, which goes immediately after the <product> element.
                // if this program is run more than once, and committed, additional
                // identical elements are added.  It is easy to modify this program
                // to change the modification.
                using(Modify modify = mgr.CreateModify())
                {
                    using(QueryExpression subexpr = mgr.Prepare(txn, ".", context))
                    {
                        modify.AddInsertAfterStep(subexpr, Modify.XmlObject.Element, "description", "very nice");

                        using(UpdateContext uc = mgr.CreateUpdateContext())
                        {
                            long numMod = modify.Execute(txn, results, context, uc);

                            System.Console.WriteLine("Performed " + numMod + " modification operations");
                            dumpDocuments(results);
                        }
                    }
                }
            }
        }
    }
Beispiel #10
0
    // Shows a timestamp for each record that matches the given XPath query.
    // The timestamp is stored as metadata on each document. This metadata was
    // added to the document when the example data was loaded into the container
    // using exampleLoadContainer.java. The timestamp represents the time
    // when the document was loaded into the container.
    private static void showTimeStamp(Manager mgr, string query,
		QueryContext context)
    {
        // Perform a single query against the referenced container using
        // the referenced context. The timestamp metadata attribute is then
        // displayed.
        System.Console.WriteLine("Exercising query: '" + query + "'.");
        System.Console.WriteLine("Return to continue: ");
        System.Console.ReadLine();

        //Perform the query
        Results results = mgr.Query(null, query, context, new DocumentConfig());

        while(results.MoveNext())
        {
            using(Document document = results.Current.ToDocument())
            {
                // We return the metadata as a MetaData object
                using(MetaData md = document.GetMetaData("http://dbxmlExamples/timestamp", "timeStamp"))
                {
                    System.Console.WriteLine("Document " + document.Name +
                        " stored on " + md.Value.ToDateTime());
                }
            }
        }

        System.Console.WriteLine(results.Size + " results returned for query '"
            + query + "'.");
    }
Beispiel #11
0
 public Results Execute(Transaction txn, Value contextItem, QueryContext context, DocumentConfig config)
 {
     return Results.Create(this.qe_.execute(Transaction.ToInternal(txn), Value.ToInternal(contextItem), QueryContext.ToInternal(context), config.Flags));
 }
Beispiel #12
0
 internal static XmlQueryContext ToInternal(QueryContext v)
 {
     if (v == null)
     {
         return null;
     }
     return v.Internal;
 }
Beispiel #13
0
 public int Execute(Transaction txn, Value toModify, QueryContext context, UpdateContext uc)
 {
     return((int)this.mod_.execute(Transaction.ToInternal(txn), Value.ToInternal(toModify), QueryContext.ToInternal(context), UpdateContext.ToInternal(uc)));
 }
Beispiel #14
0
    private static string getValue(Manager mgr, Document document, 
		string query, QueryContext context)
    {
        ///////////////////////////////////////////////////////////////////////////
        ////////    Return specific information from a document. //////////////////
        ////////          Assumes a result set of size 1         //////////////////
        ///////////////////////////////////////////////////////////////////////////

        using(Value docValue = new Value(document))
        {
            // Perform the query
            // The document provides the context for the query, so neither
            // collection() nor doc() needs to be part of the query.
            using(QueryExpression queryExpr = mgr.Prepare(null, query, context))
            {
                using(Results result = queryExpr.Execute(null, docValue, context, new DocumentConfig()))
                {
                    // We require a result set size of 1.
                    if(!result.MoveNext())
                    {
                        System.Console.WriteLine("Error!  query '" + query +
                            "' returned a result size size != 1");
                        throw new System.Exception( "getValue found result set not equal to 1.");
                    }

                    // Get the value. If we allowed the result set to be larger than size 1,
                    // we would have to loop through the results, processing each as is
                    // required by our application.
                    return result.Current.ToString();
                }
            }
        }
    }
Beispiel #15
0
 public Results LookupIndex(Transaction txn, QueryContext context, IndexSpecification.Entry entry, string parent_uri, string parent_name, Value value)
 {
     return this.LookupIndex(txn, context, entry, parent_uri, parent_name, value, new DocumentConfig());
 }
Beispiel #16
0
    private static void getDetails(Manager mgr, string query, QueryContext context)
    {
        // Perform a single query against the referenced container using
        // the referenced context.
        System.Console.WriteLine("Exercising query: '" + query + "'.");
        System.Console.WriteLine("Return to continue:");
        System.Console.ReadLine();

        // Perform the query
        Results results = mgr.Query(null, query, context, new DocumentConfig());

        System.Console.WriteLine("\tProduct : Price : Inventory Level");

        while(results.MoveNext())
        {
            /// Retrieve the value as a document
            using(Document theDocument = results.Current.ToDocument())
            {
                // Obtain information of interest from the document. Note that the
                // wildcard in the query expression allows us to not worry about what
                // namespace this document uses.
                string item = getValue(mgr, theDocument,
                    "string(/*/product)", context);
                string price = getValue(mgr, theDocument,
                    "string(/*/inventory/price)", context);
                string inventory = getValue(mgr, theDocument,
                    "string(/*/inventory/inventory)", context);

                System.Console.WriteLine("\t" + item + " : " + price + " : " +
                    inventory);
            }
        }

        System.Console.WriteLine(results.Size + " results returned for query '" +
            query + "'.");
    }
Beispiel #17
0
 public Results LookupIndex(Transaction txn, QueryContext context, IndexSpecification.Entry entry, string parent_uri, string parent_name, Value value, DocumentConfig config)
 {
     return Results.Create(this.cont_.lookupIndex(Transaction.ToInternal(txn), QueryContext.ToInternal(context), entry.URI, entry.Name, parent_uri, parent_name, entry.Index, Value.ToInternal(value), config.Flags));
 }
Beispiel #18
0
 public int Execute(Transaction txn, Value toModify, QueryContext context, UpdateContext uc)
 {
     return (int) this.mod_.execute(Transaction.ToInternal(txn), Value.ToInternal(toModify), QueryContext.ToInternal(context), UpdateContext.ToInternal(uc));
 }
Beispiel #19
0
 // Utility method that we use to make sure the documents that we thought
 // were deleted from the container are in fact deleted.
 private static void confirmDelete(Manager mgr, string query, QueryContext context)
 {
     System.Console.WriteLine("Confirming the delete.");
     System.Console.WriteLine("The query: '" + query +
         "' should return result set size 0.");
     Results results = mgr.Query(null, query, context, new DocumentConfig());
     if(results.Size == 0)
     {
         System.Console.WriteLine("Result set size is 0. Deletion confirmed.");
     }
     else
     {
         System.Console.WriteLine("Result set size is " + results.Size +
             ". Deletion failed.");
     }
 }