@@ -49,14 +49,43 @@ 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 ) ?;
56+
57+ Ok ( JdbcDatabaseConnectionDetails {
58+ driver : DERBY_JDBC_DRIVER_CLASS . to_owned ( ) ,
59+ connection_url,
60+ username_env : None ,
61+ password_env : None ,
62+ } )
63+ }
64+ }
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+ ///
77+ /// As stackable-operator generates a (correct) URL in the form
78+ /// `jdbc:derby:/tmp/foo/bar.db;create=true`, this function converts it to
79+ /// `jdbc:derby://dummy-host-for-druid:1234/tmp/foo/bar.db;create=true`
80+ pub fn jdbc_connection_details_with_host_part (
81+ & self ,
82+ unique_database_name : & str ,
83+ host_part : & str ,
84+ ) -> Result < JdbcDatabaseConnectionDetails , crate :: database_connections:: Error > {
85+ let location = self . location ( unique_database_name) ?;
86+ let connection_url = format ! ( "jdbc:derby://{host_part}/{location};create=true" )
87+ . parse ( )
88+ . context ( ParseConnectionUrlSnafu ) ?;
6089
6190 Ok ( JdbcDatabaseConnectionDetails {
6291 driver : DERBY_JDBC_DRIVER_CLASS . to_owned ( ) ,
@@ -65,4 +94,20 @@ impl JdbcDatabaseConnection for DerbyConnection {
6594 password_env : None ,
6695 } )
6796 }
97+
98+ /// Returns the configured [`Self::location`] or a sensible default value
99+ fn location (
100+ & self ,
101+ unique_database_name : & str ,
102+ ) -> Result < String , crate :: database_connections:: Error > {
103+ let location = self . location . as_ref_or_else ( || {
104+ PathBuf :: from ( format ! ( "/tmp/derby/{unique_database_name}/derby.db" ) )
105+ } ) ;
106+ Ok ( location
107+ . to_str ( )
108+ . with_context ( || NonUtf8LocationSnafu {
109+ location : location. to_path_buf ( ) ,
110+ } ) ?
111+ . to_owned ( ) )
112+ }
68113}
0 commit comments