void replaceIndex( XmlContainer &container, const std::string &URI, const std::string &nodeName, const std::string &indexType, XmlTransaction &txn, XmlUpdateContext &uc) { std::cout << "Replacing index on node: " << nodeName << std::endl; try { //Retrieve the XmlIndexSpecification from the container XmlIndexSpecification idxSpec = container.getIndexSpecification( txn ); //Lets see what indexes exist on this container std::string uri, name, index; int count = 0; std::cout << "Before index add." << std::endl; while( idxSpec.next(uri, name, index) ) { // Obtain the value as a string and print it to the console std::cout << "\tFor node '" << name << "', found index: '" << index << "'." << std::endl; count ++; } std::cout << count << " indexes found." << std::endl; //Replace the indexes for the specified node idxSpec.replaceIndex( URI, nodeName, indexType ); //Set the specification back to the container container.setIndexSpecification( txn, idxSpec, uc ); //Look at the indexes again to make sure our replacement took. count = 0; idxSpec.reset(); std::cout << "After index add." << std::endl; while( idxSpec.next(uri, name, index) ) { // Obtain the value as a string and print it to the console std::cout << "\tFor node '" << name << "', found index: '" << index << "'." << std::endl; count ++; } std::cout << count << " indexes found." << std::endl; } //Catches XmlException catch(std::exception &e) { std::cerr << "Index replace failed: \n"; std::cerr << e.what() << "\n"; txn.abort(); exit( -1 ); } std::cout << "Index replaced successfully." << std::endl; }
void deleteIndex( XmlContainer &container, const std::string &URI, const std::string &nodeName, const std::string &indexType, XmlTransaction &txn, XmlUpdateContext &uc ) { std::cout << "Deleting index type: '" << indexType << "" << " from node: '" << nodeName << "'." << std::endl; try { //Retrieve the XmlIndexSpecification from the container XmlIndexSpecification idxSpec = container.getIndexSpecification( txn ); std::cout << "Before the delete, the following indexes are maintained for the container:" << std::endl; std::string uri, name, index; while( idxSpec.next(uri, name, index) ) { // Obtain the value as a string and print it to the console std::cout << "\tFor node '" << name << "', found index: '" << index << "'." << std::endl; } std::cout << "\n" << std::endl; //Delete the indexes from the specification. idxSpec.deleteIndex( URI, nodeName, indexType ); //Set the specification back to the container container.setIndexSpecification( txn, idxSpec, uc ); //Show the remaining indexes in the container, if any. std::cout << "After the delete, the following indexes exist for the container:" << std::endl; idxSpec.reset(); while( idxSpec.next(uri, name, index) ) { // Obtain the value as a string and print it to the console std::cout << "\tFor node '" << name << "', found index: '" << index << "'." << std::endl; } std::cout << "\n" << std::endl; } //Catches XmlException. catch(std::exception &e) { std::cerr << "Index delete failed: \n"; std::cerr << e.what() << "\n"; txn.abort(); exit( -1 ); } std::cout << "Index deleted successfully.\n" << std::endl; }
void InfoCommand::execute(Args &args, Environment &env) { if (args.size() == 2 && args[1] == "preload") { doPreload(env); return; } cout << "Version: " << DBXML_VERSION_STRING << endl; cout << " " << DB_VERSION_STRING << endl; if (env.container()) { const std::string &cname = env.container()->getName(); XmlContainer::ContainerType ctype = env.container()->getContainerType(); XmlIndexSpecification is; if(env.txn()) is = env.container()->getIndexSpecification(*env.txn()); else is = env.container()->getIndexSpecification(); cout << "Default container name: " << cname << endl; cout << "Type of default container: " << ((ctype == XmlContainer::WholedocContainer) ? "WholedocContainer" : "NodeContainer") << endl; cout << "Index Nodes: " << (env.container()->getIndexNodes() ? "on" : "off") << endl; cout << "Auto-indexing: " << (is.getAutoIndexing() ? "on" : "off") << endl; } else { cout << "No default container" << endl; } // return type // verbosity // transacted cout << "Shell and XmlManager state:" << endl; if (env.transactions()) { cout << "\tTransactional, "; if (env.txn()) cout << "active transaction" << endl; else cout << "no active transaction" << endl; } else cout << "\tNot transactional" << endl;; cout << "\tVerbose: " << (env.verbose() ? "on" : "off") << endl; XmlQueryContext::EvaluationType etype = env.context().getEvaluationType(); cout << "\tQuery context state: LiveValues," << ((etype == XmlQueryContext::Eager)? "Eager" : "Lazy") << endl; }