// mutex is locked if present and necessary int DictionaryDatabase::defineStringName(OperationContext &context, const char *name, size_t namelen, NameID &id) { // Primary { id -> name\0 } // Secondary { name -> id } int err = 0; id.reset(); DbtIn primaryData((void*)name, namelen + 1); // add null DbtIn secondaryKey((void*)name, namelen); // don't add null err = primary_->appendPrimary(context, id, primaryData, /*no flags*/0); if (err == 0) { /* Cache after insert. This prevents the cache from returning bad answers * on a transaction abort, and speeds up access to newly inserted element * and attribute names that are needed for indexing after an insert. */ cache_.insert(id.raw(), primaryData); id.setDbtFromThis(context.key()); Transaction *txn = getTxn(context); err = secondary_->put(txn, &secondaryKey, &context.key(), /*no flags*/0); if (err == 0) { /* Add to the transaction's string cache, that way if an abort occurs * the values can be removed from the cache. */ if (txn) { DictionaryStringCache *dsc = txn->getStringCache(this, true); dsc->insert(&secondaryKey, id.raw()); } if (Log::isLogEnabled(Log::C_DICTIONARY, Log::L_INFO)) { ostringstream oss; oss << "Define new name " << id << " -> " << name; Log::log(environment_, Log::C_DICTIONARY, Log::L_INFO, name_.c_str(), oss.str().c_str()); } } } return err; }
int PrimaryDatabase::putPrimary(OperationContext &context, const NameID &id, const DbXmlDbt &data, u_int32_t flags) { id.setDbtFromThis(context.key()); return put(context.txn(), &context.key(), &(const_cast<DbXmlDbt&>(data)), flags); }
int PrimaryDatabase::deletePrimary(OperationContext &context, const NameID &id, u_int32_t flags) { id.setDbtFromThis(context.key()); return del(context.txn(), &context.key(), flags); }
int PrimaryDatabase::getPrimary(OperationContext &context, const NameID &id, DbtOut *data, u_int32_t flags) const { id.setDbtFromThis(context.key()); return get(context.txn(), &context.key(), data, flags); }