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
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -47,4 +47,7 @@ workspace-dev-ce/
deploy/cloudbeaver
server/**/target
apps/**/target
osgi-cache/
osgi-cache/

web
.idea
6 changes: 5 additions & 1 deletion deploy/scripts/clone-build-deps.sh
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,11 @@ echo "DBeaver branch: $DBEAVER_BRANCH"
[ ! -d dbeaver-common ] && git clone --depth 1 -b "$DBEAVER_BRANCH" https://github.com/dbeaver/dbeaver-common.git
[ ! -d dbeaver-jdbc-libsql ] && git clone --depth 1 -b "$DBEAVER_BRANCH" https://github.com/dbeaver/dbeaver-jdbc-libsql.git

# 对 dbeaver 打达梦驱动补丁
chmod a+x $SCRIPT_DIR/*sh

# 对 dbeaver 打达梦、GaussDB 驱动补丁及 GaussDB 数据库列表补丁
"$SCRIPT_DIR/patch-dbeaver-dameng.sh" "$(pwd)/dbeaver"
"$SCRIPT_DIR/patch-dbeaver-gaussdb.sh" "$(pwd)/dbeaver"
"$SCRIPT_DIR/patch-dbeaver-gaussdb-catalogs.sh" "$(pwd)/dbeaver"

echo "Clone and patch done. You can run build from cloudbeaver/deploy (e.g. ./build-backend.sh)."
Empty file modified deploy/scripts/launch-product.sh
100644 → 100755
Empty file.
112 changes: 112 additions & 0 deletions deploy/scripts/patch-dbeaver-gaussdb-catalogs.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
#!/bin/bash
# 让 Generic 驱动下使用 PostgreSQL JDBC 的数据源(如 GaussDB)通过 pg_database 列出所有数据库,
# 而不是仅显示当前连接的数据库。
# 用法: 传入 dbeaver 根目录
set -e

SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
if [ -n "$1" ]; then
DBEAVER_ROOT="$1"
else
DBEAVER_ROOT="$(cd "$SCRIPT_DIR/../.." && pwd)/../dbeaver"
fi

JAVA_FILE="${DBEAVER_ROOT}/plugins/org.jkiss.dbeaver.ext.generic/src/org/jkiss/dbeaver/ext/generic/model/GenericDataSource.java"
if [ ! -f "$JAVA_FILE" ]; then
echo "GenericDataSource.java not found: $JAVA_FILE"
echo "Usage: $0 [dbeaver_root]"
exit 1
fi

if grep -q 'isPostgreSQLCompatible' "$JAVA_FILE"; then
echo "GenericDataSource already patched for PostgreSQL/GaussDB catalogs, skip."
exit 0
fi

python3 - "$JAVA_FILE" << 'PY'
import sys
path = sys.argv[1]
with open(path, "r", encoding="utf-8", errors="replace") as f:
content = f.read()

# 在 getCatalogsNames 方法开头、 "final List<String> catalogNames = new ArrayList<>();" 之后
# 插入 isPostgreSQLCompatible 方法和 PostgreSQL 分支;并把原 try 保留为 else 分支
old_sig = """ public List<String> getCatalogsNames(
@NotNull DBRProgressMonitor monitor,
@NotNull JDBCDatabaseMetaData metaData,
GenericMetaObject catalogObject,
@Nullable DBSObjectFilter catalogFilters
) throws DBException {
final List<String> catalogNames = new ArrayList<>();
try {
try (JDBCResultSet dbResult = metaData.getCatalogs()) {"""

new_block = """ /**
* True if this connection uses PostgreSQL JDBC (e.g. PostgreSQL, GaussDB, openGauss).
* Such drivers report only the current database from getCatalogs(); we use pg_database to list all.
*/
private boolean isPostgreSQLCompatible() {
String driverClass = getContainer().getDriver().getDriverClassName();
if (driverClass != null && driverClass.contains("postgresql")) {
return true;
}
String url = getContainer().getConnectionConfiguration().getUrl();
return url != null && url.startsWith("jdbc:postgresql:");
}

public List<String> getCatalogsNames(
@NotNull DBRProgressMonitor monitor,
@NotNull JDBCDatabaseMetaData metaData,
GenericMetaObject catalogObject,
@Nullable DBSObjectFilter catalogFilters
) throws DBException {
final List<String> catalogNames = new ArrayList<>();
// PostgreSQL JDBC getCatalogs() returns only the current database; use pg_database for full list
if (isPostgreSQLCompatible()) {
String pgDatabaseSql = "SELECT datname FROM pg_catalog.pg_database WHERE NOT datistemplate AND datallowconn ORDER BY datname";
try {
try (JDBCSession session = DBUtils.openMetaSession(monitor, this, "Read database list")) {
try (JDBCStatement stmt = session.createStatement()) {
try (JDBCResultSet rs = stmt.executeQuery(pgDatabaseSql)) {
while (rs.next()) {
String name = JDBCUtils.safeGetStringTrimmed(rs, 1);
if (CommonUtils.isNotEmpty(name)) {
if (catalogFilters == null || catalogFilters.matches(name)) {
catalogNames.add(name);
monitor.subTask("Extract catalogs - " + name);
} else {
catalogsFiltered = true;
}
if (monitor.isCanceled()) {
break;
}
}
}
}
}
}
if (catalogNames.size() == 1 && omitSingleCatalog) {
catalogNames.clear();
}
return catalogNames;
} catch (SQLException e) {
if (metaModel.isCatalogsOptional()) {
log.warn("Can't read database list from pg_database", e);
return catalogNames;
}
throw new DBException("Error reading database list", e);
}
}
try {
try (JDBCResultSet dbResult = metaData.getCatalogs()) {"""

if old_sig not in content:
sys.exit("Could not find getCatalogsNames insertion point in GenericDataSource.java")
content = content.replace(old_sig, new_block, 1)

with open(path, "w", encoding="utf-8") as f:
f.write(content)
print("Patched GenericDataSource.java: PostgreSQL/GaussDB full database list via pg_database.")
PY

echo "Done."
55 changes: 55 additions & 0 deletions deploy/scripts/patch-dbeaver-gaussdb.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
#!/bin/bash
# 在 DBeaver generic 插件中插入 GaussDB/openGauss ( gaussdb_jdbc ) 驱动定义
# 用法: 传入 dbeaver 根目录,或从 cloudbeaver 仓库根目录的上一级执行
set -e

SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
if [ -n "$1" ]; then
DBEAVER_ROOT="$1"
else
DBEAVER_ROOT="$(cd "$SCRIPT_DIR/../.." && pwd)/../dbeaver"
fi

PLUGIN_XML="${DBEAVER_ROOT}/plugins/org.jkiss.dbeaver.ext.generic/plugin.xml"
if [ ! -f "$PLUGIN_XML" ]; then
echo "DBeaver plugin.xml not found: $PLUGIN_XML"
echo "Usage: $0 [dbeaver_root]"
exit 1
fi

if grep -q 'id="gaussdb_jdbc"' "$PLUGIN_XML"; then
echo "GaussDB driver already present in DBeaver plugin.xml, skip patch."
exit 0
fi

python3 - "$PLUGIN_XML" << 'PY'
import sys
path = sys.argv[1]
marker = "<!-- CUBRID -->"
driver_block = ''' <driver
id="gaussdb_jdbc"
label="GaussDB / openGauss"
class="org.postgresql.Driver"
sampleURL="jdbc:postgresql://{host}[:{port}]/[{database}]"
defaultPort="5432"
defaultDatabase="postgres"
defaultUser="gaussdb"
description="华为 GaussDB / openGauss JDBC 驱动"
supportedConfigurationTypes="MANUAL,URL"
categories="sql">
<file type="jar" path="drivers/gaussdb" bundle="drivers.gaussdb"/>
</driver>

<!-- CUBRID -->'''

with open(path, "r", encoding="utf-8", errors="replace") as f:
content = f.read()
if marker not in content:
sys.exit("Marker <!-- CUBRID --> not found in plugin.xml")
new_content = content.replace(marker, driver_block, 1)
with open(path, "w", encoding="utf-8") as f:
f.write(new_content)
print("Patched DBeaver plugin.xml: added gaussdb_jdbc driver.")
PY

echo "Done."
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
<resource name="drivers/kyuubi"/>
<resource name="drivers/databend"/>
<resource name="drivers/dameng"/>
<resource name="drivers/gaussdb"/>
</extension>

<!-- Bundles -->
Expand All @@ -46,6 +47,7 @@
<bundle id="drivers.kyuubi" label="Apache Kyuubi drivers"/>
<bundle id="drivers.databend" label="Databend drivers"/>
<bundle id="drivers.dameng" label="达梦(DM) drivers"/>
<bundle id="drivers.gaussdb" label="GaussDB/openGauss drivers"/>
</extension>

<!-- Enabled drivers -->
Expand All @@ -71,6 +73,7 @@
<driver id="generic:kyuubi_hive"/>
<driver id="databend:databend"/>
<driver id="generic:dameng_jdbc"/>
<driver id="generic:gaussdb_jdbc"/>
</extension>


Expand Down
Binary file added server/drivers/gaussdb/lib/gsjdbc4-1.1.jar
Binary file not shown.
49 changes: 49 additions & 0 deletions server/drivers/gaussdb/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
<project xmlns="http://maven.apache.org/POM/4.0.0"
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">
<modelVersion>4.0.0</modelVersion>
<artifactId>drivers.gaussdb</artifactId>
<version>1.0.0</version>
<parent>
<groupId>io.cloudbeaver</groupId>
<artifactId>drivers</artifactId>
<version>1.0.0</version>
<relativePath>../</relativePath>
</parent>

<properties>
<deps.output.dir>gaussdb</deps.output.dir>
</properties>

<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-resources-plugin</artifactId>
<version>2.6</version>
<executions>
<execution>
<id>copy-gaussdb-jar</id>
<phase>validate</phase>
<configuration>
<outputDirectory>../../../deploy/drivers/gaussdb</outputDirectory>
<overwrite>true</overwrite>
<resources>
<resource>
<directory>lib</directory>
<includes>
<include>*.jar</include>
</includes>
</resource>
</resources>
</configuration>
<goals>
<goal>copy-resources</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>

</project>
1 change: 1 addition & 0 deletions server/drivers/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
<module>db2</module>
<module>db2-jt400</module>
<module>duckdb</module>
<module>gaussdb</module>
<module>h2</module>
<module>h2_v2</module>
<module>hive2</module>
Expand Down
Loading