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