本文整理汇总了C++中MojDbReq::txn方法的典型用法代码示例。如果您正苦于以下问题:C++ MojDbReq::txn方法的具体用法?C++ MojDbReq::txn怎么用?C++ MojDbReq::txn使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类MojDbReq
的用法示例。
在下文中一共展示了MojDbReq::txn方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: delObj
MojErr MojDb::delObj(const MojObject& id, const MojObject& obj, MojDbStorageItem* item, MojObject& foundObjOut, MojDbReq& req, MojUInt32 flags)
{
MojAssert(item);
MojLogTrace(s_log);
if (MojFlagGet(flags, FlagPurge)) {
// update indexes
MojTokenSet tokenSet;
// we want purge to force delete
req.fixmode(true);
MojErr err = m_kindEngine.update(NULL, &obj, req, OpDelete, tokenSet);
MojErrCheck(err);
// gross layering violation
err = req.txn()->offsetQuota(-(MojInt64) item->size());
MojErrCheck(err);
// permanently delete
bool found = false;
err = m_objDb->del(id, req.txn(), found);
MojErrCheck(err);
if (!found)
MojErrThrow(MojErrDbCorruptDatabase);
err = foundObjOut.put(IdKey, id);
MojErrCheck(err);
} else {
// set deleted flag and put if we are not purging
MojObject newObj = obj;
MojErr err = newObj.putBool(DelKey, true);
MojErrCheck(err);
err = putObj(id, newObj, &obj, item, req, OpDelete);
MojErrCheck(err);
foundObjOut = newObj;
}
return MojErrNone;
}
示例2: find
MojErr MojDbIndex::find(MojDbCursor& cursor, MojDbWatcher* watcher, MojDbReq& req)
{
LOG_TRACE("Entering function %s", __FUNCTION__);
MojAssert(isOpen());
MojAutoPtr<MojDbQueryPlan> plan(new MojDbQueryPlan(*m_kindEngine));
MojAllocCheck(plan.get());
MojErr err = plan->init(cursor.query(), *this);
MojErrCheck(err);
if (watcher) {
// we have to add the watch before beginning the txn or we may miss events
MojAssert(cursor.txn() == NULL);
err = addWatch(*plan, cursor, watcher, req);
MojErrCheck(err);
}
if (!cursor.txn()) {
MojDbStorageTxn* txn = req.txn();
bool cursorOwnsTxn = !(req.batch() || txn);
if (txn) {
cursor.txn(txn, cursorOwnsTxn);
} else {
MojRefCountedPtr<MojDbStorageTxn> localTxn;
err = m_collection->beginTxn(localTxn);
MojErrCheck(err);
cursor.txn(localTxn.get(), cursorOwnsTxn);
req.txn(localTxn.get());
}
}
cursor.m_dbIndex = this; // for debugging
err = m_collection->find(plan, cursor.txn(), cursor.m_storageQuery);
MojErrCheck(err);
cursor.m_watcher = watcher;
return MojErrNone;
}
示例3: stats
MojErr MojDbIndex::stats(MojObject& objOut, MojSize& usageOut, MojDbReq& req)
{
LOG_TRACE("Entering function %s", __FUNCTION__);
MojAssert(isOpen());
MojSize count = 0;
MojSize size = 0;
MojErr err = m_index->stats(req.txn(), count, size);
LOG_DEBUG("[db_mojodb] IndexStats: Kind: %s;Index: %s; Id: %zX; count= %zu; size= %zu; delMisses = %d, err= %d \n",
m_kind->name().data(), m_name.data(), idIndex(), count, size, m_delMisses, err);
MojErrCheck(err);
usageOut += size;
err = objOut.put(SizeKey, (MojInt64) size);
MojErrCheck(err);
err = objOut.put(CountKey, (MojInt64) count);
MojErrCheck(err);
err = objOut.put(DelMissesKey, (MojInt64) m_delMisses); // cumulative since start
MojErrCheck(err);
MojThreadReadGuard guard(m_lock);
if (!m_watcherMap.empty()) {
MojObject watcherInfo;
for (WatcherMap::ConstIterator i = m_watcherMap.begin(); i != m_watcherMap.end(); ++i) {
err = watcherInfo.put(i.key(), (MojInt64) i.value());
MojErrCheck(err);
}
err = objOut.put(WatchesKey, watcherInfo);
MojErrCheck(err);
}
return MojErrNone;
}
示例4: updateLocale
MojErr MojDbIndex::updateLocale(const MojChar* locale, MojDbReq& req)
{
LOG_TRACE("Entering function %s", __FUNCTION__);
MojAssert(isOpen());
MojAssert(locale);
bool haveCollate = false;
for (PropVec::ConstIterator i = m_props.begin(); i != m_props.end(); ++i) {
if ((*i)->collation() != MojDbCollationInvalid) {
haveCollate = true;
MojErr err = (*i)->updateLocale(locale);
MojErrCheck(err);
}
}
if (haveCollate) {
// drop and reindex
MojErr err = drop(req);
MojErrCheck(err);
err = build(req.txn());
MojErrCheck(err);
}
m_locale.assign(locale);
return MojErrNone;
}
示例5: readIds
MojErr MojDbKindState::readIds(const MojChar* key, MojDbReq& req, MojObject& objOut, MojRefCountedPtr<MojDbStorageItem>& itemOut)
{
MojErr err = readObj(key, objOut, m_kindEngine->indexIdDb(), req.txn(), itemOut);
MojErrCheck(err);
return MojErrNone;
}
示例6: writeIds
MojErr MojDbKindState::writeIds(const MojChar* key, const MojObject& obj, MojDbReq& req, MojRefCountedPtr<MojDbStorageItem>& oldItem)
{
MojErr err = writeObj(key, obj, m_kindEngine->indexIdDb(), req.txn(), oldItem);
MojErrCheck(err);
return MojErrNone;
}
示例7: open
MojErr MojDbIndex::open(MojDbStorageIndex* index, const MojObject& id, MojDbReq& req, bool created)
{
LOG_TRACE("Entering function %s", __FUNCTION__);
MojAssert(!isOpen() && !m_props.empty());
MojAssert(index);
// we don't want to take built-in props into account when sorting indexes,
m_sortKey = m_propNames;
m_id = id;
MojDbKey idKey;
MojErr err = idKey.assign(id);
MojErrCheck(err);
err = m_idSet.put(idKey);
MojErrCheck(err);
err = addBuiltinProps();
MojErrCheck(err);
if (created && !isIdIndex()) {
// if this index was just created, we need to re-index before committing the transaction
MojDbStorageTxn* txn = req.txn();
txn->notifyPreCommit(m_preCommitSlot);
txn->notifyPostCommit(m_postCommitSlot);
} else {
// otherwise it's ready
m_ready = true;
}
// and we're open
m_index.reset(index);
m_collection = m_index.get();
return MojErrNone;
}
示例8: initUsage
MojErr MojDbQuotaEngine::initUsage(MojDbKind* kind, MojDbReq& req)
{
MojAssert(kind);
MojRefCountedPtr<MojDbStorageItem> item;
MojErr err = m_usageDb->get(kind->id(), req.txn(), false, item);
MojErrCheck(err);
if (!item.get()) {
MojObject stats;
MojSize usage = 0;
err = kind->stats(stats, usage, req, false);
MojErrCheck(err);
err = insertUsage(kind->id(), (MojInt64) usage, req.txn());
MojErrCheck(err);
}
return MojErrNone;
}
示例9: drop
MojErr MojDbIndex::drop(MojDbReq& req)
{
LOG_TRACE("Entering function %s", __FUNCTION__);
MojAssert(isOpen());
MojErr err = m_index->drop(req.txn());
MojErrCheck(err);
return MojErrNone;
}
示例10: drop
MojErr MojDbIndex::drop(MojDbReq& req)
{
MojAssert(isOpen());
MojLogTrace(s_log);
MojErr err = m_index->drop(req.txn());
MojErrCheck(err);
return MojErrNone;
}
示例11: open
MojErr MojDbQuotaEngine::open(const MojObject& conf, MojDb* db, MojDbReq& req)
{
LOG_TRACE("Entering function %s", __FUNCTION__);
MojAssert(db);
MojErr err = db->storageEngine()->openDatabase(_T("UsageDbName"), req.txn(), m_usageDb);
MojErrCheck(err);
err = MojDbPutHandler::open(conf, db, req);
MojErrCheck(err);
MojDbKindEngine::KindMap& kinds = db->kindEngine()->kindMap();
for (MojDbKindEngine::KindMap::ConstIterator i = kinds.begin();
i != kinds.end(); ++i) {
err = initUsage(i.value().get(), req);
MojErrCheck(err);
}
err = refreshImpl(req.txn());
MojErrCheck(err);
m_isOpen = true;
return MojErrNone;
}
示例12: initTokens
MojErr MojDbKindState::initTokens(MojDbReq& req, const StringSet& strings)
{
// TODO: bug inside this function. (latest strace step)
MojAssertMutexLocked(m_lock);
// TODO: filing load tokens. Go inside readObj
// load tokens
MojErr err = readObj(TokensKey, m_tokensObj, m_kindEngine->kindDb(), req.txn(), m_oldTokensItem);
MojErrCheck(err);
// populate token vec
MojUInt8 maxToken = 0;
err = m_tokenVec.resize(m_tokensObj.size());
MojErrCheck(err);
for (MojObject::ConstIterator i = m_tokensObj.begin(); i != m_tokensObj.end(); ++i) {
MojString key = i.key();
MojInt64 value = i.value().intValue();
MojSize idx = (MojSize) (value - MojObjectWriter::TokenStartMarker);
if (value < MojObjectWriter::TokenStartMarker || value >= MojUInt8Max || idx >= m_tokenVec.size()) {
MojErrThrow(MojErrDbInvalidToken);
}
if (value > maxToken) {
maxToken = (MojUInt8) value;
}
err = m_tokenVec.setAt(idx, key);
MojErrCheck(err);
}
if (maxToken > 0) {
m_nextToken = (MojUInt8) (maxToken + 1);
}
// add strings
bool updated = false;
for (StringSet::ConstIterator i = strings.begin(); i != strings.end(); ++i) {
if (!m_tokensObj.contains(*i)) {
updated = true;
MojUInt8 token = 0;
TokenVec tokenVec;
MojObject tokenObj;
err = addPropImpl(*i, false, token, tokenVec, tokenObj);
MojErrCheck(err);
}
}
if (updated) {
err = writeTokens(m_tokensObj);
MojErrCheck(err);
}
return MojErrNone;
}
示例13: updateOwnIndexes
MojErr MojDbKind::updateOwnIndexes(const MojObject* newObj, const MojObject* oldObj, const MojDbReq& req, MojInt32& idxcount)
{
MojInt32 count = 0;
for (IndexVec::ConstIterator i = m_indexes.begin();
i != m_indexes.end(); ++i) {
count++;
MojErr err = (*i)->update(newObj, oldObj, req.txn(), req.fixmode());
MojErrCheck(err);
}
MojLogInfo(s_log, _T("Kind_UpdateOwnIndexes: %s; count: %d \n"), this->id().data(), count);
idxcount += count;
return MojErrNone;
}
示例14: getImpl
MojErr MojDb::getImpl(const MojObject& id, MojObjectVisitor& visitor, MojDbOp op, MojDbReq& req)
{
MojRefCountedPtr<MojDbStorageItem> item;
MojErr err = m_objDb->get(id, req.txn(), false, item);
MojErrCheck(err);
if (item.get()) {
MojString kindId;
err = item->kindId(kindId, m_kindEngine);
MojErrCheck(err);
err = m_kindEngine.checkPermission(kindId, op, req);
MojErrCheck(err);
err = item->visit(visitor, m_kindEngine);
MojErrCheck(err);
err = item->close();
MojErrCheck(err);
}
return MojErrNone;
}
示例15: open
MojErr MojDbKindEngine::open(MojDb* db, MojDbReq& req)
{
MojAssert(db);
MojAssertWriteLocked(db->m_schemaLock);
MojLogTrace(s_log);
// open kind db and index seq
m_db = db;
MojDbStorageEngine* engine = db->storageEngine();
MojDbStorageTxn* txn = req.txn();
MojAssert(engine);
MojErr err = engine->openDatabase(KindsDbName, txn, m_kindDb);
MojErrCheck(err);
err = engine->openDatabase(IndexIdsDbName, txn, m_indexIdDb);
MojErrCheck(err);
err = engine->openSequence(IndexIdsSeqName, txn, m_indexIdSeq);
MojErrCheck(err);
// built-in kinds
err = addBuiltin(RootKindJson, req);
MojErrCheck(err);
err = addBuiltin(KindKindJson, req);
MojErrCheck(err);
err = addBuiltin(RevTimestampJson, req);
MojErrCheck(err);
err = addBuiltin(DbStateJson, req);
MojErrCheck(err);
err = addBuiltin(PermissionJson, req);
MojErrCheck(err);
err = addBuiltin(QuotaJson, req);
MojErrCheck(err);
// built-in indexes
err = setupRootKind();
MojErrCheck(err);
// locale
err = db->getLocale(m_locale, req);
MojErrCheck(err);
// load kinds from obj db
err = loadKinds(req);
MojErrCheck(err);
return MojErrNone;
}