Skip to content
Merged
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
89 changes: 59 additions & 30 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions crates/stackable-operator/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,10 @@ All notable changes to this project will be documented in this file.
### Added

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

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

## [0.110.0] - 2026-04-10

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,14 +49,10 @@ impl JdbcDatabaseConnection for DerbyConnection {
unique_database_name: &str,
_templating_mechanism: &TemplatingMechanism,
) -> Result<JdbcDatabaseConnectionDetails, crate::database_connections::Error> {
let location = self.location.as_ref_or_else(|| {
PathBuf::from(format!("/tmp/derby/{unique_database_name}/derby.db"))
});
let location = location.to_str().with_context(|| NonUtf8LocationSnafu {
location: location.to_path_buf(),
})?;
let connection_url = format!("jdbc:derby:{location};create=true",);
let connection_url = connection_url.parse().context(ParseConnectionUrlSnafu)?;
let location = self.location(unique_database_name)?;
let connection_url = format!("jdbc:derby:{location};create=true")
.parse()
.context(ParseConnectionUrlSnafu)?;

Ok(JdbcDatabaseConnectionDetails {
driver: DERBY_JDBC_DRIVER_CLASS.to_owned(),
Expand All @@ -66,3 +62,48 @@ impl JdbcDatabaseConnection for DerbyConnection {
})
}
}

impl DerbyConnection {
/// Returns the JDBC connection URL in a format such as
/// `jdbc:derby://localhost:1527//opt/var/druid_state/derby;create=true`.
///
/// E.g. according to the [Druid docs](https://druid.apache.org/docs/latest/design/metadata-storage/#derby)
/// we should configure something like
/// `jdbc:derby://localhost:1527//opt/var/druid_state/derby;create=true`.
///
/// Druid actually starts a Derby instance, which listens on `127.0.0.1:1527`. The schema seems
/// to be the filesystem location.
pub fn jdbc_connection_details_for_network_access(
&self,
unique_database_name: &str,
host_part: &str,
) -> Result<JdbcDatabaseConnectionDetails, crate::database_connections::Error> {
let location = self.location(unique_database_name)?;
let connection_url = format!("jdbc:derby://{host_part}/{location};create=true")
.parse()
.context(ParseConnectionUrlSnafu)?;

Ok(JdbcDatabaseConnectionDetails {
driver: DERBY_JDBC_DRIVER_CLASS.to_owned(),
connection_url,
username_env: None,
password_env: None,
})
}

/// Returns the configured [`Self::location`] or a sensible default value
fn location(
&self,
unique_database_name: &str,
) -> Result<String, crate::database_connections::Error> {
let location = self.location.as_ref_or_else(|| {
PathBuf::from(format!("/tmp/derby/{unique_database_name}/derby.db"))
});
Ok(location
.to_str()
.with_context(|| NonUtf8LocationSnafu {
location: location.to_path_buf(),
})?
.to_owned())
}
}
Loading