-
Notifications
You must be signed in to change notification settings - Fork 14
Allow replacing the DocumentDBSchemaService #477
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: develop
Are you sure you want to change the base?
Changes from all commits
543b65a
c1281a5
94c65d9
ad1d4e5
a341734
7958a6d
196ab46
6aeab4a
87c4190
8db4f2b
78eac43
b7e4346
30bf479
c5899db
9a61559
e7998c8
42438a1
61640dd
3328ff5
0612175
bb115b9
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -20,11 +20,15 @@ | |
import org.checkerframework.checker.nullness.qual.Nullable; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
import software.amazon.documentdb.jdbc.metadata.DocumentDbMetadataService; | ||
import software.amazon.documentdb.jdbc.metadata.DocumentDbMetadataServiceImpl; | ||
|
||
import java.io.InputStream; | ||
import java.sql.Connection; | ||
import java.sql.DriverManager; | ||
import java.sql.SQLException; | ||
import java.util.Properties; | ||
import java.util.function.Supplier; | ||
|
||
import static software.amazon.documentdb.jdbc.DocumentDbConnectionProperties.DOCUMENT_DB_SCHEME; | ||
|
||
|
@@ -69,6 +73,23 @@ public class DocumentDbDriver extends software.amazon.documentdb.jdbc.common.Dri | |
new DocumentDbDriver().register(); | ||
} | ||
|
||
private final Supplier<DocumentDbMetadataService> metadataServiceProvider; | ||
|
||
/** | ||
* Constructs a new DocumentDbDriver and uses the default metadata service. | ||
*/ | ||
public DocumentDbDriver() { | ||
metadataServiceProvider = () -> new DocumentDbMetadataServiceImpl(); | ||
} | ||
|
||
/** | ||
* Constructs a new DocumentDbDriver with the provided metadata service. | ||
* @param metadataServiceProvider metadata service to use | ||
*/ | ||
public DocumentDbDriver(final Supplier<DocumentDbMetadataService> metadataServiceProvider) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @normanj-bitquill I'm assuming this will be the entry point to override the schema service for a future local file implementation. Correct? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @birschick-bq That is correct. The goal is to supply my own implementation of the DocumentDbMetadataService that will be used for all connections made using the driver. |
||
this.metadataServiceProvider = metadataServiceProvider; | ||
} | ||
|
||
@SneakyThrows | ||
protected void register() { | ||
DriverManager.registerDriver(this); | ||
|
@@ -91,7 +112,11 @@ protected void register() { | |
throw new SQLException(exception.getMessage(), exception); | ||
} | ||
|
||
return new DocumentDbConnection(properties); | ||
final DocumentDbMetadataService metadataService = metadataServiceProvider.get(); | ||
if (metadataService == null) { | ||
throw new SQLException("Unable to retrieve the DocumentDbMetadataService"); | ||
} | ||
return new DocumentDbConnection(properties, metadataService); | ||
} | ||
|
||
/** | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we might have to check for nulls since the public interface from
DocumentDbDriver
might return anull
from theSupplier
.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would it be sufficient to add a not null check in the
DocumentDbDriver
constructor so that theDocumentDbMetadataService
is never null?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added a null check in
DocumentDbDriver
just before this constructor is called.