Files
openidea/java/jdbc-bridge/build.py
T
Vladislav Kuzmin 450c78b90d feat(database): support custom JDBC driver profiles (#4331)
A Custom JDBC driver connects any database that ships a JDBC driver. Driver profiles (driver and dependency JARs, driver class detected from the JARs, URL template with {host}/{port}/{database}/{file} fields) are stored locally and shared by all projects; project files can't start a driver until the user approves the source. Queries run through a bundled Java 17 bridge (java/jdbc-bridge, reproducible from source) found with the existing JDK discovery. Options › Read-only calls Connection.setReadOnly(true) and the IDE rejects table edits; Cancel calls Statement.cancel() and keeps the session, with a three-second fallback that reconnects. Transactions, Explain Plan and grid edits are off for JDBC sources.

Co-authored-by: principalwater <67874880+principalwater@users.noreply.github.com>
2026-11-19 09:13:12 +08:00

33 lines
1.5 KiB
Python

"""Build the committed Java 17 JDBC bridge, or run its standalone protocol tests."""
import argparse
import os
from pathlib import Path
import subprocess
import tempfile
import zipfile
root = Path(__file__).resolve().parent
parser = argparse.ArgumentParser(description=__doc__)
parser.add_argument("--test", action="store_true")
parser.add_argument("--out", type=Path, help="output JAR (with --test: the fixture driver for JDBC_FIXTURE_JAR)")
args = parser.parse_args()
java_home = os.environ.get("JAVA_HOME")
def tool(name):
return str(Path(java_home) / "bin" / name) if java_home else name
with tempfile.TemporaryDirectory() as scratch:
classes = Path(scratch) / "classes"
classes.mkdir()
sources = sorted((root / "src").rglob("*.java"))
if args.test:
sources += sorted((root / "tests").glob("*.java"))
subprocess.run([tool("javac"), "--release", "17", "-encoding", "UTF-8", "-g:none",
"-d", classes, *sources], check=True)
if args.test:
subprocess.run([tool("java"), "-ea", "-cp", classes, "ai.openidea.jdbc.SelfTest"], check=True, timeout=45)
if not args.test or args.out:
with zipfile.ZipFile(args.out or root / "openidea-jdbc-bridge.jar", "w") as jar:
for path in sorted(classes.rglob("SelfTest*.class" if args.test else "*.class")):
entry = zipfile.ZipInfo(path.relative_to(classes).as_posix(), (2026, 1, 1, 0, 0, 0))
jar.writestr(entry, path.read_bytes(), compress_type=zipfile.ZIP_DEFLATED)