Search in sources :

Example 16 with BadRequestException

use of doitincloud.commons.exceptions.BadRequestException in project rdbcache by rdbcache.

the class Request method processOptions.

private static void processOptions(Context context, HttpServletRequest request, KeyInfo keyInfo, String[] options) {
    Map<String, String[]> params = request.getParameterMap();
    if (keyInfo.getIsNew()) {
        if (options[1] != null) {
            keyInfo.setTable(options[1]);
        }
        if (options[0] != null) {
            keyInfo.setExpire(options[0]);
        }
        if (params != null && params.size() > 0) {
            QueryInfo queryInfo = new QueryInfo(keyInfo.getTable(), params);
            keyInfo.setQuery(queryInfo);
        }
    } else {
        if (options[0] != null && !options[0].equals(keyInfo.getExpire())) {
            keyInfo.setExpire(options[0]);
            keyInfo.setIsNew(true);
        }
        if (options[1] != null && !options[1].equals(keyInfo.getTable())) {
            throw new BadRequestException(context, "can not change table name for an existing key");
        }
        if (params != null && params.size() > 0) {
            QueryInfo queryInfo = new QueryInfo(keyInfo.getTable(), params);
            if (keyInfo.getQueryKey() == null || !keyInfo.getQueryKey().equals(queryInfo.getKey())) {
                throw new BadRequestException(context, "can not modify condition for an existing key");
            }
        }
    }
}
Also used : BadRequestException(doitincloud.commons.exceptions.BadRequestException) QueryInfo(doitincloud.rdbcache.queries.QueryInfo)

Aggregations

BadRequestException (doitincloud.commons.exceptions.BadRequestException)16 Context (doitincloud.rdbcache.supports.Context)15 KvPairs (doitincloud.rdbcache.supports.KvPairs)14 AnyKey (doitincloud.rdbcache.supports.AnyKey)12 KeyInfo (doitincloud.rdbcache.models.KeyInfo)7 KvPair (doitincloud.rdbcache.models.KvPair)7 NotFoundException (doitincloud.commons.exceptions.NotFoundException)3 QueryInfo (doitincloud.rdbcache.queries.QueryInfo)3 KvIdType (doitincloud.rdbcache.models.KvIdType)2