/** * set db type. * * @param dbType dbType */ public void setDbType(final String dbType) { this.dbType = DbTypeUtils.buildByDriverClassName(dbType); }
private String buildRootPath(final String id) { return RepositoryPathUtils.buildZookeeperRootPath(rootPathPrefix, id); } }
private void writeFile(final HmilyTransaction hmilyTransaction) { makeDir(); String fileName = RepositoryPathUtils.getFullFileName(filePath, hmilyTransaction.getTransId()); try { FileUtils.writeFile(fileName, RepositoryConvertUtils.convert(hmilyTransaction, serializer)); } catch (HmilyException e) { e.printStackTrace(); } }
@Override public Boolean updateRetry(final String id, final Integer retry, final String appName) { if (StringUtils.isBlank(id) || StringUtils.isBlank(appName) || Objects.isNull(retry)) { return false; } final String tableName = RepositoryPathUtils.buildDbTableName(appName); String sqlBuilder = String.format("update %s set retried_count = %d,last_time= '%s' where trans_id =%s", tableName, retry, DateUtils.getCurrentDateTime(), id); jdbcTemplate.execute(sqlBuilder); return Boolean.TRUE; }
public HmilyTransaction() { this.transId = IdWorkerUtils.getInstance().createUUID(); this.createTime = new Date(); this.lastTime = new Date(); hmilyParticipants = Lists.newCopyOnWriteArrayList(); }
@Override public void init(final String modelName, final HmilyConfig hmilyConfig) { keyPrefix = RepositoryPathUtils.buildRedisKeyPrefix(modelName); final HmilyRedisConfig hmilyRedisConfig = hmilyConfig.getHmilyRedisConfig(); try { buildJedisPool(hmilyRedisConfig); } catch (Exception e) { LogUtil.error(LOGGER, "redis init error please check you config:{}", e::getMessage); throw new HmilyRuntimeException(e); } }
@Override public void init(final String modelName, final HmilyConfig hmilyConfig) { rootPathPrefix = RepositoryPathUtils.buildZookeeperPathPrefix(modelName); try { connect(hmilyConfig.getHmilyZookeeperConfig()); } catch (Exception e) { LogUtil.error(LOGGER, "zookeeper init error please check you config:{}", e::getMessage); throw new HmilyRuntimeException(e.getMessage()); } }
@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 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 Boolean login(final String userName, final String password) { LogUtil.info(LOGGER, "输入的用户名密码为:{}", () -> userName + "," + password); if (userName.equals(this.userName) && password.equals(this.password)) { LOGIN_SUCCESS = true; return Boolean.TRUE; } return Boolean.FALSE; }
@Override public int remove(final String id) { String fullFileName = RepositoryPathUtils.getFullFileName(filePath, id); File file = new File(fullFileName); if (file.exists()) { file.delete(); } return ROWS; }
@Override public void init(final String modelName, final HmilyConfig hmilyConfig) { filePath = RepositoryPathUtils.buildFilePath(modelName); File file = new File(filePath); if (!file.exists()) { file.getParentFile().mkdirs(); file.mkdirs(); } }
/** * acquire spring bean. * * @param type type * @param <T> class * @return bean */ public <T> T getBean(final Class<T> type) { AssertUtils.notNull(type); return cfgContext.getBean(type); }
/** * Build part number string. * * @return the string */ public String buildPartNumber() { return String.valueOf(ID_WORKER_UTILS.nextId()); }
private String buildBannerText() { return CommonConstant.LINE_SEPARATOR + CommonConstant.LINE_SEPARATOR + HMILY_LOGO + CommonConstant.LINE_SEPARATOR + " :: Hmily :: (v" + VersionUtils.getVersion(getClass(), "2.0.0") + ")" + CommonConstant.LINE_SEPARATOR; }
private HmilyTransaction readTransaction(final File file) throws Exception { try (FileInputStream fis = new FileInputStream(file)) { byte[] content = new byte[(int) file.length()]; fis.read(content); return RepositoryConvertUtils.transformBean(content, serializer); } }
@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); } }
/** * Create uuid string. * * @return the string */ public String createUUID() { return String.valueOf(ID_WORKER_UTILS.nextId()); }