int DictionaryDatabase::lookupIDFromName(OperationContext &context, const Name &name, NameID &id, bool define) { int err = 0; if (name == Name::dbxml_colon_name) { id = nidName_; } else if (name == Name::dbxml_colon_root) { id = nidRoot_; } if (id == 0) { MutexLock ml(mutex_); u_int32_t flags = (getTxn(context) && !define) ? DB_READ_COMMITTED : 0; name.setDbtFromThis_SecondaryKey(context.key()); if (stringCacheLookup(context, context.key(), id)) return 0; err = secondary_->get(getTxn(context), &context.key(), &context.data(), flags); if (err == 0) { id.setThisFromDbt(context.data()); stringCache_.insert(&context.key(), id.raw()); } else if (err == DB_NOTFOUND && define) { err = defineName(context, name, id); // define from name:uri } else { id.reset(); } } return err; }
void DictionaryDatabase::display(OperationContext &context, ostream &out) const { { Cursor myCursor(const_cast<PrimaryDatabase&>(*primary_.get()), getTxn(context), CURSOR_READ, 0); if(myCursor.error() != 0) throw XmlException(myCursor.error()); int err = 0; NameID id; while((err = myCursor.get(context.key(), context.data(), DB_NEXT)) == 0) { id.setThisFromDbtAsId(context.key()); Buffer val(context.data().data, context.data().size, true); out << id << " -> " << val.asString(true) << endl; } } { Cursor myCursor(const_cast<SecondaryDatabase&>(*secondary_.get()), getTxn(context), CURSOR_READ, 0); if(myCursor.error() != 0) throw XmlException(myCursor.error()); int err = 0; NameID id; while((err = myCursor.get(context.key(), context.data(), DB_NEXT)) == 0) { Buffer val(context.key().data, context.key().size, true); id.setThisFromDbt(context.data()); out << val.asString(true) << " -> " << id << endl; } } }
int DictionaryDatabase::lookupIDFromStringNameInternal( OperationContext &context, DbXmlDbt &dbt, NameID &id, bool define) const { if (!dbt.size) { id.reset(); return 0; } u_int32_t flags = (getTxn(context) && !define) ? DB_READ_COMMITTED : 0; if (stringCacheLookup(context, dbt, id)) return 0; int err = secondary_->get(getTxn(context), &dbt, &context.data(), flags); if (err == 0) { id.setThisFromDbt(context.data()); stringCache_.insert(&dbt, id.raw()); } else id.reset(); return err; }