feat(h2): bundle multi-version JDBC drivers

This commit is contained in:
t8y2 committed 2026-08-20 17:41:22 +08:00
1 parent a6a76640e0
commit 345cd3f8b3
18 files changed
+1358 -113

No files matched your search

+14 -5
View File
@@ -36,8 +36,13 @@ const MONGODB_PROFILES: &[AgentDriverProfile] = &[AgentDriverProfile {
store_visible: false,
}];
const H2_PROFILES: &[AgentDriverProfile] =
&[AgentDriverProfile { profile: "h2-legacy", key: "h2-legacy", label: "H2 2.1 Legacy", store_visible: true }];
const H2_PROFILES: &[AgentDriverProfile] = &[
AgentDriverProfile { profile: "h2-legacy", key: "h2", label: "H2 2.1 Legacy", store_visible: false },
AgentDriverProfile { profile: "h2-v1", key: "h2", label: "H2 1.x", store_visible: false },
AgentDriverProfile { profile: "h2-v2", key: "h2", label: "H2 2.0–2.1", store_visible: false },
AgentDriverProfile { profile: "h2-v3", key: "h2", label: "H2 2.2+", store_visible: false },
AgentDriverProfile { profile: "h2-custom", key: "h2", label: "H2 Custom JAR", store_visible: false },
];
const EXTRA_AGENT_LABELS: &[(&str, &str)] = &[
("duckdb", "DuckDB"),
@@ -419,11 +424,15 @@ mod tests {
use super::*;
#[test]
fn h2_legacy_profile_uses_separate_agent() {
fn h2_profiles_share_the_same_agent() {
assert_eq!(agent_key(&DatabaseType::H2, None), Some("h2"));
assert_eq!(agent_key(&DatabaseType::H2, Some("h2")), Some("h2"));
assert_eq!(agent_key(&DatabaseType::H2, Some("h2-legacy")), Some("h2-legacy"));
assert!(driver_store_entries().any(|(key, label)| key == "h2-legacy" && label == "H2 2.1 Legacy"));
assert_eq!(agent_key(&DatabaseType::H2, Some("h2-legacy")), Some("h2"));
assert_eq!(agent_key(&DatabaseType::H2, Some("h2-v1")), Some("h2"));
assert_eq!(agent_key(&DatabaseType::H2, Some("h2-v2")), Some("h2"));
assert_eq!(agent_key(&DatabaseType::H2, Some("h2-v3")), Some("h2"));
assert_eq!(agent_key(&DatabaseType::H2, Some("h2-custom")), Some("h2"));
assert!(!driver_store_entries().any(|(key, _)| key == "h2-legacy"));
}
#[test]
+36 -4
View File
@@ -25,7 +25,7 @@ impl AgentSessionRole {
fn agent_jdbc_driver_class(config: &ConnectionConfig) -> &str {
let driver_class = config.jdbc_driver_class.as_deref().unwrap_or("");
if config.db_type == DatabaseType::H2
if (config.db_type == DatabaseType::H2 && !h2_uses_custom_driver(config))
|| (config.db_type == DatabaseType::SapHana && matches!(driver_class, "sap_hana" | "saphana"))
{
""
@@ -34,6 +34,19 @@ fn agent_jdbc_driver_class(config: &ConnectionConfig) -> &str {
}
}
fn agent_jdbc_driver_paths(config: &ConnectionConfig) -> &[String] {
if config.db_type == DatabaseType::H2 && !h2_uses_custom_driver(config) {
&[]
} else {
&config.jdbc_driver_paths
}
}
fn h2_uses_custom_driver(config: &ConnectionConfig) -> bool {
config.db_type == DatabaseType::H2
&& config.driver_profile.as_deref().is_some_and(|profile| profile.eq_ignore_ascii_case("h2-custom"))
}
pub fn agent_connect_params(
config: &ConnectionConfig,
host: &str,
@@ -113,7 +126,8 @@ pub fn agent_connect_params_with_role(
"gbase_server": config.gbase_server,
"informix_server": config.informix_server,
"jdbc_driver_class": agent_jdbc_driver_class(config),
"jdbc_driver_paths": &config.jdbc_driver_paths,
"jdbc_driver_paths": agent_jdbc_driver_paths(config),
"driver_profile": config.driver_profile.as_deref().unwrap_or(""),
"sessionRole": session_role.as_str(),
"database_type": config.db_type,
});
@@ -855,18 +869,36 @@ mod tests {
}
#[test]
fn h2_agent_connect_params_ignore_stale_driver_class() {
for driver_profile in [None, Some("h2-legacy")] {
fn h2_bundled_agent_connect_params_ignore_stale_custom_driver_config() {
for driver_profile in
[None, Some("h2"), Some("h2-auto"), Some("h2-legacy"), Some("h2-v1"), Some("h2-v2"), Some("h2-v3")]
{
let mut cfg = config(DatabaseType::H2, Some("test"));
cfg.driver_profile = driver_profile.map(str::to_string);
cfg.jdbc_driver_class = Some("h2_embedded".to_string());
cfg.jdbc_driver_paths = vec!["/tmp/stale-h2.jar".to_string()];
let params = agent_connect_params(&cfg, "127.0.0.1", 9092, "test").unwrap();
assert_eq!(params["jdbc_driver_class"], "");
assert_eq!(params["jdbc_driver_paths"], serde_json::json!([]));
}
}
#[test]
fn h2_custom_agent_connect_params_preserve_external_driver_config() {
let mut cfg = config(DatabaseType::H2, Some("test"));
cfg.driver_profile = Some("h2-custom".to_string());
cfg.jdbc_driver_class = Some("org.h2.Driver".to_string());
cfg.jdbc_driver_paths = vec!["/tmp/h2-custom.jar".to_string(), "/tmp/h2-helper.jar".to_string()];
let params = agent_connect_params(&cfg, "127.0.0.1", 9092, "test").unwrap();
assert_eq!(params["driver_profile"], "h2-custom");
assert_eq!(params["jdbc_driver_class"], "org.h2.Driver");
assert_eq!(params["jdbc_driver_paths"], serde_json::json!(["/tmp/h2-custom.jar", "/tmp/h2-helper.jar"]));
}
#[test]
fn vastbase_agent_url_defaults_to_postgres_database_when_empty() {
let cfg = config(DatabaseType::Vastbase, Some(""));