use of doitincloud.rdbcache.models.KvPair in project rdbcache by rdbcache.
the class RedisRepoImpl method findAndSave.
@Override
public boolean findAndSave(final Context context, final KvPairs pairs, final AnyKey anyKey) {
if (LOGGER.isTraceEnabled()) {
LOGGER.trace("findAndSave pairs(" + pairs.size() + "): " + pairs.printKey() + "anyKey(" + anyKey.size() + "): " + anyKey.printTable());
}
boolean allOk = true;
for (int i = 0; i < pairs.size(); i++) {
KvPair pair = pairs.get(i);
String key = pair.getId();
String type = pair.getType();
String hashKey = hdataPrefix + "::" + type + ":" + key;
KeyInfo keyInfo = anyKey.getAny(i);
Map<String, Object> map = pair.getData();
Map<String, Object> fmap = null;
if (enableDataCache) {
fmap = AppCtx.getCacheOps().getData(pair.getIdType());
if (fmap != null && fmap.size() > 0) {
LOGGER.debug("findAndSave - found from cache " + key);
}
AppCtx.getCacheOps().putData(pair, keyInfo);
}
StopWatch stopWatch = null;
if (fmap == null) {
try {
stopWatch = context.startStopWatch("redis", "hashOps.entries");
fmap = hashOps.entries(hashKey);
if (stopWatch != null)
stopWatch.stopNow();
if (fmap != null && fmap.size() > 0) {
LOGGER.debug("findAndSave - found from redis " + key);
}
} catch (Exception e) {
if (stopWatch != null)
stopWatch.stopNow();
String msg = e.getCause().getMessage();
LOGGER.error(msg);
e.printStackTrace();
throw new ServerErrorException(context, msg);
}
}
pair.setData(fmap);
try {
stopWatch = context.startStopWatch("redis", "hashOps.putAll");
hashOps.putAll(hashKey, map);
if (stopWatch != null)
stopWatch.stopNow();
LOGGER.debug("findAndSave - save " + key);
} catch (Exception e) {
if (stopWatch != null)
stopWatch.stopNow();
if (enableDataCache) {
AppCtx.getCacheOps().removeData(pair.getIdType());
}
allOk = false;
String msg = e.getCause().getMessage();
LOGGER.error(msg);
e.printStackTrace();
}
if (allOk) {
allOk = fmap != null && fmap.size() > 0;
}
}
if (LOGGER.isTraceEnabled())
LOGGER.trace("findAndSave returns " + allOk);
return allOk;
}
use of doitincloud.rdbcache.models.KvPair in project rdbcache by rdbcache.
the class ExpireOps method setExpireKey.
public void setExpireKey(Context context, KvPairs pairs, AnyKey anyKey) {
for (int i = 0; i < pairs.size(); i++) {
KvPair pair = pairs.get(i);
KeyInfo keyInfo = anyKey.getAny(i);
setExpireKey(context, pair, keyInfo);
}
}
use of doitincloud.rdbcache.models.KvPair in project rdbcache by rdbcache.
the class AbsDbaseRepo method update.
@Override
public boolean update(final Context context, final KvPairs pairs, final AnyKey anyKey) {
boolean allOk = true;
for (int i = 0; i < pairs.size(); i++) {
KvPair pair = pairs.get(i);
KeyInfo keyInfo = anyKey.getAny(i);
if (!update(context, pair, keyInfo)) {
allOk = false;
}
}
return allOk;
}
use of doitincloud.rdbcache.models.KvPair in project rdbcache by rdbcache.
the class AbsDbaseRepo method delete.
@Override
public boolean delete(final Context context, final KvPairs pairs, final AnyKey anyKey) {
boolean allOk = true;
for (int i = 0; i < pairs.size(); i++) {
KvPair pair = pairs.get(i);
KeyInfo keyInfo = anyKey.getAny(i);
if (!delete(context, pair, keyInfo)) {
allOk = false;
}
}
return allOk;
}
use of doitincloud.rdbcache.models.KvPair 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;
}
Aggregations