diff --git a/README.md b/README.md index e197d27..0111461 100644 --- a/README.md +++ b/README.md @@ -17,6 +17,7 @@ Nacos 从 2.2.0 版本开始,可通过 SPI 机制注入多数据源实现插件, |---------------|-------| | 2.2.0 - 2.3.0 | 0.0.2 | | 2.3.1 - 2.3.2 | 0.0.3 | +| 2.4.0 - 2.4.1 | 0.0.4 | ```xml diff --git a/pom.xml b/pom.xml index 76042ef..40fb1dc 100644 --- a/pom.xml +++ b/pom.xml @@ -10,7 +10,7 @@ com.pig4cloud.plugin nacos-datasource-plugin-pg - 0.0.3 + 0.0.4 nacos-datasource-plugin-pg nacos-datasource-plugin-pg https://pig4cloud.com @@ -23,7 +23,7 @@ - 2.3.2 + 2.4.1 0.0.32 3.8.1 1.8 diff --git a/src/main/java/com/pig4cloud/plugin/impl/postgresql/PostgresqlAbstractMapper.java b/src/main/java/com/pig4cloud/plugin/impl/postgresql/PostgresqlAbstractMapper.java index 5fbfa84..30170f9 100644 --- a/src/main/java/com/pig4cloud/plugin/impl/postgresql/PostgresqlAbstractMapper.java +++ b/src/main/java/com/pig4cloud/plugin/impl/postgresql/PostgresqlAbstractMapper.java @@ -152,4 +152,14 @@ public String count(List where) { return sql.toString(); } + /** + * Get function by functionName. + * @param functionName functionName + * @return function + */ + @Override + public String getFunction(String functionName) { + return TrustedPgFunctionEnum.getFunctionByName(functionName); + } + } diff --git a/src/main/java/com/pig4cloud/plugin/impl/postgresql/TrustedPgFunctionEnum.java b/src/main/java/com/pig4cloud/plugin/impl/postgresql/TrustedPgFunctionEnum.java new file mode 100644 index 0000000..6cece35 --- /dev/null +++ b/src/main/java/com/pig4cloud/plugin/impl/postgresql/TrustedPgFunctionEnum.java @@ -0,0 +1,47 @@ +package com.pig4cloud.plugin.impl.postgresql; + +import java.util.HashMap; +import java.util.Map; + +/** + * @author lengleng + * @date 2024/8/25 + */ +public enum TrustedPgFunctionEnum { + + /** + * NOW(). + */ + NOW("NOW()", "NOW()"); + + private static final Map LOOKUP_MAP = new HashMap<>(); + + static { + for (TrustedPgFunctionEnum entry : TrustedPgFunctionEnum.values()) { + LOOKUP_MAP.put(entry.functionName, entry); + } + } + + private final String functionName; + + private final String function; + + TrustedPgFunctionEnum(String functionName, String function) { + this.functionName = functionName; + this.function = function; + } + + /** + * Get the function name. + * @param functionName function name + * @return function + */ + public static String getFunctionByName(String functionName) { + TrustedPgFunctionEnum entry = LOOKUP_MAP.get(functionName); + if (entry != null) { + return entry.function; + } + throw new IllegalArgumentException(String.format("Invalid function name: %s", functionName)); + } + +}