public static void notNull(Object obj) { if (obj == null) { throw new TransactionRuntimeException("argument invalid,Please check"); } }
public static void checkConditionArgument(boolean condition, String message) { if (!condition) { throw new TransactionRuntimeException(message); } }
public static void notNull(Object obj, String message) { if (obj == null) { throw new TransactionRuntimeException(message); } }
public BlockTask getTask(final String key) { try { return LOADING_CACHE.get(key); } catch (ExecutionException e) { throw new TransactionRuntimeException(e.getCause()); } }
private void makeDir() { if (!initialized) { synchronized (FileTransactionRecoverRepository.class) { if (!initialized) { File rootPathFile = new File(filePath); if (!rootPathFile.exists()) { boolean result = rootPathFile.mkdir(); if (!result) { throw new TransactionRuntimeException("cannot create root path, the path to create is:" + filePath); } initialized = true; } else if (!rootPathFile.isDirectory()) { throw new TransactionRuntimeException("rootPath is not directory"); } } } } }
private int executeUpdate(final String sql, final Object... params) { try { try (Connection connection = dataSource.getConnection(); PreparedStatement ps = connection.prepareStatement(sql)) { if (params != null) { for (int i = 0; i < params.length; i++) { ps.setObject(i + 1, params[i]); } } return ps.executeUpdate(); } } catch (SQLException e) { LOGGER.error("executeUpdate->" + e.getMessage()); throw new TransactionRuntimeException(e); } }
private void start(final TxConfig txConfig) { if (!checkDataConfig(txConfig)) { throw new TransactionRuntimeException("please check you config!"); } txTransactionInitialize.init(txConfig); }
private void stop() { try { if (null != bossGroup) { bossGroup.shutdownGracefully().await(); } if (null != workerGroup) { workerGroup.shutdownGracefully().await(); } if (null != servletExecutor) { servletExecutor.shutdownGracefully().await(); } } catch (InterruptedException e) { throw new TransactionRuntimeException(" Netty Container stop interrupted", e); } }
@Override public void initialization(final TxConfig txConfig) { try { loadSpi(txConfig); nettyClientService.start(txConfig); txCompensationService.start(txConfig); } catch (Exception e) { throw new TransactionRuntimeException("tx transaction ex:{}:" + e.getMessage()); } new RaincatLogo().logo(); }
@Override public void init(final String appName, final TxConfig txConfig) { setRootPath(RepositoryPathUtils.buildZookeeperPath(appName)); try { connect(txConfig.getTxZookeeperConfig()); } catch (Exception e) { LogUtil.error(LOGGER, "zookeeper init exception please check you config:{}", e::getMessage); throw new TransactionRuntimeException(e.getMessage()); } }
@Override public int update(final TransactionRecover transactionRecover) throws TransactionRuntimeException { String sql = "update " + tableName + " set last_time = ?,version =version+ 1,retried_count =retried_count+1 where id = ? and version=? "; if (CompensationOperationTypeEnum.TASK_EXECUTE.getCode() == transactionRecover.getOperation()) { sql = "update " + tableName + " set last_time = ?,complete_flag = ? where id = ?"; executeUpdate(sql, new Date(), CommonConstant.TX_TRANSACTION_COMPLETE_FLAG_OK, transactionRecover.getId()); return ROWS; } int success = executeUpdate(sql, new Date(), transactionRecover.getId(), transactionRecover.getVersion()); if (success <= 0) { throw new TransactionRuntimeException(UPDATE_EX); } return success; }
@Override public Boolean updateRetry(final String id, final Integer retry, final String applicationName) { if (StringUtils.isBlank(id) || StringUtils.isBlank(applicationName) || Objects.isNull(retry)) { return Boolean.FALSE; } final String mongoTableName = RepositoryPathUtils.buildMongoTableName(applicationName); Query query = new Query(); query.addCriteria(new Criteria("transId").is(id)); Update update = new Update(); update.set("lastTime", DateUtils.getCurrentDateTime()); update.set("retriedCount", retry); final WriteResult writeResult = mongoTemplate.updateFirst(query, update, MongoAdapter.class, mongoTableName); if (writeResult.getN() <= 0) { throw new TransactionRuntimeException("更新数据异常!"); } return Boolean.TRUE; }
@Override public int update(final TransactionRecover transactionRecover) throws TransactionRuntimeException { if (CompensationOperationTypeEnum.TASK_EXECUTE.getCode() == transactionRecover.getOperation()) { TransactionRecover recover = findById(transactionRecover.getId()); recover.setCompleteFlag(CommonConstant.TX_TRANSACTION_COMPLETE_FLAG_OK); writeFile(recover); return ROWS; } transactionRecover.setLastTime(new Date()); transactionRecover.setVersion(transactionRecover.getVersion() + 1); transactionRecover.setRetriedCount(transactionRecover.getRetriedCount() + 1); try { writeFile(transactionRecover); } catch (Exception e) { throw new TransactionRuntimeException(UPDATE_EX); } return ROWS; }
throw new TransactionRuntimeException("TxManager connection ex!");
@Override public int update(final TransactionRecover transactionRecover) throws TransactionRuntimeException { try { final String redisKey = RedisHelper.buildRecoverKey(keyName, transactionRecover.getId()); if (CompensationOperationTypeEnum.TASK_EXECUTE.getCode() == transactionRecover.getOperation()) { TransactionRecover recover = findById(transactionRecover.getId()); recover.setCompleteFlag(CommonConstant.TX_TRANSACTION_COMPLETE_FLAG_OK); jedisClient.set(redisKey, TransactionRecoverUtils.convert(recover, objectSerializer)); return ROWS; } transactionRecover.setVersion(transactionRecover.getVersion() + 1); transactionRecover.setLastTime(new Date()); transactionRecover.setRetriedCount(transactionRecover.getRetriedCount() + 1); jedisClient.set(redisKey, TransactionRecoverUtils.convert(transactionRecover, objectSerializer)); return ROWS; } catch (Exception e) { throw new TransactionRuntimeException(e); } }
@Override public int update(final TransactionRecover transactionRecover) throws TransactionRuntimeException { Query query = new Query(); query.addCriteria(new Criteria("transId").is(transactionRecover.getId())); Update update = new Update(); if (CompensationOperationTypeEnum.TASK_EXECUTE.getCode() == transactionRecover.getOperation()) { update.set("completeFlag",CommonConstant.TX_TRANSACTION_COMPLETE_FLAG_OK); } else if (CompensationOperationTypeEnum.COMPENSATION.getCode() == transactionRecover.getOperation()) { update.set("lastTime", new Date()); update.set("retriedCount", transactionRecover.getRetriedCount() + 1); update.set("version", transactionRecover.getVersion() + 1); } final WriteResult writeResult = template.updateFirst(query, update, MongoAdapter.class, collectionName); if (writeResult.getN() <= 0) { throw new TransactionRuntimeException(UPDATE_EX); } return ROWS; }