use of doitincloud.commons.exceptions.NotFoundException in project rdbcache by rdbcache.
the class RdbcacheApis method delall_get.
/**
* delall_get get single item
*
* To delete a key from redis and database based on the input key. No query string.
* It returns immediately.
*
* @param request HttpServletRequest
* @param key String, hash key
* @param opt1 String, can be "sync" or "async" and table
* @param opt2 String, can be "sync" or "async" and table, but not the same as opt1
* @return ResponseEntity
*/
@RequestMapping(value = { "/rdbcache/v1/delall/{key}", "/rdbcache/v1/delall/{key}/{opt1}", "/rdbcache/v1/delall/{key}/{opt1}/{opt2}" }, method = RequestMethod.GET)
public ResponseEntity<?> delall_get(HttpServletRequest request, @PathVariable("key") String key, @PathVariable Optional<String> opt1, @PathVariable Optional<String> opt2) {
if (request.getParameterMap().size() != 0) {
throw new BadRequestException("query string is not supported");
}
if (key.equals("*")) {
throw new BadRequestException("no * allowed as key");
}
Context context = new Context();
KvPairs pairs = new KvPairs(key);
AnyKey anyKey = Request.process(context, request, pairs, opt1, opt2);
if (anyKey.getKeyInfo().getIsNew()) {
throw new NotFoundException("key not found for " + key);
}
LOGGER.trace(anyKey.print() + " pairs(" + pairs.size() + "): " + pairs.printKey());
AppCtx.getAsyncOps().doDeleteFromRedisAndDbase(context, pairs, anyKey);
return Response.send(context, pairs);
}
use of doitincloud.commons.exceptions.NotFoundException in project rdbcache by rdbcache.
the class RdbcacheApis method delkey_get.
/**
* delkey_get get/delete single item
*
* To delete a key from redis based on the input key. No query string.
* It returns immediately. It will not delete database entry.
*
* @param request HttpServletRequest
* @param key String, hash key
* @param opt1 String, can be "sync" or "async" and table
* @param opt2 String, can be "sync" or "async" and table, but not the same as opt1
* @return ResponseEntity
*/
@RequestMapping(value = { "/rdbcache/v1/delkey/{key}", "/rdbcache/v1/delkey/{key}/{opt1}", "/rdbcache/v1/delkey/{key}/{opt1}/{opt2}" }, method = { RequestMethod.GET, RequestMethod.DELETE })
public ResponseEntity<?> delkey_get(HttpServletRequest request, @PathVariable("key") String key, @PathVariable Optional<String> opt1, @PathVariable Optional<String> opt2) {
if (request.getParameterMap().size() != 0) {
throw new BadRequestException("query string is not supported");
}
if (key.equals("*")) {
throw new BadRequestException("no * allowed as key");
}
Context context = new Context();
KvPairs pairs = new KvPairs(key);
AnyKey anyKey = Request.process(context, request, pairs, opt1, opt2);
if (anyKey.getKeyInfo().getIsNew()) {
throw new NotFoundException("key not found for " + key);
}
LOGGER.trace(anyKey.print() + " pairs(" + pairs.size() + "): " + pairs.printKey());
AppCtx.getAsyncOps().doDeleteFromRedis(context, pairs, anyKey);
return Response.send(context, pairs);
}
use of doitincloud.commons.exceptions.NotFoundException in project rdbcache by rdbcache.
the class RdbcacheApis method pull_post.
/**
* pull_post post multiple items
*
* To pull one or more entries based on input keys. No * key. No query string.
* Once data found, it returns immediately. It queries redis first, then database.
*
* @param request HttpServletRequest
* @param opt1 String, can be expire or table or "sync" or "async"
* @param opt2 String, can be expire or table or "sync" or "async", but not otp1
* @param opt3 String, can be expire or table or "sync" or "async", but not otp1 and opt2
* @return ResponseEntity
*/
@RequestMapping(value = { "/rdbcache/v1/pull", "/rdbcache/v1/pull/{opt1}", "/rdbcache/v1/pull/{opt1}/{opt2}", "/rdbcache/v1/pull/{opt1}/{opt2}/{opt3}" }, method = RequestMethod.POST)
public ResponseEntity<?> pull_post(HttpServletRequest request, @PathVariable Optional<String> opt1, @PathVariable Optional<String> opt2, @PathVariable Optional<String> opt3, @RequestBody ArrayList<String> keys) {
if (request.getParameterMap().size() != 0) {
throw new BadRequestException("query string is not supported");
}
if (keys == null || keys.size() == 0) {
throw new BadRequestException("missing keys");
}
if (keys.contains("*")) {
throw new BadRequestException("no * allowed as key");
}
if (request.getParameterMap().size() > 0) {
throw new BadRequestException("query string is not supported");
}
Context context = new Context(true, true);
KvPairs pairs = new KvPairs(keys);
AnyKey anyKey = Request.process(context, request, pairs, opt1, opt2, opt3);
if (anyKey.size() != pairs.size()) {
throw new NotFoundException("one or more keys not found");
}
for (int i = 0; i < anyKey.size(); i++) {
KvPair pair = pairs.get(i);
KeyInfo keyInfo = anyKey.get(i);
if (keyInfo.getIsNew()) {
throw new NotFoundException("key not found for " + pair.getId());
}
}
LOGGER.trace(anyKey.print() + " pairs(" + pairs.size() + "): " + pairs.printKey());
if (!AppCtx.getRedisRepo().find(context, pairs, anyKey)) {
KvPairs dbPairs = new KvPairs();
for (int i = 0; i < pairs.size(); i++) {
KvPair pair = pairs.get(i);
if (!pair.hasContent()) {
KeyInfo keyInfo = anyKey.get(i);
KvPairs pairsNew = new KvPairs(pair);
AnyKey anyKeyNew = new AnyKey(keyInfo);
if (AppCtx.getDbaseRepo().find(context, pairsNew, anyKeyNew)) {
dbPairs.add(pair);
}
}
}
if (dbPairs.size() > 0) {
AppCtx.getAsyncOps().doSaveToRedis(context, dbPairs, anyKey);
}
}
return Response.send(context, pairs);
}
use of doitincloud.commons.exceptions.NotFoundException in project rdbcache by rdbcache.
the class RdbcacheApis method get_get.
/**
* get_get get single item
*
* To get data based on key and/or query string.
* Once data found, it returns immediately. It queries redis first, then database.
*
* @param request HttpServletRequest
* @param key String, hash key
* @param opt1 String, can be expire or table or "sync" or "async"
* @param opt2 String, can be expire or table or "sync" or "async", but not otp1
* @param opt3 String, can be expire or table or "sync" or "async", but not otp1 and opt2
* @return ResponseEntity
*/
@RequestMapping(value = { "/rdbcache/v1/get/{key}", "/rdbcache/v1/get/{key}/{opt1}", "/rdbcache/v1/get/{key}/{opt1}/{opt2}", "/rdbcache/v1/get/{key}/{opt1}/{opt2}/{opt3}" }, method = RequestMethod.GET)
public ResponseEntity<?> get_get(HttpServletRequest request, @PathVariable("key") String key, @PathVariable Optional<String> opt1, @PathVariable Optional<String> opt2, @PathVariable Optional<String> opt3) {
Context context = new Context(true);
KvPairs pairs = new KvPairs(key);
AnyKey anyKey = Request.process(context, request, pairs, opt1, opt2, opt3);
LOGGER.trace(anyKey.print() + " pairs(" + pairs.size() + "): " + pairs.printKey());
if (key.equals("*")) {
if (AppCtx.getDbaseRepo().find(context, pairs, anyKey)) {
AppCtx.getAsyncOps().doSaveToRedis(context, pairs, anyKey);
} else {
throw new NotFoundException(context, "data not found");
}
} else {
if (!AppCtx.getRedisRepo().find(context, pairs, anyKey)) {
if (AppCtx.getDbaseRepo().find(context, pairs, anyKey)) {
AppCtx.getAsyncOps().doSaveToRedis(context, pairs, anyKey);
} else {
throw new NotFoundException(context, "data not found");
}
}
}
return Response.send(context, pairs);
}
Aggregations