diff --git a/nacos-datasource-plugin-ext/README.md b/nacos-datasource-plugin-ext/README.md index 9a9ede8..d494dd5 100644 --- a/nacos-datasource-plugin-ext/README.md +++ b/nacos-datasource-plugin-ext/README.md @@ -24,17 +24,45 @@ nacos-postgresql-datasource-plugin-ext工程可打包适配Postgresql的数据 ### 2.1、插件引入 -方式一:使用postgresql作为依赖引入到Nacos主分支源码中,例如: +- 方式一:使用postgresql作为依赖引入到Nacos主分支源码中,例如: ```xml - com.alibaba.nacos - nacos-postgresql-datasource-plugin-ext - 1.0.0-SNAPSHOT - + com.alibaba.nacos + nacos-postgresql-datasource-plugin-ext + 1.0.0-SNAPSHOT + ``` -方式二:下载当前插件项目源码,打包为jar包,将该文件的路径配置到startup.sh文件中,使用Nacos的loader.path机制指定该插件的路径,可修改startup.sh中的loader.path参数的位置进行指定。 +- 方式二:下载当前插件项目源码,打包为jar包 将该文件的路径配置到startup.sh文件中,使用Nacos的loader.path机制指定该插件的路径,可修改startup.sh中的loader.path参数的位置进行指定。 +- 默认情况下,startup.sh 脚本中已经指定了默认的插件路径 ${NACOS_HOME}/plugins +- 因此,可以将打包后的插件 jar 包放到此目录下 +- 最终形成的目录结构如下 + +```shell +bin + startup.sh +conf + application.properties +target + nacos-server.jar +plugins +``` + +- 因此,你要做的就是,将插件的 jar 包,以及包含依赖的 jar 包都放到 plugins 目录下即可 +- 本 fork 分支下,我们提供数据源插件的打包的 jar 包,但是,这个 jar 包是不包含数据库的 JDBC 驱动的 +- 因此,你除了将需要的数据源的 jar 包放到 plugins 目录下之外,还需要对应的 JDBC 的驱动 jar 包也放到下面去 + - 这样做的目的是为了将 JDBC 驱动进行解耦,以便于你可以选择自己更合适的 JDBC 驱动版本 + - 而不是插件里面直接合并的驱动版本 +- 以 postgre 为例,你需要这两个 jar 包 + +```shell +nacos-postgresql-datasource-plugin-ext-1.0.0-SNAPSHOT.jar +postgresql-42.2.19.jar +``` + +- 因此,只需要将这两个 jar 包放到 plugins 目录下即可 +- 然后就是更改 conf/application.properties 里面的配置为你的数据源即可 ### 2.2、修改数据库配置文件 diff --git a/nacos-datasource-plugin-ext/bash/.gitignore b/nacos-datasource-plugin-ext/bash/.gitignore new file mode 100644 index 0000000..d703923 --- /dev/null +++ b/nacos-datasource-plugin-ext/bash/.gitignore @@ -0,0 +1,2 @@ +backup +deploy diff --git a/nacos-datasource-plugin-ext/bash/collect.bat b/nacos-datasource-plugin-ext/bash/collect.bat new file mode 100644 index 0000000..3bbbd85 --- /dev/null +++ b/nacos-datasource-plugin-ext/bash/collect.bat @@ -0,0 +1,43 @@ +@echo off +echo collect begin ... + +set src_path=.. +set dst_path=.\deploy +set target_dir=target + +:: 脚本功能 +:: 将打包的结果收集到 deploy 目录中,并将原来的 deploy 目录移动到 backup 目录 +:: 也就是说,deploy 是最新的打包结果,backup 是上一次打包结果 + +mkdir %dst_path% +mkdir .\backup + +rd /q /s .\backup +move /Y %dst_path% .\backup + +rd /q /s %dst_path% +mkdir %dst_path% + +rd %src_path%\%target_dir% +for /F %%i in ('dir /S /B %src_path%\%target_dir%') do ( + + for /F %%j in ('dir /B %%i\*.jar') do ( + echo copy /B /Y %%i\%%j %dst_path%\ + copy /B /Y %%i\%%j %dst_path%\ + ) + for /F %%j in ('dir /B %%i\*.war') do ( + echo copy /B /Y %%i\%%j %dst_path%\ + copy /B /Y %%i\%%j %dst_path%\ + ) + for /F %%j in ('dir /B %%i\*.tar') do ( + echo copy /B /Y %%i\%%j %dst_path%\ + copy /B /Y %%i\%%j %dst_path%\ + ) + for /F %%j in ('dir /B %%i\*.gz') do ( + echo copy /B /Y %%i\%%j %dst_path%\ + copy /B /Y %%i\%%j %dst_path%\ + ) +) + + +echo collect done. diff --git a/nacos-datasource-plugin-ext/nacos-dm-datasource-plugin-ext/pom.xml b/nacos-datasource-plugin-ext/nacos-dm-datasource-plugin-ext/pom.xml index 5f16ef1..33bd1c7 100644 --- a/nacos-datasource-plugin-ext/nacos-dm-datasource-plugin-ext/pom.xml +++ b/nacos-datasource-plugin-ext/nacos-dm-datasource-plugin-ext/pom.xml @@ -17,6 +17,8 @@ 8.1.3.62 + + DmJdbcDriver18 @@ -24,6 +26,8 @@ com.dameng DmJdbcDriver18 ${jdbc.dm.version} + provided + true com.alibaba.nacos @@ -33,5 +37,12 @@ - + + + + org.apache.maven.plugins + maven-dependency-plugin + + + \ No newline at end of file diff --git a/nacos-datasource-plugin-ext/nacos-kingbase-datasource-plugin-ext/pom.xml b/nacos-datasource-plugin-ext/nacos-kingbase-datasource-plugin-ext/pom.xml index 734d592..3c1d941 100644 --- a/nacos-datasource-plugin-ext/nacos-kingbase-datasource-plugin-ext/pom.xml +++ b/nacos-datasource-plugin-ext/nacos-kingbase-datasource-plugin-ext/pom.xml @@ -16,6 +16,8 @@ 8 8 8.6.0 + + kingbase8 @@ -23,6 +25,8 @@ cn.com.kingbase kingbase8 8.6.0 + provided + true @@ -33,5 +37,12 @@ - + + + + org.apache.maven.plugins + maven-dependency-plugin + + + \ No newline at end of file diff --git a/nacos-datasource-plugin-ext/nacos-kingbase-datasource-plugin-ext/src/main/java/com/alibaba/nacos/plugin/datasource/dialect/KingbaseDatabaseDialect.java b/nacos-datasource-plugin-ext/nacos-kingbase-datasource-plugin-ext/src/main/java/com/alibaba/nacos/plugin/datasource/dialect/KingbaseDatabaseDialect.java index 06a0e20..7c510b0 100644 --- a/nacos-datasource-plugin-ext/nacos-kingbase-datasource-plugin-ext/src/main/java/com/alibaba/nacos/plugin/datasource/dialect/KingbaseDatabaseDialect.java +++ b/nacos-datasource-plugin-ext/nacos-kingbase-datasource-plugin-ext/src/main/java/com/alibaba/nacos/plugin/datasource/dialect/KingbaseDatabaseDialect.java @@ -1,6 +1,7 @@ package com.alibaba.nacos.plugin.datasource.dialect; import com.alibaba.nacos.plugin.datasource.constants.DatabaseTypeConstant; +import com.alibaba.nacos.plugin.datasource.enums.mysql.TrustedMysqlFunctionEnum; /** * kingbase database dialect. @@ -14,4 +15,9 @@ public class KingbaseDatabaseDialect extends AbstractDatabaseDialect { public String getType() { return DatabaseTypeConstant.KINGBASE; } + + @Override + public String getFunction(String functionName) { + return TrustedMysqlFunctionEnum.getFunctionByName(functionName); + } } diff --git a/nacos-datasource-plugin-ext/nacos-mssql-datasource-plugin-ext/pom.xml b/nacos-datasource-plugin-ext/nacos-mssql-datasource-plugin-ext/pom.xml index 2263512..c872eb4 100644 --- a/nacos-datasource-plugin-ext/nacos-mssql-datasource-plugin-ext/pom.xml +++ b/nacos-datasource-plugin-ext/nacos-mssql-datasource-plugin-ext/pom.xml @@ -15,6 +15,8 @@ 8 8 12.6.0.jre8 + + mssql-jdbc @@ -22,6 +24,8 @@ com.microsoft.sqlserver mssql-jdbc ${mssql-jdbc.version} + provided + true com.alibaba.nacos @@ -30,8 +34,15 @@ compile - - - + + + + + + org.apache.maven.plugins + maven-dependency-plugin + + + \ No newline at end of file diff --git a/nacos-datasource-plugin-ext/nacos-opengauss-datasource-plugin-ext/pom.xml b/nacos-datasource-plugin-ext/nacos-opengauss-datasource-plugin-ext/pom.xml index 75812d6..e7eb8a9 100644 --- a/nacos-datasource-plugin-ext/nacos-opengauss-datasource-plugin-ext/pom.xml +++ b/nacos-datasource-plugin-ext/nacos-opengauss-datasource-plugin-ext/pom.xml @@ -16,6 +16,8 @@ 8 8 42.2.19 + + opengauss-jdbc @@ -24,6 +26,8 @@ org.opengauss opengauss-jdbc 5.1.0-og + provided + true com.alibaba.nacos @@ -40,6 +44,10 @@ + + org.apache.maven.plugins + maven-dependency-plugin + org.apache.maven.plugins diff --git a/nacos-datasource-plugin-ext/nacos-opengauss-datasource-plugin-ext/src/main/java/com/alibaba/nacos/plugin/datasource/dialect/GaussdbDatabaseDialect.java b/nacos-datasource-plugin-ext/nacos-opengauss-datasource-plugin-ext/src/main/java/com/alibaba/nacos/plugin/datasource/dialect/GaussdbDatabaseDialect.java index a9ddcf5..e8fbae4 100644 --- a/nacos-datasource-plugin-ext/nacos-opengauss-datasource-plugin-ext/src/main/java/com/alibaba/nacos/plugin/datasource/dialect/GaussdbDatabaseDialect.java +++ b/nacos-datasource-plugin-ext/nacos-opengauss-datasource-plugin-ext/src/main/java/com/alibaba/nacos/plugin/datasource/dialect/GaussdbDatabaseDialect.java @@ -17,6 +17,7 @@ package com.alibaba.nacos.plugin.datasource.dialect; import com.alibaba.nacos.plugin.datasource.constants.DatabaseTypeConstant; +import com.alibaba.nacos.plugin.datasource.impl.enums.GaussdbFunctionEnum; /** * PostgreSQL database dialect. @@ -49,4 +50,9 @@ public String getLimitPageSqlWithOffset(String sql, int startOffset, int pageSiz return sql + " OFFSET " + startOffset + " LIMIT " + pageSize; } + @Override + public String getFunction(String functionName) { + return GaussdbFunctionEnum.getFunctionByName(functionName); + } + } diff --git a/nacos-datasource-plugin-ext/nacos-oracle-datasource-plugin-ext/pom.xml b/nacos-datasource-plugin-ext/nacos-oracle-datasource-plugin-ext/pom.xml index 5dba104..16c5cf1 100644 --- a/nacos-datasource-plugin-ext/nacos-oracle-datasource-plugin-ext/pom.xml +++ b/nacos-datasource-plugin-ext/nacos-oracle-datasource-plugin-ext/pom.xml @@ -15,6 +15,8 @@ 8 8 23.2.0.0 + + ojdbc8,orai18n @@ -22,6 +24,15 @@ com.oracle.database.jdbc ojdbc8 ${jdbc.oracle.version} + provided + true + + + com.oracle.database.nls + orai18n + ${jdbc.oracle.version} + provided + true com.alibaba.nacos @@ -30,5 +41,12 @@ compile - + + + + org.apache.maven.plugins + maven-dependency-plugin + + + \ No newline at end of file diff --git a/nacos-datasource-plugin-ext/nacos-postgresql-datasource-plugin-ext/pom.xml b/nacos-datasource-plugin-ext/nacos-postgresql-datasource-plugin-ext/pom.xml index 8f3aba7..2c4896d 100644 --- a/nacos-datasource-plugin-ext/nacos-postgresql-datasource-plugin-ext/pom.xml +++ b/nacos-datasource-plugin-ext/nacos-postgresql-datasource-plugin-ext/pom.xml @@ -15,6 +15,8 @@ 8 8 42.2.19 + + postgresql @@ -23,6 +25,8 @@ org.postgresql postgresql ${jdbc.postgresql.version} + provided + true com.alibaba.nacos @@ -31,8 +35,15 @@ compile - - - + + + + + + org.apache.maven.plugins + maven-dependency-plugin + + + \ No newline at end of file diff --git a/pom.xml b/pom.xml index 28d3dc2..f079075 100644 --- a/pom.xml +++ b/pom.xml @@ -1,21 +1,21 @@ + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> 4.0.0 - + com.alibaba.nacos nacos-plugin-ext pom ${revision} - + li-xiao-shuang 644968328@qq.com - + Apache License, Version 2.0 @@ -23,7 +23,7 @@ repo - + nacos-group https://github.com/nacos-group @@ -56,7 +56,7 @@ test - + @@ -85,7 +85,7 @@ ${alibaba-nacos.version} provided - + com.alibaba.nacos nacos-common @@ -101,8 +101,32 @@ - + + + + + org.apache.maven.plugins + maven-dependency-plugin + 3.1.2 + + + copy-lib + package + + copy-dependencies + + + + ${project.build.directory}/libs + + ${copy-lib.artifact-ids} + + + + + + @@ -120,7 +144,8 @@ - + @@ -142,7 +167,7 @@ - + org.codehaus.mojo