use of com.terran4j.commons.util.error.BusinessException in project commons by terran4j.
the class JedisCacheService method getHashEntry.
@Override
public <T> T getHashEntry(String key, String entryKey, Class<T> clazz) throws BusinessException {
if (StringUtils.isBlank(key) || StringUtils.isBlank(entryKey) || clazz == null) {
throw new NullPointerException("请检查传入参数");
}
Gson g = new Gson();
T t = null;
String value = null;
synchronized (jedis) {
value = jedis.hget(key, entryKey);
}
if (!StringUtils.isBlank(value)) {
try {
t = g.fromJson(value, clazz);
} catch (JsonSyntaxException e) {
throw new BusinessException(CommonErrorCode.JSON_ERROR, e).put("methodName", "getHashEntry").put("key", key).put("clazz", clazz).put("value", value).setMessage("${methodName}方法, key=${key}, value=${value}, 解析json串失败: " + e.getMessage());
}
}
return t;
}
use of com.terran4j.commons.util.error.BusinessException in project commons by terran4j.
the class JedisCacheService method getHashMap.
@Override
public <T> Map<String, T> getHashMap(String key, Class<T> clazz) throws BusinessException {
if (StringUtils.isBlank(key) || clazz == null) {
throw new NullPointerException("请检查传入参数");
}
Gson g = new Gson();
Map<String, T> returnMap = new HashMap<String, T>();
Map<String, String> tmpMap = null;
synchronized (jedis) {
tmpMap = jedis.hgetAll(key);
}
if (tmpMap != null) {
for (Map.Entry<String, String> entry : tmpMap.entrySet()) {
try {
returnMap.put(entry.getKey(), g.fromJson(entry.getValue(), clazz));
} catch (JsonSyntaxException e) {
throw new BusinessException(CommonErrorCode.JSON_ERROR, e).put("methodName", "getHashMap").put("key", key).put("clazz", clazz).put("value", entry.getValue()).setMessage("${methodName}方法, key=${key}, value=${value}, 解析json串失败: " + e.getMessage());
}
}
}
return returnMap;
}
use of com.terran4j.commons.util.error.BusinessException in project commons by terran4j.
the class RedisTemplateCacheService method getHashEntry.
@Override
public <T> T getHashEntry(String key, String entryKey, Class<T> clazz) throws BusinessException {
if (StringUtils.isBlank(key)) {
throw new NullPointerException("key is blank");
}
if (StringUtils.isBlank(entryKey)) {
throw new NullPointerException("entryKey is blank");
}
if (clazz == null) {
throw new NullPointerException("clazz is null");
}
Gson g = new Gson();
T t = null;
String value = (String) redisTemplate.opsForHash().get(key, entryKey);
if (!StringUtils.isBlank(value)) {
try {
t = g.fromJson(value, clazz);
} catch (JsonSyntaxException e) {
throw new BusinessException(CommonErrorCode.JSON_ERROR, e).put("methodName", "getHashEntry").put("key", key).put("clazz", clazz).put("value", value).setMessage("${methodName}方法, key=${key}, value=${value}, 解析json串失败: " + e.getMessage());
}
}
return t;
}
use of com.terran4j.commons.util.error.BusinessException in project commons by terran4j.
the class DSynchronizedTest method testGetLockKey.
@Test
public void testGetLockKey() {
Method method = ReflectionUtils.findMethod(getClass(), "doSomething", int.class, int.class);
Assert.assertNotNull(method);
String keyEL = "#target.toKey()";
String key = null;
try {
key = DSynchronizedAspect.getLockKey(keyEL, this, method, new Object[] { 1, 2 });
Assert.assertEquals("1-2", key);
key = DSynchronizedAspect.getLockKey(keyEL, this, method, new Object[] { 3, 2 });
Assert.assertEquals("2-3", key);
} catch (BusinessException e) {
e.printStackTrace();
Assert.fail(e.getMessage());
}
}
use of com.terran4j.commons.util.error.BusinessException in project commons by terran4j.
the class DSynchronizedTest method testGetLockKeyWithArgs.
@Test
public void testGetLockKeyWithArgs() {
Method method = ReflectionUtils.findMethod(getClass(), "doSomething", int.class, int.class);
Assert.assertNotNull(method);
String keyEL = "#target.toKey(#a, #b)";
String key = null;
try {
key = DSynchronizedAspect.getLockKey(keyEL, this, method, new Object[] { 1, 2 });
Assert.assertEquals("1-2", key);
key = DSynchronizedAspect.getLockKey(keyEL, this, method, new Object[] { 3, 2 });
Assert.assertEquals("2-3", key);
} catch (BusinessException e) {
e.printStackTrace();
Assert.fail(e.getMessage());
}
}
Aggregations