use of doitincloud.rdbcache.models.KeyInfo in project rdbcache by rdbcache.
the class RequestTest method process1.
@Test
public void process1() {
try {
String key = "*";
Optional<String> tableOpt = Optional.of("tb1");
Optional<String> expireOpt = Optional.of("30");
String queryString = "id=1";
HttpServletRequest request = getRequest("get", key, null, tableOpt, expireOpt, queryString);
Context context = new Context();
AnyKey anyKey = Request.process(context, request, new KvPairs(key), tableOpt, expireOpt);
assertEquals(1, anyKey.size());
KeyInfo keyInfo = anyKey.getKeyInfo();
assertTrue(keyInfo.getIsNew());
assertEquals("KeyInfo(true, tb1, 30, {id: {=: [1]}})", keyInfo.toString());
} catch (Exception e) {
e.printStackTrace();
fail(e.getCause().getMessage());
}
}
use of doitincloud.rdbcache.models.KeyInfo in project rdbcache by rdbcache.
the class Query method ifInsertOk.
public boolean ifInsertOk() {
Assert.isTrue(anyKey.size() == 1, "anyKey.size() = " + anyKey.size() + ", insert only supports anyKey size == 1");
KeyInfo keyInfo = anyKey.getKeyInfo();
String table = keyInfo.getTable();
if (table == null) {
return false;
}
String queryKey = keyInfo.getQueryKey();
if (queryKey == null) {
return false;
}
return true;
}
use of doitincloud.rdbcache.models.KeyInfo in project rdbcache by rdbcache.
the class Query method ifDeleteOk.
public boolean ifDeleteOk() {
Assert.isTrue(anyKey.size() == pairs.size(), anyKey.size() + " != " + pairs.size() + ", delete only supports anyKey size == pairs size");
KeyInfo keyInfo = anyKey.getKeyInfo();
String table = keyInfo.getTable();
if (table == null) {
return false;
}
String queryKey = keyInfo.getQueryKey();
if (queryKey == null) {
return false;
}
return true;
}
use of doitincloud.rdbcache.models.KeyInfo 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);
if (pair.getType().equals("data")) {
pair.setType(table);
}
pair.setData(list.get(i));
keyInfo = anyKey.getAny(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 doitincloud.rdbcache.models.KeyInfo in project rdbcache by rdbcache.
the class Query method getLimit.
private int getLimit() {
KeyInfo keyInfo = anyKey.getKeyInfo();
Integer queryLimit = keyInfo.getQueryLimit();
int size = pairs.size();
int limit = 0;
if (queryLimit != null || size > 0) {
if (size == 0) {
limit = queryLimit;
} else if (queryLimit != null && size > queryLimit) {
limit = queryLimit;
} else {
limit = size;
}
}
if (limit == 0 && !context.isBatch()) {
limit = 1;
}
return limit;
}
Aggregations