Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 34 additions & 6 deletions nacos-datasource-plugin-ext/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,17 +24,45 @@ nacos-postgresql-datasource-plugin-ext工程可打包适配Postgresql的数据

### 2.1、插件引入

方式一:使用postgresql作为依赖引入到Nacos主分支源码中,例如:
- 方式一:使用postgresql作为依赖引入到Nacos主分支源码中,例如:

```xml
<dependency>
<groupId>com.alibaba.nacos</groupId>
<artifactId>nacos-postgresql-datasource-plugin-ext</artifactId>
<version>1.0.0-SNAPSHOT</version>
</dependency>
<groupId>com.alibaba.nacos</groupId>
<artifactId>nacos-postgresql-datasource-plugin-ext</artifactId>
<version>1.0.0-SNAPSHOT</version>
</dependency>
```

方式二:下载当前插件项目源码,打包为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、修改数据库配置文件

Expand Down
2 changes: 2 additions & 0 deletions nacos-datasource-plugin-ext/bash/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
backup
deploy
43 changes: 43 additions & 0 deletions nacos-datasource-plugin-ext/bash/collect.bat
Original file line number Diff line number Diff line change
@@ -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
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

批处理脚本在移动目录前未检查目标目录是否存在。

🟡 Major | 🐞 Bugs

📋 问题详情

在执行move /Y %dst_path% .�ackup之前没有检查%dst_path%目录是否存在,如果该目录不存在,move命令会报错。应该先检查目录是否存在再执行移动操作。

💡 解决方案

在移动目录前添加条件判断以避免错误。

- move /Y %dst_path% .\backup
+ if exist %dst_path% move /Y %dst_path% .\backup

您的反馈对我们很重要!(建议右键在新标签页中打开以下链接)

有用意见👍无用意见👎错误意见❌


rd /q /s %dst_path%
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

批处理脚本中存在冗余的目录删除操作。

🟢 Minor | 🧹 Code Smells

📋 问题详情

脚本中第21行和第18行都执行了rd命令删除%dst_path%目录,这会造成不必要的重复操作,并且如果第一次删除失败,第二次也会失败。应该移除其中一次删除操作以提高脚本效率和清晰度。

💡 解决方案

移除第18行的冗余目录删除命令。

- 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.
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,17 @@
<!-- 驱动小版本不同时,可能会造成某些操作异常(读取超长CLOB,TEXT),
需要使用达梦安装目录下drivers/jdbc下的驱动 -->
<jdbc.dm.version>8.1.3.62</jdbc.dm.version> <!--8.1.2.79-->

<copy-lib.artifact-ids>DmJdbcDriver18</copy-lib.artifact-ids>
</properties>

<dependencies>
<dependency>
<groupId>com.dameng</groupId>
<artifactId>DmJdbcDriver18</artifactId>
<version>${jdbc.dm.version}</version>
<scope>provided</scope>
<optional>true</optional>
</dependency>
<dependency>
<groupId>com.alibaba.nacos</groupId>
Expand All @@ -33,5 +37,12 @@
</dependency>
</dependencies>


<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,17 @@
<maven.compiler.source>8</maven.compiler.source>
<maven.compiler.target>8</maven.compiler.target>
<jdbc.kingbase.version>8.6.0</jdbc.kingbase.version>

<copy-lib.artifact-ids>kingbase8</copy-lib.artifact-ids>
</properties>

<dependencies>
<dependency>
<groupId>cn.com.kingbase</groupId>
<artifactId>kingbase8</artifactId>
<version>8.6.0</version>
<scope>provided</scope>
<optional>true</optional>
</dependency>

<dependency>
Expand All @@ -33,5 +37,12 @@
</dependency>
</dependencies>


<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
Original file line number Diff line number Diff line change
@@ -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.
Expand All @@ -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);
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

应使用与Kingbase数据库相关的函数枚举类,而不是复用MySQL的函数枚举。

🟠 Critical | 🐞 Bugs

📋 问题详情

getFunction方法中直接调用了TrustedMysqlFunctionEnum.getFunctionByName(functionName),这是不合适的,因为Kingbase数据库可能不支持所有MySQL函数,或者有自己特定的函数实现。应该使用Kingbase专用的函数枚举类来提供正确的函数映射。

💡 解决方案

修改getFunction方法中的函数获取逻辑,使其使用Kingbase专用的函数枚举类。

- return TrustedMysqlFunctionEnum.getFunctionByName(functionName);
+ return KingbaseFunctionEnum.getFunctionByName(functionName);

您的反馈对我们很重要!(建议右键在新标签页中打开以下链接)

有用意见👍无用意见👎错误意见❌

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,17 @@
<maven.compiler.source>8</maven.compiler.source>
<maven.compiler.target>8</maven.compiler.target>
<mssql-jdbc.version>12.6.0.jre8</mssql-jdbc.version>

<copy-lib.artifact-ids>mssql-jdbc</copy-lib.artifact-ids>
</properties>

<dependencies>
<dependency>
<groupId>com.microsoft.sqlserver</groupId>
<artifactId>mssql-jdbc</artifactId>
<version>${mssql-jdbc.version}</version>
<scope>provided</scope>
<optional>true</optional>
</dependency>
<dependency>
<groupId>com.alibaba.nacos</groupId>
Expand All @@ -30,8 +34,15 @@
<scope>compile</scope>
</dependency>
</dependencies>





<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
</plugin>
</plugins>
</build>

</project>
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
<maven.compiler.source>8</maven.compiler.source>
<maven.compiler.target>8</maven.compiler.target>
<jdbc.postgresql.version>42.2.19</jdbc.postgresql.version>

<copy-lib.artifact-ids>opengauss-jdbc</copy-lib.artifact-ids>
</properties>


Expand All @@ -24,6 +26,8 @@
<groupId>org.opengauss</groupId>
<artifactId>opengauss-jdbc</artifactId>
<version>5.1.0-og</version>
<scope>provided</scope>
<optional>true</optional>
</dependency>
<dependency>
<groupId>com.alibaba.nacos</groupId>
Expand All @@ -40,6 +44,10 @@

<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
</plugin>
<!--Packaging plug-in-->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

类注释描述不准确,应更新为反映实际数据库类型。

🟢 Minor | 🧹 Code Smells

📋 问题详情

该类的注释仍然标注为'PostgreSQL database dialect',但实际上它用于GaussDB/OpenGauss数据库。这种误导性的注释可能导致开发者对数据库方言的理解产生混淆。

💡 解决方案

更新类注释以准确反映其用途。

-  * PostgreSQL database dialect.
+  * GaussDB/OpenGauss database dialect.

您的反馈对我们很重要!(建议右键在新标签页中打开以下链接)

有用意见👍无用意见👎错误意见❌


/**
* PostgreSQL database dialect.
Expand Down Expand Up @@ -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);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,24 @@
<maven.compiler.source>8</maven.compiler.source>
<maven.compiler.target>8</maven.compiler.target>
<jdbc.oracle.version>23.2.0.0</jdbc.oracle.version>

<copy-lib.artifact-ids>ojdbc8,orai18n</copy-lib.artifact-ids>
</properties>

<dependencies>
<dependency>
<groupId>com.oracle.database.jdbc</groupId>
<artifactId>ojdbc8</artifactId>
<version>${jdbc.oracle.version}</version>
<scope>provided</scope>
<optional>true</optional>
</dependency>
<dependency>
<groupId>com.oracle.database.nls</groupId>
<artifactId>orai18n</artifactId>
<version>${jdbc.oracle.version}</version>
<scope>provided</scope>
<optional>true</optional>
</dependency>
<dependency>
<groupId>com.alibaba.nacos</groupId>
Expand All @@ -30,5 +41,12 @@
<scope>compile</scope>
</dependency>
</dependencies>

<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
<maven.compiler.source>8</maven.compiler.source>
<maven.compiler.target>8</maven.compiler.target>
<jdbc.postgresql.version>42.2.19</jdbc.postgresql.version>

<copy-lib.artifact-ids>postgresql</copy-lib.artifact-ids>
</properties>


Expand All @@ -23,6 +25,8 @@
<groupId>org.postgresql</groupId>
<artifactId>postgresql</artifactId>
<version>${jdbc.postgresql.version}</version>
<scope>provided</scope>
<optional>true</optional>
</dependency>
<dependency>
<groupId>com.alibaba.nacos</groupId>
Expand All @@ -31,8 +35,15 @@
<scope>compile</scope>
</dependency>
</dependencies>





<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
</plugin>
</plugins>
</build>

</project>
Loading