@@ -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