|
@@ -24,9 +24,14 @@ TeBkWorld TeBkRestController::db() {
|
|
int rid = rand() % 10000 + 1;
|
|
int rid = rand() % 10000 + 1;
|
|
GenericObject id;
|
|
GenericObject id;
|
|
id << rid;
|
|
id << rid;
|
|
- TeBkWorld w = sqli->get<TeBkWorld>(id);
|
|
|
|
- delete sqli;
|
|
|
|
- return w;
|
|
|
|
|
|
+ try {
|
|
|
|
+ TeBkWorld w = sqli->get<TeBkWorld>(id);
|
|
|
|
+ delete sqli;
|
|
|
|
+ return w;
|
|
|
|
+ } catch(const std::exception& e) {
|
|
|
|
+ delete sqli;
|
|
|
|
+ throw e;
|
|
|
|
+ }
|
|
}
|
|
}
|
|
|
|
|
|
std::vector<TeBkWorld> TeBkRestController::queries(std::string queries) {
|
|
std::vector<TeBkWorld> TeBkRestController::queries(std::string queries) {
|
|
@@ -34,25 +39,30 @@ std::vector<TeBkWorld> TeBkRestController::queries(std::string queries) {
|
|
int queryCount = 1;
|
|
int queryCount = 1;
|
|
try {
|
|
try {
|
|
queryCount = CastUtil::lexical_cast<int>(queries);
|
|
queryCount = CastUtil::lexical_cast<int>(queries);
|
|
- } catch(...) {
|
|
|
|
|
|
+ } catch(const std::exception& e) {
|
|
}
|
|
}
|
|
if(queryCount<1)queryCount=1;
|
|
if(queryCount<1)queryCount=1;
|
|
else if(queryCount>500)queryCount=500;
|
|
else if(queryCount>500)queryCount=500;
|
|
|
|
|
|
DataSourceInterface* sqli = DataSourceManager::getImpl();
|
|
DataSourceInterface* sqli = DataSourceManager::getImpl();
|
|
|
|
|
|
- std::string tbName = "world";
|
|
|
|
- sqli->startSession(&tbName);
|
|
|
|
- for (int c = 0; c < queryCount; ++c) {
|
|
|
|
- int rid = rand() % 10000 + 1;
|
|
|
|
- GenericObject id;
|
|
|
|
- id << rid;
|
|
|
|
- TeBkWorld w = sqli->get<TeBkWorld>(id);
|
|
|
|
- wlst.push_back(w);
|
|
|
|
|
|
+ try {
|
|
|
|
+ std::string tbName = "world";
|
|
|
|
+ sqli->startSession(&tbName);
|
|
|
|
+ for (int c = 0; c < queryCount; ++c) {
|
|
|
|
+ int rid = rand() % 10000 + 1;
|
|
|
|
+ GenericObject id;
|
|
|
|
+ id << rid;
|
|
|
|
+ TeBkWorld w = sqli->get<TeBkWorld>(id);
|
|
|
|
+ wlst.push_back(w);
|
|
|
|
+ }
|
|
|
|
+ sqli->endSession();
|
|
|
|
+ delete sqli;
|
|
|
|
+ return wlst;
|
|
|
|
+ } catch(const std::exception& e) {
|
|
|
|
+ delete sqli;
|
|
|
|
+ throw e;
|
|
}
|
|
}
|
|
- sqli->endSession();
|
|
|
|
- delete sqli;
|
|
|
|
- return wlst;
|
|
|
|
}
|
|
}
|
|
|
|
|
|
std::vector<TeBkWorld> TeBkRestController::updates(std::string queries) {
|
|
std::vector<TeBkWorld> TeBkRestController::updates(std::string queries) {
|
|
@@ -60,36 +70,40 @@ std::vector<TeBkWorld> TeBkRestController::updates(std::string queries) {
|
|
int queryCount = 1;
|
|
int queryCount = 1;
|
|
try {
|
|
try {
|
|
queryCount = CastUtil::lexical_cast<int>(queries);
|
|
queryCount = CastUtil::lexical_cast<int>(queries);
|
|
- } catch(...) {
|
|
|
|
|
|
+ } catch(const std::exception& e) {
|
|
}
|
|
}
|
|
if(queryCount<1)queryCount=1;
|
|
if(queryCount<1)queryCount=1;
|
|
else if(queryCount>500)queryCount=500;
|
|
else if(queryCount>500)queryCount=500;
|
|
|
|
|
|
DataSourceInterface* sqli = DataSourceManager::getImpl();
|
|
DataSourceInterface* sqli = DataSourceManager::getImpl();
|
|
|
|
|
|
- std::string tbName = "world";
|
|
|
|
- sqli->startSession(&tbName);
|
|
|
|
- for (int c = 0; c < queryCount; ++c) {
|
|
|
|
- int rid = rand() % 10000 + 1;
|
|
|
|
- GenericObject id;
|
|
|
|
- id << rid;
|
|
|
|
- TeBkWorld w = sqli->get<TeBkWorld>(id);
|
|
|
|
- int newRandomNumber = rand() % 10000 + 1;
|
|
|
|
- if(w.getRandomNumber() == newRandomNumber) {
|
|
|
|
- newRandomNumber -= 1;
|
|
|
|
|
|
+ try {
|
|
|
|
+ std::string tbName = "world";
|
|
|
|
+ sqli->startSession(&tbName);
|
|
|
|
+ for (int c = 0; c < queryCount; ++c) {
|
|
|
|
+ int rid = rand() % 10000 + 1;
|
|
|
|
+ GenericObject id;
|
|
|
|
+ id << rid;
|
|
|
|
+ TeBkWorld w = sqli->get<TeBkWorld>(id);
|
|
|
|
+ int newRandomNumber = rand() % 10000 + 1;
|
|
|
|
+ if(w.getRandomNumber() == newRandomNumber) {
|
|
|
|
+ newRandomNumber -= 1;
|
|
|
|
+ }
|
|
|
|
+ w.setRandomNumber(newRandomNumber);
|
|
|
|
+ wlst.push_back(w);
|
|
}
|
|
}
|
|
- w.setRandomNumber(newRandomNumber);
|
|
|
|
- wlst.push_back(w);
|
|
|
|
- }
|
|
|
|
|
|
|
|
- sqli->startTransaction();
|
|
|
|
- sqli->bulkUpdate<TeBkWorld>(wlst);
|
|
|
|
- sqli->commit();
|
|
|
|
|
|
+ sqli->startTransaction();
|
|
|
|
+ sqli->bulkUpdate<TeBkWorld>(wlst);
|
|
|
|
+ sqli->commit();
|
|
|
|
|
|
- sqli->endSession();
|
|
|
|
-
|
|
|
|
- delete sqli;
|
|
|
|
- return wlst;
|
|
|
|
|
|
+ sqli->endSession();
|
|
|
|
+ delete sqli;
|
|
|
|
+ return wlst;
|
|
|
|
+ } catch(const std::exception& e) {
|
|
|
|
+ delete sqli;
|
|
|
|
+ throw e;
|
|
|
|
+ }
|
|
}
|
|
}
|
|
|
|
|
|
std::string TeBkRestController::plaintext() {
|
|
std::string TeBkRestController::plaintext() {
|
|
@@ -99,37 +113,50 @@ std::string TeBkRestController::plaintext() {
|
|
void TeBkRestController::updateCache() {
|
|
void TeBkRestController::updateCache() {
|
|
CacheInterface* cchi = CacheManager::getImpl();
|
|
CacheInterface* cchi = CacheManager::getImpl();
|
|
DataSourceInterface* sqli = DataSourceManager::getImpl();
|
|
DataSourceInterface* sqli = DataSourceManager::getImpl();
|
|
- std::string tbName = "world";
|
|
|
|
- sqli->startSession(&tbName);
|
|
|
|
- for (int c = 1; c <= 10000; ++c) {
|
|
|
|
- GenericObject id;
|
|
|
|
- id << c;
|
|
|
|
- TeBkWorld w = sqli->get<TeBkWorld>(id);
|
|
|
|
- cchi->setO(CastUtil::lexical_cast<std::string>(c), w);
|
|
|
|
|
|
+
|
|
|
|
+ try {
|
|
|
|
+ std::string tbName = "world";
|
|
|
|
+ sqli->startSession(&tbName);
|
|
|
|
+ std::vector<TeBkWorld> wlist = sqli->getAll<TeBkWorld>();
|
|
|
|
+ sqli->endSession();
|
|
|
|
+ for (int c = 0; c < (int)wlist.size(); ++c) {
|
|
|
|
+ TeBkWorld& w = wlist.at(c);
|
|
|
|
+ cchi->setO(CastUtil::lexical_cast<std::string>(w.getId()), w);
|
|
|
|
+ }
|
|
|
|
+ delete sqli;
|
|
|
|
+ delete cchi;
|
|
|
|
+ } catch(const std::exception& e) {
|
|
|
|
+ delete sqli;
|
|
|
|
+ delete cchi;
|
|
|
|
+ throw e;
|
|
}
|
|
}
|
|
- sqli->endSession();
|
|
|
|
- delete sqli;
|
|
|
|
- delete cchi;
|
|
|
|
}
|
|
}
|
|
|
|
|
|
std::vector<TeBkWorld> TeBkRestController::cachedWorlds(std::string count) {
|
|
std::vector<TeBkWorld> TeBkRestController::cachedWorlds(std::string count) {
|
|
int queryCount = 1;
|
|
int queryCount = 1;
|
|
try {
|
|
try {
|
|
queryCount = CastUtil::lexical_cast<int>(count);
|
|
queryCount = CastUtil::lexical_cast<int>(count);
|
|
- } catch(...) {
|
|
|
|
|
|
+ } catch(const std::exception& e) {
|
|
}
|
|
}
|
|
if(queryCount<1)queryCount=1;
|
|
if(queryCount<1)queryCount=1;
|
|
else if(queryCount>500)queryCount=500;
|
|
else if(queryCount>500)queryCount=500;
|
|
|
|
|
|
CacheInterface* cchi = CacheManager::getImpl();
|
|
CacheInterface* cchi = CacheManager::getImpl();
|
|
- std::vector<std::string> keys;
|
|
|
|
- for (int c = 0; c < queryCount; ++c) {
|
|
|
|
- int rid = rand() % 10000 + 1;
|
|
|
|
- keys.push_back(CastUtil::lexical_cast<std::string>(rid));
|
|
|
|
- }
|
|
|
|
|
|
|
|
- std::vector<TeBkWorld> wlst = cchi->mgetO<TeBkWorld>(keys);
|
|
|
|
|
|
+ try {
|
|
|
|
+ std::vector<std::string> keys;
|
|
|
|
+ for (int c = 0; c < queryCount; ++c) {
|
|
|
|
+ int rid = rand() % 10000 + 1;
|
|
|
|
+ keys.push_back(CastUtil::lexical_cast<std::string>(rid));
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ std::vector<TeBkWorld> wlst = cchi->mgetO<TeBkWorld>(keys);
|
|
|
|
|
|
- delete cchi;
|
|
|
|
- return wlst;
|
|
|
|
|
|
+ delete cchi;
|
|
|
|
+ return wlst;
|
|
|
|
+ } catch(const std::exception& e) {
|
|
|
|
+ delete cchi;
|
|
|
|
+ throw e;
|
|
|
|
+ }
|
|
}
|
|
}
|
|
|
|
+
|