merge & reformat code

This commit is contained in:
jianghang.loujh
2024-03-08 11:58:46 +08:00
parent 6dffcc8573
commit 8ca900377a
3 changed files with 49 additions and 45 deletions

View File

@@ -28,9 +28,9 @@ import com.google.common.cache.LoadingCache;
public class Util { public class Util {
private static final Logger logger = LoggerFactory.getLogger(Util.class); private static final Logger logger = LoggerFactory.getLogger(Util.class);
public static final String AUTO_GENERATED_PREFIX = "AUTO_GENERATED_"; public static final String AUTO_GENERATED_PREFIX = "AUTO_GENERATED_";
/** /**
* 通过DS执行sql * 通过DS执行sql
@@ -165,39 +165,38 @@ public class Util {
public static ThreadPoolExecutor newFixedDaemonThreadPool(int nThreads, long keepAliveTime) { public static ThreadPoolExecutor newFixedDaemonThreadPool(int nThreads, long keepAliveTime) {
return new ThreadPoolExecutor(nThreads, return new ThreadPoolExecutor(nThreads,
nThreads, nThreads,
keepAliveTime, keepAliveTime,
TimeUnit.MILLISECONDS, TimeUnit.MILLISECONDS,
new SynchronousQueue<>(), new SynchronousQueue<>(),
DaemonThreadFactory.daemonThreadFactory, DaemonThreadFactory.daemonThreadFactory,
(r, exe) -> { (r, exe) -> {
if (!exe.isShutdown()) { if (!exe.isShutdown()) {
try { try {
exe.getQueue().put(r); exe.getQueue().put(r);
} catch (InterruptedException e) { } catch (InterruptedException e) {
// ignore // ignore
}
} }
} }
); });
} }
public static ThreadPoolExecutor newSingleDaemonThreadExecutor(long keepAliveTime) { public static ThreadPoolExecutor newSingleDaemonThreadExecutor(long keepAliveTime) {
return new ThreadPoolExecutor(1, return new ThreadPoolExecutor(1,
1, 1,
keepAliveTime, keepAliveTime,
TimeUnit.MILLISECONDS, TimeUnit.MILLISECONDS,
new SynchronousQueue<>(), new SynchronousQueue<>(),
DaemonThreadFactory.daemonThreadFactory, DaemonThreadFactory.daemonThreadFactory,
(r, exe) -> { (r, exe) -> {
if (!exe.isShutdown()) { if (!exe.isShutdown()) {
try { try {
exe.getQueue().put(r); exe.getQueue().put(r);
} catch (InterruptedException e) { } catch (InterruptedException e) {
// ignore // ignore
}
} }
}); }
});
} }
public final static String timeZone; // 当前时区 public final static String timeZone; // 当前时区
@@ -330,10 +329,11 @@ public class Util {
/** /**
* Check if the time string has millisecond or microsecond units * Check if the time string has millisecond or microsecond units
*
* @param timeStr time string * @param timeStr time string
* @return boolean * @return boolean
*/ */
public static boolean isAccuracyOverSecond(String timeStr){ public static boolean isAccuracyOverSecond(String timeStr) {
if (StringUtils.isEmpty(timeStr)) { if (StringUtils.isEmpty(timeStr)) {
return false; return false;
} }
@@ -341,13 +341,13 @@ public class Util {
return times.length > 1 && !times[times.length - 1].isEmpty(); return times.length > 1 && !times[times.length - 1].isEmpty();
} }
/** /**
* Check if the datetime string has microsecond or nanosecond units * Check if the datetime string has microsecond or nanosecond units
*
* @param datetimeStr datetime string * @param datetimeStr datetime string
* @return boolean * @return boolean
*/ */
public static boolean isAccuracyOverMillisecond(String datetimeStr){ public static boolean isAccuracyOverMillisecond(String datetimeStr) {
if (StringUtils.isEmpty(datetimeStr)) { if (StringUtils.isEmpty(datetimeStr)) {
return false; return false;
} }
@@ -355,10 +355,12 @@ public class Util {
return times.length > 1 && times[times.length - 1].length() > 3; return times.length > 1 && times[times.length - 1].length() > 3;
} }
/** /**
* MySQL has fractional seconds support for TIME, DATETIME, and TIMESTAMP values, with up to microseconds (6 digits) precision. * MySQL has fractional seconds support for TIME, DATETIME, and TIMESTAMP
* ISO-8601 standard format is with up to nanoseconds (9 digits) precision, which is sufficient for storing MySQL time-related data. * values, with up to microseconds (6 digits) precision. ISO-8601 standard
* format is with up to nanoseconds (9 digits) precision, which is sufficient
* for storing MySQL time-related data.
*
* @param datetimeStr datetime string * @param datetimeStr datetime string
* @return LocalDateTime * @return LocalDateTime
*/ */
@@ -368,9 +370,9 @@ public class Util {
} }
datetimeStr = datetimeStr.trim(); datetimeStr = datetimeStr.trim();
try { try {
//Replace SPACE in middle with `T` to comply with ISO-8601 standard format // Replace SPACE in middle with `T` to comply with ISO-8601 standard format
return LocalDateTime.parse(datetimeStr.replace(" ", "T")); return LocalDateTime.parse(datetimeStr.replace(" ", "T"));
}catch (Exception e){ } catch (Exception e) {
logger.error("Convert datetime string to ISOLocalDateTime fail:{}", datetimeStr, e); logger.error("Convert datetime string to ISOLocalDateTime fail:{}", datetimeStr, e);
} }
return null; return null;

View File

@@ -8,6 +8,7 @@ import java.util.Arrays;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Properties; import java.util.Properties;
import org.apache.commons.lang.StringUtils; import org.apache.commons.lang.StringUtils;
import org.springframework.boot.context.properties.bind.Bindable; import org.springframework.boot.context.properties.bind.Bindable;
import org.springframework.boot.context.properties.bind.Binder; import org.springframework.boot.context.properties.bind.Binder;
@@ -87,12 +88,12 @@ public class YamlUtils {
entry.setValue(((OriginTrackedValue) value).getValue()); entry.setValue(((OriginTrackedValue) value).getValue());
} }
} }
ConfigurationPropertySource sources = new MapConfigurationPropertySource(properties); ConfigurationPropertySource sources = new MapConfigurationPropertySource(properties);
PropertyPlaceholderHelper propertyPlaceholderHelper = new PropertyPlaceholderHelper("${", "}"); PropertyPlaceholderHelper propertyPlaceholderHelper = new PropertyPlaceholderHelper("${", "}");
Binder binder = new Binder(Arrays.asList(sources), value -> { Binder binder = new Binder(Arrays.asList(sources), value -> {
if (value instanceof String) { if (value instanceof String) {
return propertyPlaceholderHelper.replacePlaceholders((String)value, baseProperties); return propertyPlaceholderHelper.replacePlaceholders((String) value, baseProperties);
} }
return value; return value;
}); });

View File

@@ -1,12 +1,5 @@
package com.alibaba.otter.canal.client.adapter.rdb.support; package com.alibaba.otter.canal.client.adapter.rdb.support;
import com.alibaba.druid.DbType;
import com.alibaba.otter.canal.client.adapter.rdb.config.MappingConfig;
import com.alibaba.otter.canal.client.adapter.support.Util;
import org.apache.commons.lang.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.io.Reader; import java.io.Reader;
import java.io.StringReader; import java.io.StringReader;
import java.math.BigDecimal; import java.math.BigDecimal;
@@ -17,6 +10,14 @@ import java.util.Collection;
import java.util.LinkedHashMap; import java.util.LinkedHashMap;
import java.util.Map; import java.util.Map;
import org.apache.commons.lang.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.alibaba.druid.DbType;
import com.alibaba.otter.canal.client.adapter.rdb.config.MappingConfig;
import com.alibaba.otter.canal.client.adapter.support.Util;
public class SyncUtil { public class SyncUtil {
private static final Logger logger = LoggerFactory.getLogger(SyncUtil.class); private static final Logger logger = LoggerFactory.getLogger(SyncUtil.class);