void putDocWithMyCompression(XmlManager& mgr, const string& containerName, XmlDocument& xdoc, XmlUpdateContext& uc, XmlCompression& myCompression) { // Define an unique name to use for registering the compression string compressionName = "myCompression"; // Register custom class mgr.registerCompression(compressionName.c_str(), myCompression); // Set the container type as WholedocContainer // and use the custom compression XmlContainerConfig contConf; contConf.setAllowCreate(true); contConf.setContainerType(XmlContainer::WholedocContainer); contConf.setCompressionName(compressionName.c_str()); // Create container XmlContainer cont = mgr.createContainer(containerName, contConf); // Put Document cont.putDocument(xdoc, uc); }
void RepNode::openContainer() { // reopening a container is forbidden. if (!cont_.isNull()) throwException("Attempt to re-open a container."); XmlContainerConfig conf; // wait for being elected as a Master or start up done(as a client). while (!(isMaster() || appData_.isStartupDone())) yield(); if (isMaster()) conf.setAllowCreate(true); XmlTransaction txn; while (true) { try { txn = mgr_->createTransaction(); cont_ = mgr_->openContainer(txn, containerName_, conf); txn.commit(); return; /* * One thing to watch out for is a case where the databases * you are trying to open do not yet exist. This can happen * for replicas where the databases are being opened * read-only. If this happens, ENOENT is returned by the * open() call. */ } catch (XmlException &xe) { ostringstream o; XmlException::ExceptionCode ec = xe.getExceptionCode(); if (ec == XmlException::DATABASE_ERROR) { int dbErr = xe.getDbErrno(); if (dbErr != ENOENT && dbErr != DB_REP_LOCKOUT) { o << envHome_ << ":" << xe.what() << endl << "DB_ERRNO:" << dbErr << endl; throwException(o.str()); } } else if (ec != XmlException::CONTAINER_NOT_FOUND) { o << envHome_ << ":" << xe.what() << endl << "ExceptionCode :" << ec << endl; throwException(o.str()); } yield(); } } }
void putDocWithoutDefaultCompression(XmlManager& mgr, const string& containerName, XmlDocument& xdoc, XmlUpdateContext& uc) { // Set the container type as WholedocContainer and turn off // the default compression XmlContainerConfig contConf; contConf.setAllowCreate(true); contConf.setContainerType(XmlContainer::WholedocContainer); contConf.setCompressionName(XmlContainerConfig::NO_COMPRESSION); // Create container XmlContainer cont = mgr.createContainer(containerName, contConf); // Put Document cont.putDocument(xdoc, uc); }
void putDocWithDefaultCompression(XmlManager& mgr, const string& containerName, XmlDocument& xdoc, XmlUpdateContext& uc) { // Set the container type as WholedocContainer and // use the default compression XmlContainerConfig contConf; contConf.setAllowCreate(true); contConf.setContainerType(XmlContainer::WholedocContainer); // The following line is unnecessary because default compression // would take effect if user do not turn off it explicitly. contConf.setCompressionName(XmlContainerConfig::DEFAULT_COMPRESSION); // Create container XmlContainer cont = mgr.createContainer(containerName, contConf); // Put Document cont.putDocument(xdoc, uc); }