use of com.rdbcache.exceptions.ServerErrorException in project rdbcache by rdbcache.
the class Query method executeDelete.
public boolean executeDelete() {
boolean allOk = true;
for (int i = 0; i < pairs.size(); i++) {
KvPair pair = pairs.get(i);
KeyInfo keyInfo = anyKey.getAny(i);
String table = keyInfo.getTable();
if (!keyInfo.getIsNew() && !keyInfo.hasParams() && keyInfo.ifJustCreated()) {
waitForParamsUpdate(pair.getId(), keyInfo);
}
if (!Parser.prepareStandardClauseParams(context, pair, keyInfo)) {
String msg = "executeDelete failed when calling prepareStandardClauseParams for " + pair.getId();
LOGGER.error(msg);
context.logTraceMessage(msg);
if (context.isSync()) {
throw new ServerErrorException(context, msg);
}
continue;
}
params = keyInfo.getParams();
String clause = keyInfo.getClause();
sql = "delete from " + table + " where " + clause + " limit 1";
LOGGER.trace("sql: " + sql);
LOGGER.trace("params: " + params.toString());
StopWatch stopWatch = context.startStopWatch("dbase", "jdbcTemplate.delete");
try {
if (jdbcTemplate.update(sql, params.toArray()) > 0) {
if (stopWatch != null)
stopWatch.stopNow();
LOGGER.trace("delete " + pair.getId() + " from " + table);
continue;
} else {
if (stopWatch != null)
stopWatch.stopNow();
allOk = false;
}
} catch (Exception e) {
if (stopWatch != null)
stopWatch.stopNow();
allOk = false;
String msg = e.getCause().getMessage();
LOGGER.error(msg);
context.logTraceMessage(msg);
e.printStackTrace();
if (context.isSync()) {
throw new ServerErrorException(context, msg);
}
}
keyInfo.setQueryKey(null);
}
return allOk;
}
use of com.rdbcache.exceptions.ServerErrorException in project rdbcache by rdbcache.
the class Query method executeSelect.
public boolean executeSelect() {
KeyInfo keyInfo = anyKey.getKeyInfo();
String table = keyInfo.getTable();
LOGGER.trace("sql: " + sql);
LOGGER.trace("params: " + (params != null ? params.toString() : "null"));
List<Map<String, Object>> list = null;
StopWatch stopWatch = context.startStopWatch("dbase", "jdbcTemplate.queryForList");
try {
if (params != null) {
list = jdbcTemplate.queryForList(sql, params.toArray());
} else {
list = jdbcTemplate.queryForList(sql);
}
if (stopWatch != null)
stopWatch.stopNow();
if (list != null && list.size() > 0) {
for (int i = 0; i < list.size(); i++) {
KvPair pair = pairs.getAny(i);
keyInfo = anyKey.getAny(i);
pair.setData(list.get(i));
//
if (!Parser.prepareStandardClauseParams(context, pair, keyInfo)) {
String msg = "executeSelect failed when prepareStandardClauseParams for " + pair.getId();
LOGGER.error(msg);
context.logTraceMessage(msg);
if (context.isSync()) {
throw new ServerErrorException(context, msg);
}
}
LOGGER.trace("found " + pair.getId() + " from " + table);
}
return true;
}
} catch (Exception e) {
if (stopWatch != null)
stopWatch.stopNow();
e.printStackTrace();
String msg = e.getCause().getMessage();
LOGGER.error(msg);
context.logTraceMessage(msg);
if (context.isSync()) {
throw new ServerErrorException(context, msg);
}
}
return false;
}
use of com.rdbcache.exceptions.ServerErrorException in project rdbcache by rdbcache.
the class Request method process.
public static AnyKey process(Context context, HttpServletRequest request, KvPairs pairs, Optional<String> opt1, Optional<String> opt2) {
LOGGER.info("URI: " + request.getRequestURI());
if (PropCfg.getEnableMonitor())
context.enableMonitor(request);
AnyKey anyKey = new AnyKey();
if (pairs == null) {
return anyKey;
}
// find the keyinfo for the first key
if (pairs.size() > 0) {
AppCtx.getKeyInfoRepo().find(context, new KvPairs(pairs.getPair()), anyKey);
}
KeyInfo keyInfo = anyKey.getAny();
Map<String, String[]> params = request.getParameterMap();
if ((params != null && params.size() > 0) || opt1 != null || opt2 != null) {
processOptions(context, keyInfo, params, opt1, opt2);
}
if (pairs.size() == 0 || context.getAction().startsWith("select_")) {
return anyKey;
}
// find keyinfo for the second key and after
if (pairs.size() > 1) {
AppCtx.getKeyInfoRepo().find(context, pairs, anyKey);
}
for (int i = 0; i < pairs.size() && i < anyKey.size(); i++) {
keyInfo = anyKey.get(i);
if (keyInfo.getIsNew()) {
keyInfo.setIsNew(false);
String key = pairs.get(i).getId();
AppCtx.getLocalCache().putKeyInfo(key, keyInfo);
keyInfo.setIsNew(true);
}
}
if (anyKey.size() != 1 && pairs.size() != anyKey.size()) {
throw new ServerErrorException(context, "case not supported, anyKey size(" + anyKey.size() + ") != 1 && pairs size(" + pairs.size() + ") != anyKey size(" + anyKey.size() + ")");
}
return anyKey;
}
Aggregations