@Override public int updateBusinessActivityState(String businessActivityIds, BusinessActivityStatus businessActivityStatus) throws SQLException { String sql = "UPDATE tm_business_activity_log SET businessActivityStatus = ? " + "WHERE isDeleted = 0 and businessActivityId = ?"; try (PreparedStatement ptmt = dataSource.prepareStatement(sql)) { ptmt.setInt(1, businessActivityStatus.getCode()); ptmt.setString(2, businessActivityIds); int rsCount = ptmt.executeUpdate(); if (rsCount > 0) { return rsCount; } return 0; } catch (Exception e) { throw e; } }
public static void destroy() { for (HulkInterceptor interceptor : interceptors) { interceptor.destroy(); } datasource.destroy(); bam.destroy(); }
@Override public PreparedStatement prepareStatement(String sql) throws SQLException { SqlType sqlType = getSqlType(sql); if (sqlType == SqlType.SELECT || sqlType == SqlType.SELECT_FOR_UPDATE) { return readDataSources.get((int) Math.random() * readDataSources.size()) .getConnection().prepareStatement(sql); } else if (sqlType == SqlType.INSERT || sqlType == SqlType.UPDATE || sqlType == SqlType.DELETE) { return writeDataSources.get((int) Math.random() * writeDataSources.size()) .getConnection().prepareStatement(sql); } else { throw new SQLException("only select, insert, update, delete sql is supported"); } }
@Bean public HulkDataSource hulkDataSource() { List<DataSource> writeDataSources = new ArrayList<>(); List<DataSource> readDataSources = new ArrayList<>(); for (PoolProperties properties : properties.getLogMasters()) { DataSource writeDataSource = new DataSource(); writeDataSource.setPoolProperties(properties); writeDataSources.add(writeDataSource); } for (PoolProperties properties : properties.getLogSlaves()) { DataSource readDataSource = new DataSource(); readDataSource.setPoolProperties(properties); readDataSources.add(readDataSource); } return new SQLDataSource(writeDataSources, readDataSources); }
@Override public int remove(List<String> businessActivityIds) throws SQLException { String sql = "UPDATE tm_business_activity_log SET isDeleted = 1 " + "WHERE isDeleted = 0 and businessActivityId in (" + transListString(businessActivityIds) + ") "; try (PreparedStatement ptmt = dataSource.prepareStatement(sql)) { int index = 1; for (String businessActivityId : businessActivityIds) { ptmt.setString(index++, businessActivityId); } int rsCount = ptmt.executeUpdate(); if (rsCount > 0) { return rsCount; } return 0; } catch (Exception e) { throw e; } }
@Override public boolean writeEx(BusinessActivityException ex) throws SQLException { if (null == ex) { return false; } String sql = "REPLACE INTO tm_business_activity_exception_log(businessActivityId,exceptionContent) " + "VALUES (?, ?)"; try (PreparedStatement ptmt = dataSource.prepareStatement(sql)) { ptmt.setString(1, getBusinessActivityIdStr(ex.getId())); ptmt.setString(2, ex.getException()); if (ptmt.executeUpdate() > 0) { return true; } return false; } catch (Exception e) { throw e; } }
PreparedStatement ptmt = null; try { ptmt = dataSource.prepareStatement(sql); for (HulkContext ctx : ctxs) { if (ctx == null) {
"FROM tm_business_activity_log " + "WHERE isDeleted = 0 and businessActivityStatus in ('8', '9') and businessActivityId in (?)"; try (PreparedStatement ptmt = dataSource.prepareStatement(sql)) { String businessActivityIdStr = getBusinessActivityIdStr(businessActivityId); ptmt.setString(1, businessActivityIdStr);
"FROM tm_business_activity_log " + "WHERE isDeleted = 0 and businessActivityStatus in ('8', '9') limit ?"; try (PreparedStatement ptmt = dataSource.prepareStatement(sql)) { ptmt.setInt(1, size); ResultSet resultSet = ptmt.executeQuery();