text
stringlengths 0
2.2M
|
---|
void TeBkUmMgrRouter::db(TeBkUmMgrWorld& w) {
|
#ifdef INC_SDORM_MONGO
|
MongoDBRawDataSourceImpl* sqli = getDb();
|
int rid = rand() % 10000 + 1;
|
try {
|
bson_t q = BSON_INITIALIZER;
|
bson_append_int32(&q, "_id", 3, rid);
|
sqli->begin(WORLD);
|
sqli->executeQuery(&q, &w, &TeBkUmMgrRouter::dbUtil);
|
sqli->end();
|
bson_destroy(&q);
|
} catch(const std::exception& e) {
|
throw e;
|
}
|
#endif
|
}
|
#ifdef INC_SDORM_MONGO
|
void TeBkUmMgrRouter::dbUtil(void* ctx, int rn, std::vector<MgRawRes>& data) {
|
TeBkUmMgrWorld* w = (TeBkUmMgrWorld*)ctx;
|
for(int i=0;i<(int)data.size();i++) {
|
if(data.at(i).n=="_id") {
|
w->setId((int)data.at(i).d);
|
if(w->getId()<=0) {
|
w->setId((int)data.at(i).l);
|
}
|
}
|
if(data.at(i).n=="randomNumber") {
|
w->setRandomNumber((int)data.at(i).d);
|
if(w->getRandomNumber()==0) {
|
w->setRandomNumber((int)data.at(i).l);
|
}
|
}
|
}
|
}
|
#endif
|
void TeBkUmMgrRouter::queries(const char* q, int ql, std::vector<TeBkUmMgrWorld>& wlst) {
|
int queryCount = 0;
|
strToNum(q, ql, queryCount);
|
if(queryCount<1)queryCount=1;
|
else if(queryCount>500)queryCount=500;
|
#ifdef INC_SDORM_MONGO
|
MongoDBRawDataSourceImpl* sqli = getDb();
|
try {
|
TeBkUmMgrWorld w;
|
sqli->begin(WORLD);
|
for (int c = 0; c < queryCount; ++c) {
|
int rid = rand() % 10000 + 1;
|
bson_t q = BSON_INITIALIZER;
|
bson_append_int32(&q, "_id", 3, rid);
|
sqli->executeQuery(&q, &w, &TeBkUmMgrRouter::dbUtil);
|
bson_destroy(&q);
|
wlst.push_back(w);
|
}
|
sqli->end();
|
} catch(const std::exception& e) {
|
throw e;
|
}
|
#endif
|
}
|
void TeBkUmMgrRouter::updates(const char* q, int ql, std::vector<TeBkUmMgrWorld>& wlst) {
|
int queryCount = 0;
|
strToNum(q, ql, queryCount);
|
if(queryCount<1)queryCount=1;
|
else if(queryCount>500)queryCount=500;
|
#ifdef INC_SDORM_MONGO
|
MongoDBRawDataSourceImpl* sqli = getDb();
|
try {
|
sqli->startBulk(WORLD);
|
for (int c = 0; c < queryCount; ++c) {
|
int rid = rand() % 10000 + 1;
|
bson_t q;
|
bson_init(&q);
|
bson_append_int32(&q, "_id", 3, rid);
|
TeBkUmMgrWorld w;
|
sqli->executeQuery(&q, &w, &TeBkUmMgrRouter::dbUtil);
|
int newRandomNumber = rand() % 10000 + 1;
|
if(w.getRandomNumber() == newRandomNumber) {
|
newRandomNumber += 1;
|
if(newRandomNumber>=10000) {
|
newRandomNumber = 1;
|
}
|
}
|
w.setRandomNumber(newRandomNumber);
|
bson_t du;
|
bson_t d;
|
bson_init(&du);
|
bson_append_document_begin(&du, "$set", 4, &d);
|
//bson_append_int32(&d, "_id", 3, w.getId());
|
bson_append_int32(&d, "randomNumber", 12, w.getRandomNumber());
|
bson_append_document_end(&du, &d);
|
sqli->addBulk(&q, &du);
|
/*char* str = bson_as_json(&du, NULL);
|
printf("%s\n", str);
|
bson_free(str);*/
|
bson_destroy(&du);
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.