示例#1
0
    // Method that deletes all documents from a DB XML container that match a given
    // XQuery.
    private static void deleteIndex(Manager mgr, Container container,
                                    string URI, string nodeName, string indexType, Transaction txn)
    {
        System.Console.WriteLine("Deleting index type '" + indexType +
                                 "' from node '" + nodeName + "'.");

        // Retrieve the index specification from the container
        using (IndexSpecification idxSpec = container.GetIndexSpecification(txn))
        {
            // See what indexes exist on the container
            int count = 0;
            System.Console.WriteLine("Before the delete, the following indexes are maintained for the container:");
            // Loop over the indexes and report what's there.
            while (idxSpec.MoveNext())
            {
                System.Console.WriteLine("\tFor node '" + idxSpec.Current.Name +
                                         "', found index: '" + idxSpec.Current.Index + "'.");
                ++count;
            }
            System.Console.WriteLine(count + " indexes found.");

            // Delete the indexes from the specification.
            idxSpec.DeleteIndex(
                new IndexSpecification.Entry(URI, nodeName, indexType));

            // Get an update context.
            using (UpdateContext updateContext = mgr.CreateUpdateContext())
            {
                // Set the specification back to the container
                container.SetIndexSpecification(txn, idxSpec, updateContext);
            }
        }

        // Retrieve the index specification from the container
        using (IndexSpecification idxSpec = container.GetIndexSpecification(txn))
        {
            // Look at the indexes again to make sure our deletion took.
            int count = 0;
            System.Console.WriteLine("After the delete, the following indexes are maintained for the container:");
            while (idxSpec.MoveNext())
            {
                System.Console.WriteLine("\tFor node '" + idxSpec.Current.Name +
                                         "', found index: '" + idxSpec.Current.Index + "'.");
                ++count;
            }
            System.Console.WriteLine(count + " indexes found.");
        }
    }
示例#2
0
    private static void addIndex(Container container, string uri, string name,
                                 string index, Transaction txn, UpdateContext uc)
    {
        System.Console.WriteLine("Adding index type '" + index +
                                 "' to node '" + name + "'.");

        // Retrieve the index specification from the container
        using (IndexSpecification idxSpec = container.GetIndexSpecification(txn))
        {
            // See what indexes exist on the container
            int count = 0;
            System.Console.WriteLine("Before index add.");
            while (idxSpec.MoveNext())
            {
                System.Console.WriteLine("\tFor node '" + idxSpec.Current.Name +
                                         "', found index: '" + idxSpec.Current.Index +
                                         "'.");
                ++count;
            }

            System.Console.WriteLine(count + " indexes found.");

            // Add the index to the specification.
            // If it already exists, then this does nothing.
            idxSpec.AddIndex(new IndexSpecification.Entry(uri, name, index));

            // Set the specification back to the container
            container.SetIndexSpecification(txn, idxSpec, uc);
        }

        // Retrieve the index specification from the container
        using (IndexSpecification idxSpec = container.GetIndexSpecification(txn))
        {
            // Look at the indexes again to make sure our replacement took.
            int count = 0;
            System.Console.WriteLine("After index add.");
            while (idxSpec.MoveNext())
            {
                System.Console.WriteLine("\tFor node '" + idxSpec.Current.Name +
                                         "', found index: '" + idxSpec.Current.Index +
                                         "'.");
                ++count;
            }

            System.Console.WriteLine(count + " indexes found.");
        }
    }