Skip to content

Commit adc92d4

Browse files
authored
feat: Add DerbyConnection::jdbc_connection_details_for_network_access helper (#1200)
* feat: Add DerbyConnection::jdbc_connection_details_with_host_part helper * docs * cargo update * changelog * Rename to jdbc_connection_details_for_network_access
1 parent bdcd118 commit adc92d4

3 files changed

Lines changed: 110 additions & 38 deletions

File tree

Cargo.lock

Lines changed: 59 additions & 30 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

crates/stackable-operator/CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,10 @@ All notable changes to this project will be documented in this file.
99
### Added
1010

1111
- Derive `strum::AsRefStr` for `ClientAuthenticationMethod` ([#1197]).
12+
- Add `DerbyConnection::jdbc_connection_details_for_network_access` helper ([#1200]).
1213

1314
[#1197]: https://github.com/stackabletech/operator-rs/pull/1197
15+
[#1200]: https://github.com/stackabletech/operator-rs/pull/1200
1416

1517
## [0.110.0] - 2026-04-10
1618

crates/stackable-operator/src/database_connections/databases/derby.rs

Lines changed: 49 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -49,14 +49,10 @@ impl JdbcDatabaseConnection for DerbyConnection {
4949
unique_database_name: &str,
5050
_templating_mechanism: &TemplatingMechanism,
5151
) -> Result<JdbcDatabaseConnectionDetails, crate::database_connections::Error> {
52-
let location = self.location.as_ref_or_else(|| {
53-
PathBuf::from(format!("/tmp/derby/{unique_database_name}/derby.db"))
54-
});
55-
let location = location.to_str().with_context(|| NonUtf8LocationSnafu {
56-
location: location.to_path_buf(),
57-
})?;
58-
let connection_url = format!("jdbc:derby:{location};create=true",);
59-
let connection_url = connection_url.parse().context(ParseConnectionUrlSnafu)?;
52+
let location = self.location(unique_database_name)?;
53+
let connection_url = format!("jdbc:derby:{location};create=true")
54+
.parse()
55+
.context(ParseConnectionUrlSnafu)?;
6056

6157
Ok(JdbcDatabaseConnectionDetails {
6258
driver: DERBY_JDBC_DRIVER_CLASS.to_owned(),
@@ -66,3 +62,48 @@ impl JdbcDatabaseConnection for DerbyConnection {
6662
})
6763
}
6864
}
65+
66+
impl DerbyConnection {
67+
/// Returns the JDBC connection URL in a format such as
68+
/// `jdbc:derby://localhost:1527//opt/var/druid_state/derby;create=true`.
69+
///
70+
/// E.g. according to the [Druid docs](https://druid.apache.org/docs/latest/design/metadata-storage/#derby)
71+
/// we should configure something like
72+
/// `jdbc:derby://localhost:1527//opt/var/druid_state/derby;create=true`.
73+
///
74+
/// Druid actually starts a Derby instance, which listens on `127.0.0.1:1527`. The schema seems
75+
/// to be the filesystem location.
76+
pub fn jdbc_connection_details_for_network_access(
77+
&self,
78+
unique_database_name: &str,
79+
host_part: &str,
80+
) -> Result<JdbcDatabaseConnectionDetails, crate::database_connections::Error> {
81+
let location = self.location(unique_database_name)?;
82+
let connection_url = format!("jdbc:derby://{host_part}/{location};create=true")
83+
.parse()
84+
.context(ParseConnectionUrlSnafu)?;
85+
86+
Ok(JdbcDatabaseConnectionDetails {
87+
driver: DERBY_JDBC_DRIVER_CLASS.to_owned(),
88+
connection_url,
89+
username_env: None,
90+
password_env: None,
91+
})
92+
}
93+
94+
/// Returns the configured [`Self::location`] or a sensible default value
95+
fn location(
96+
&self,
97+
unique_database_name: &str,
98+
) -> Result<String, crate::database_connections::Error> {
99+
let location = self.location.as_ref_or_else(|| {
100+
PathBuf::from(format!("/tmp/derby/{unique_database_name}/derby.db"))
101+
});
102+
Ok(location
103+
.to_str()
104+
.with_context(|| NonUtf8LocationSnafu {
105+
location: location.to_path_buf(),
106+
})?
107+
.to_owned())
108+
}
109+
}

0 commit comments

Comments
 (0)