@Override public Boolean batchRemove(final List<String> ids, final String applicationName) { if (CollectionUtils.isEmpty(ids) || StringUtils.isBlank(applicationName)) { return Boolean.FALSE; } String keyPrefix = RepositoryPathUtils.buildRedisKeyPrefix(applicationName); final String[] keys = ids.stream() .map(id -> RepositoryPathUtils.buildRedisKey(keyPrefix, id)).toArray(String[]::new); jedisClient.del(keys); return Boolean.TRUE; }
@Override public int remove(final String id) { try { final String redisKey = RepositoryPathUtils.buildRedisKey(keyPrefix, id); return jedisClient.del(redisKey).intValue(); } catch (Exception e) { throw new HmilyRuntimeException(e); } }
@Override public Boolean updateRetry(final String id, final Integer retry, final String appName) { if (StringUtils.isBlank(id) || StringUtils.isBlank(appName) || Objects.isNull(retry)) { return Boolean.FALSE; } String keyPrefix = RepositoryPathUtils.buildRedisKeyPrefix(appName); final String key = RepositoryPathUtils.buildRedisKey(keyPrefix, id); final byte[] bytes = jedisClient.get(key.getBytes()); try { final CoordinatorRepositoryAdapter adapter = objectSerializer.deSerialize(bytes, CoordinatorRepositoryAdapter.class); adapter.setRetriedCount(retry); adapter.setLastTime(DateUtils.getDateYYYY()); jedisClient.set(key, objectSerializer.serialize(adapter)); return Boolean.TRUE; } catch (Exception e) { e.printStackTrace(); return Boolean.FALSE; } }
@Override public HmilyTransaction findById(final String id) { try { final String redisKey = RepositoryPathUtils.buildRedisKey(keyPrefix, id); byte[] contents = jedisClient.get(redisKey.getBytes()); return RepositoryConvertUtils.transformBean(contents, objectSerializer); } catch (Exception e) { return null; } }
@Override public int create(final HmilyTransaction hmilyTransaction) { try { final String redisKey = RepositoryPathUtils.buildRedisKey(keyPrefix, hmilyTransaction.getTransId()); jedisClient.set(redisKey, RepositoryConvertUtils.convert(hmilyTransaction, objectSerializer)); return ROWS; } catch (Exception e) { throw new HmilyRuntimeException(e); } }
@Override public int updateStatus(final String id, final Integer status) { try { final String redisKey = RepositoryPathUtils.buildRedisKey(keyPrefix, id); byte[] contents = jedisClient.get(redisKey.getBytes()); if (contents != null) { CoordinatorRepositoryAdapter adapter = objectSerializer.deSerialize(contents, CoordinatorRepositoryAdapter.class); adapter.setStatus(status); jedisClient.set(redisKey, objectSerializer.serialize(adapter)); } } catch (HmilyException e) { e.printStackTrace(); return FAIL_ROWS; } return ROWS; }
@Override public int updateParticipant(final HmilyTransaction hmilyTransaction) { try { final String redisKey = RepositoryPathUtils.buildRedisKey(keyPrefix, hmilyTransaction.getTransId()); byte[] contents = jedisClient.get(redisKey.getBytes()); CoordinatorRepositoryAdapter adapter = objectSerializer.deSerialize(contents, CoordinatorRepositoryAdapter.class); adapter.setContents(objectSerializer.serialize(hmilyTransaction.getHmilyParticipants())); jedisClient.set(redisKey, objectSerializer.serialize(adapter)); } catch (HmilyException e) { e.printStackTrace(); return FAIL_ROWS; } return ROWS; }
@Override public int update(final HmilyTransaction hmilyTransaction) throws HmilyRuntimeException { try { final String redisKey = RepositoryPathUtils.buildRedisKey(keyPrefix, hmilyTransaction.getTransId()); hmilyTransaction.setVersion(hmilyTransaction.getVersion() + 1); hmilyTransaction.setLastTime(new Date()); hmilyTransaction.setRetriedCount(hmilyTransaction.getRetriedCount() + 1); jedisClient.set(redisKey, RepositoryConvertUtils.convert(hmilyTransaction, objectSerializer)); return ROWS; } catch (Exception e) { throw new HmilyRuntimeException(e); } }