void DeleteDocumentCommand::execute(Args &args, Environment &env)
{
	if(args.size() != 2) {
		throw CommandException("Wrong number of arguments");
	}
	env.testContainer();
	
	if(env.txn()) {
		XmlTransaction myTxn = env.childTransaction();
		env.container()->deleteDocument(myTxn, args[1], env.uc());
		myTxn.commit();
	} else {
		env.container()->deleteDocument(args[1], env.uc());
	}
	
	if(env.verbose()) cout << "Document deleted, name = " << args[1] << endl;
}
Exemple #2
0
void DeleteIndexCommand::execute(Args &args, Environment &env)
{
	if(args.size() != 2 && args.size() != 4) {
		throw CommandException("Wrong number of arguments");
	}
	env.testContainer();
	
	if(env.verbose()) {
		if(args.size() == 2) cout << "Deleting default index type: " << args[1] << endl;
		else cout << "Deleting index type: " << args[3] << " from node: {" << args[1] << "}:" << args[2] << endl;
	}
	
	if(env.txn()) {
		XmlTransaction myTxn = env.childTransaction();
		if(args.size() == 2) env.container()->deleteDefaultIndex(myTxn, args[1], env.uc());
		else env.container()->deleteIndex(myTxn, args[1], args[2], args[3], env.uc());
		myTxn.commit();
	} else {
		if(args.size() == 2) env.container()->deleteDefaultIndex(args[1], env.uc());
		else env.container()->deleteIndex(args[1], args[2], args[3], env.uc());
	}
}
void AddDocumentCommand::execute(Args &args, Environment &env)
{
	if ((args.size() < 3) || (args.size() > 4)){
		throw CommandException("Wrong number of arguments");
	}
	env.testContainer();
	env.deleteResults();

	if ((args.size() == 4) && (args[3] == "q")) {
		if(env.txn()) {
			XmlTransaction myTxn = env.childTransaction();
			env.results() = new XmlResults(
				env.db().query(myTxn, args[2], env.context()));

			XmlValue value;
			while(env.results()->next(value)) {
				string v = value.asString();
				string name = env.container()->
					putDocument(myTxn, args[1], v, env.uc(),
						    DBXML_GEN_NAME);
				if(env.verbose())
					cout << "Document added, name = " << name << endl;
			}

			myTxn.commit();
		} else {
			env.results() = new XmlResults(env.db().query(args[2],
								      env.context()));
			XmlValue value;
			while(env.results()->next(value)) {
				string v = value.asString();
				string name = env.container()->
					putDocument(args[1], v, env.uc(), DBXML_GEN_NAME);
				if(env.verbose())
					cout << "Document added, name = " << name << endl;
			}

		}
	} else {
		// by string or by file
		bool byString = true;
		if (args.size() == 4 && args[3] == "f")
			byString = false;
		XmlDocument doc = env.db().createDocument();
		doc.setName(args[1]);
		if (byString)
			doc.setContent(args[2]);
		else {
			XmlInputStream *is = env.db().createLocalFileInputStream(args[2]);
			doc.setContentAsXmlInputStream(is);
		}
		if(env.txn()) {
			XmlTransaction myTxn = env.childTransaction();
			env.container()->putDocument(myTxn, doc, env.uc());
			myTxn.commit();
		} else {
			env.container()->putDocument(doc, env.uc());
		}

		// put doc content in last results
		XmlResults res = env.db().createResults();
		res.add(XmlValue(doc));
		env.results() = new XmlResults(res);

		if(env.verbose())
			cout << "Document added, name = " << args[1] << endl;
	}
}