Skip to content

Commit d2588ae

Browse files
Merge pull request #24 from BugsGuru/release_25_2_1_sqle_gaussdb
Release 25 2 1 sqle gaussdb
2 parents 9f20bb1 + 7b2c2ec commit d2588ae

File tree

10 files changed

+230
-3
lines changed

10 files changed

+230
-3
lines changed

.gitignore

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,4 +47,7 @@ workspace-dev-ce/
4747
deploy/cloudbeaver
4848
server/**/target
4949
apps/**/target
50-
osgi-cache/
50+
osgi-cache/
51+
52+
web
53+
.idea

config/core/cloudbeaver.conf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
sslConfigurationPath:"${CLOUDBEAVER_SSL_CONF_PATH:workspace/.data/ssl-config.xml}",
1010

11-
rootURI: "${CLOUDBEAVER_ROOT_URI:/}",
11+
rootURI: "${CLOUDBEAVER_ROOT_URI:/sql_query}",
1212
serviceURI: "/api/",
1313
supportedHosts: [],
1414

deploy/scripts/clone-build-deps.sh

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,11 @@ echo "DBeaver branch: $DBEAVER_BRANCH"
2020
[ ! -d dbeaver-common ] && git clone --depth 1 -b "$DBEAVER_BRANCH" https://github.com/dbeaver/dbeaver-common.git
2121
[ ! -d dbeaver-jdbc-libsql ] && git clone --depth 1 -b "$DBEAVER_BRANCH" https://github.com/dbeaver/dbeaver-jdbc-libsql.git
2222

23-
# 对 dbeaver 打达梦驱动补丁
23+
chmod a+x $SCRIPT_DIR/*sh
24+
25+
# 对 dbeaver 打达梦、GaussDB 驱动补丁及 GaussDB 数据库列表补丁
2426
"$SCRIPT_DIR/patch-dbeaver-dameng.sh" "$(pwd)/dbeaver"
27+
"$SCRIPT_DIR/patch-dbeaver-gaussdb.sh" "$(pwd)/dbeaver"
28+
"$SCRIPT_DIR/patch-dbeaver-gaussdb-catalogs.sh" "$(pwd)/dbeaver"
2529

2630
echo "Clone and patch done. You can run build from cloudbeaver/deploy (e.g. ./build-backend.sh)."

deploy/scripts/launch-product.sh

100644100755
File mode changed.
Lines changed: 112 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,112 @@
1+
#!/bin/bash
2+
# 让 Generic 驱动下使用 PostgreSQL JDBC 的数据源(如 GaussDB)通过 pg_database 列出所有数据库,
3+
# 而不是仅显示当前连接的数据库。
4+
# 用法: 传入 dbeaver 根目录
5+
set -e
6+
7+
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
8+
if [ -n "$1" ]; then
9+
DBEAVER_ROOT="$1"
10+
else
11+
DBEAVER_ROOT="$(cd "$SCRIPT_DIR/../.." && pwd)/../dbeaver"
12+
fi
13+
14+
JAVA_FILE="${DBEAVER_ROOT}/plugins/org.jkiss.dbeaver.ext.generic/src/org/jkiss/dbeaver/ext/generic/model/GenericDataSource.java"
15+
if [ ! -f "$JAVA_FILE" ]; then
16+
echo "GenericDataSource.java not found: $JAVA_FILE"
17+
echo "Usage: $0 [dbeaver_root]"
18+
exit 1
19+
fi
20+
21+
if grep -q 'isPostgreSQLCompatible' "$JAVA_FILE"; then
22+
echo "GenericDataSource already patched for PostgreSQL/GaussDB catalogs, skip."
23+
exit 0
24+
fi
25+
26+
python3 - "$JAVA_FILE" << 'PY'
27+
import sys
28+
path = sys.argv[1]
29+
with open(path, "r", encoding="utf-8", errors="replace") as f:
30+
content = f.read()
31+
32+
# 在 getCatalogsNames 方法开头、 "final List<String> catalogNames = new ArrayList<>();" 之后
33+
# 插入 isPostgreSQLCompatible 方法和 PostgreSQL 分支;并把原 try 保留为 else 分支
34+
old_sig = """ public List<String> getCatalogsNames(
35+
@NotNull DBRProgressMonitor monitor,
36+
@NotNull JDBCDatabaseMetaData metaData,
37+
GenericMetaObject catalogObject,
38+
@Nullable DBSObjectFilter catalogFilters
39+
) throws DBException {
40+
final List<String> catalogNames = new ArrayList<>();
41+
try {
42+
try (JDBCResultSet dbResult = metaData.getCatalogs()) {"""
43+
44+
new_block = """ /**
45+
* True if this connection uses PostgreSQL JDBC (e.g. PostgreSQL, GaussDB, openGauss).
46+
* Such drivers report only the current database from getCatalogs(); we use pg_database to list all.
47+
*/
48+
private boolean isPostgreSQLCompatible() {
49+
String driverClass = getContainer().getDriver().getDriverClassName();
50+
if (driverClass != null && driverClass.contains("postgresql")) {
51+
return true;
52+
}
53+
String url = getContainer().getConnectionConfiguration().getUrl();
54+
return url != null && url.startsWith("jdbc:postgresql:");
55+
}
56+
57+
public List<String> getCatalogsNames(
58+
@NotNull DBRProgressMonitor monitor,
59+
@NotNull JDBCDatabaseMetaData metaData,
60+
GenericMetaObject catalogObject,
61+
@Nullable DBSObjectFilter catalogFilters
62+
) throws DBException {
63+
final List<String> catalogNames = new ArrayList<>();
64+
// PostgreSQL JDBC getCatalogs() returns only the current database; use pg_database for full list
65+
if (isPostgreSQLCompatible()) {
66+
String pgDatabaseSql = "SELECT datname FROM pg_catalog.pg_database WHERE NOT datistemplate AND datallowconn ORDER BY datname";
67+
try {
68+
try (JDBCSession session = DBUtils.openMetaSession(monitor, this, "Read database list")) {
69+
try (JDBCStatement stmt = session.createStatement()) {
70+
try (JDBCResultSet rs = stmt.executeQuery(pgDatabaseSql)) {
71+
while (rs.next()) {
72+
String name = JDBCUtils.safeGetStringTrimmed(rs, 1);
73+
if (CommonUtils.isNotEmpty(name)) {
74+
if (catalogFilters == null || catalogFilters.matches(name)) {
75+
catalogNames.add(name);
76+
monitor.subTask("Extract catalogs - " + name);
77+
} else {
78+
catalogsFiltered = true;
79+
}
80+
if (monitor.isCanceled()) {
81+
break;
82+
}
83+
}
84+
}
85+
}
86+
}
87+
}
88+
if (catalogNames.size() == 1 && omitSingleCatalog) {
89+
catalogNames.clear();
90+
}
91+
return catalogNames;
92+
} catch (SQLException e) {
93+
if (metaModel.isCatalogsOptional()) {
94+
log.warn("Can't read database list from pg_database", e);
95+
return catalogNames;
96+
}
97+
throw new DBException("Error reading database list", e);
98+
}
99+
}
100+
try {
101+
try (JDBCResultSet dbResult = metaData.getCatalogs()) {"""
102+
103+
if old_sig not in content:
104+
sys.exit("Could not find getCatalogsNames insertion point in GenericDataSource.java")
105+
content = content.replace(old_sig, new_block, 1)
106+
107+
with open(path, "w", encoding="utf-8") as f:
108+
f.write(content)
109+
print("Patched GenericDataSource.java: PostgreSQL/GaussDB full database list via pg_database.")
110+
PY
111+
112+
echo "Done."
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
#!/bin/bash
2+
# 在 DBeaver generic 插件中插入 GaussDB/openGauss ( gaussdb_jdbc ) 驱动定义
3+
# 用法: 传入 dbeaver 根目录,或从 cloudbeaver 仓库根目录的上一级执行
4+
set -e
5+
6+
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
7+
if [ -n "$1" ]; then
8+
DBEAVER_ROOT="$1"
9+
else
10+
DBEAVER_ROOT="$(cd "$SCRIPT_DIR/../.." && pwd)/../dbeaver"
11+
fi
12+
13+
PLUGIN_XML="${DBEAVER_ROOT}/plugins/org.jkiss.dbeaver.ext.generic/plugin.xml"
14+
if [ ! -f "$PLUGIN_XML" ]; then
15+
echo "DBeaver plugin.xml not found: $PLUGIN_XML"
16+
echo "Usage: $0 [dbeaver_root]"
17+
exit 1
18+
fi
19+
20+
if grep -q 'id="gaussdb_jdbc"' "$PLUGIN_XML"; then
21+
echo "GaussDB driver already present in DBeaver plugin.xml, skip patch."
22+
exit 0
23+
fi
24+
25+
python3 - "$PLUGIN_XML" << 'PY'
26+
import sys
27+
path = sys.argv[1]
28+
marker = "<!-- CUBRID -->"
29+
driver_block = ''' <driver
30+
id="gaussdb_jdbc"
31+
label="GaussDB / openGauss"
32+
class="org.postgresql.Driver"
33+
sampleURL="jdbc:postgresql://{host}[:{port}]/[{database}]"
34+
defaultPort="5432"
35+
defaultDatabase="postgres"
36+
defaultUser="gaussdb"
37+
description="华为 GaussDB / openGauss JDBC 驱动"
38+
supportedConfigurationTypes="MANUAL,URL"
39+
categories="sql">
40+
<file type="jar" path="drivers/gaussdb" bundle="drivers.gaussdb"/>
41+
</driver>
42+
43+
<!-- CUBRID -->'''
44+
45+
with open(path, "r", encoding="utf-8", errors="replace") as f:
46+
content = f.read()
47+
if marker not in content:
48+
sys.exit("Marker <!-- CUBRID --> not found in plugin.xml")
49+
new_content = content.replace(marker, driver_block, 1)
50+
with open(path, "w", encoding="utf-8") as f:
51+
f.write(new_content)
52+
print("Patched DBeaver plugin.xml: added gaussdb_jdbc driver.")
53+
PY
54+
55+
echo "Done."

server/bundles/io.cloudbeaver.resources.drivers.base/plugin.xml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
<resource name="drivers/kyuubi"/>
2323
<resource name="drivers/databend"/>
2424
<resource name="drivers/dameng"/>
25+
<resource name="drivers/gaussdb"/>
2526
</extension>
2627

2728
<!-- Bundles -->
@@ -46,6 +47,7 @@
4647
<bundle id="drivers.kyuubi" label="Apache Kyuubi drivers"/>
4748
<bundle id="drivers.databend" label="Databend drivers"/>
4849
<bundle id="drivers.dameng" label="达梦(DM) drivers"/>
50+
<bundle id="drivers.gaussdb" label="GaussDB/openGauss drivers"/>
4951
</extension>
5052

5153
<!-- Enabled drivers -->
@@ -71,6 +73,7 @@
7173
<driver id="generic:kyuubi_hive"/>
7274
<driver id="databend:databend"/>
7375
<driver id="generic:dameng_jdbc"/>
76+
<driver id="generic:gaussdb_jdbc"/>
7477
</extension>
7578

7679

1.03 MB
Binary file not shown.

server/drivers/gaussdb/pom.xml

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
<project xmlns="http://maven.apache.org/POM/4.0.0"
2+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
3+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
4+
<modelVersion>4.0.0</modelVersion>
5+
<artifactId>drivers.gaussdb</artifactId>
6+
<version>1.0.0</version>
7+
<parent>
8+
<groupId>io.cloudbeaver</groupId>
9+
<artifactId>drivers</artifactId>
10+
<version>1.0.0</version>
11+
<relativePath>../</relativePath>
12+
</parent>
13+
14+
<properties>
15+
<deps.output.dir>gaussdb</deps.output.dir>
16+
</properties>
17+
18+
<build>
19+
<plugins>
20+
<plugin>
21+
<groupId>org.apache.maven.plugins</groupId>
22+
<artifactId>maven-resources-plugin</artifactId>
23+
<version>2.6</version>
24+
<executions>
25+
<execution>
26+
<id>copy-gaussdb-jar</id>
27+
<phase>validate</phase>
28+
<configuration>
29+
<outputDirectory>../../../deploy/drivers/gaussdb</outputDirectory>
30+
<overwrite>true</overwrite>
31+
<resources>
32+
<resource>
33+
<directory>lib</directory>
34+
<includes>
35+
<include>*.jar</include>
36+
</includes>
37+
</resource>
38+
</resources>
39+
</configuration>
40+
<goals>
41+
<goal>copy-resources</goal>
42+
</goals>
43+
</execution>
44+
</executions>
45+
</plugin>
46+
</plugins>
47+
</build>
48+
49+
</project>

server/drivers/pom.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
<module>db2</module>
2323
<module>db2-jt400</module>
2424
<module>duckdb</module>
25+
<module>gaussdb</module>
2526
<module>h2</module>
2627
<module>h2_v2</module>
2728
<module>hive2</module>

0 commit comments

Comments
 (0)