-
Notifications
You must be signed in to change notification settings - Fork 692
Spanner expose databaseId provider bean #1530
Conversation
* | ||
* @since 1.2 | ||
*/ | ||
public interface DatabaseUtilityProvider<T> { |
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.
This looks identical to java.util.function.Supplier
except for the name. Why not just use Supplier
in its place?
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.
Yea I actually prefer using those general "functional" classes. Will change.
docs/src/main/asciidoc/spanner.adoc
Outdated
[source,java] | ||
---- | ||
@Bean | ||
public DatabaseUtilityProvider<DatabaseId> databaseIdProvider() { |
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 thought we discussed and agreed on using something like DatabaseClientProvider
. It's more flexible in a sense that it allows the app to connect to Spanner instances even in different projects.
You can always implement a DatabaseClientProvider
that works with DatabaseId
.
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.
@meltsufin , so there is a provider bean for DatabaseClient exposed. However the way DatabaseClients receive their instance/database/project id is via the DatabaseId class. furthermore there is a DatabaseAdminClient that also uses the DatabaseId
so it made sense to also make a provider bean available for DatabaseId
(emphasizing that DatabaseClient provider bean is also exposed)
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.
Updated the refdoc to emphasize that a bean for Supplier of DatabaseClient is also available and an option to set.
Speaking of Suppliers, should we go back and remove CredentialProvider and ProjectIDProvider and just use Suppler of Credentials and Supplier of ProjectID ?
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.
Some more review.
* @param <U> the type of objects this provider bases its products on. | ||
* @author Chengyuan Zhao | ||
*/ | ||
public class CachingDatabaseUtilityProvider<T, U> implements Supplier<T> { |
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 this is too generic. The specificity of the name of the class does not reflect its function. What it does seems very generic and not specific to "Database".
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.
removed a type parameter, PTAL
*/ | ||
public SpannerDatabaseAdminTemplate(DatabaseAdminClient databaseAdminClient, | ||
DatabaseClient databaseClient, | ||
DatabaseId databaseId) { | ||
Supplier<DatabaseClient> databaseClientProvider, |
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.
Why would you need this, if you can compute it from the databaseIdProvider
?
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.
If the user had chosen to provide his own DatabaseClient supplier then that wouldn't be right (for example if he sets things that aren't in DatabaseId). Also if we just use the DAtabaseIdProvider we would need to create new instances of DatabaseClient in here (instead of using existing ones) and also have a Spanner.class on hand.
Codecov Report
@@ Coverage Diff @@
## master #1530 +/- ##
=========================================
Coverage ? 69.22%
Complexity ? 1633
=========================================
Files ? 238
Lines ? 6281
Branches ? 647
=========================================
Hits ? 4348
Misses ? 1648
Partials ? 285
Continue to review full report at Codecov.
|
Codecov Report
@@ Coverage Diff @@
## master #1530 +/- ##
=========================================
Coverage ? 69.22%
Complexity ? 1633
=========================================
Files ? 238
Lines ? 6281
Branches ? 647
=========================================
Hits ? 4348
Misses ? 1648
Partials ? 285
Continue to review full report at Codecov.
|
* @param <U> the type of objects this provider bases its products on. | ||
* @author Chengyuan Zhao | ||
*/ | ||
public class CachingDatabaseClientProvider<U> implements Supplier<DatabaseClient> { |
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 don't think there's much value in this U
type parameter either.
I would just call this class DatabaseIdBasedDatabaseClientProvider
and it doesn't need any generics at all. It just needs the DatabaseIdProvider
and a Spanner
instance.
Why does this class even need to be public?
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 don't think there's a reason to make it that restrictive. There's no reason U
can't be the Spanner
object in another use-case or a just a string specifying the instance ID.
I don't think we gain any simplification by being more restrictive here, actually.
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.
In that case, you might be better off going back to the most generic design as you had before, and just renaming this class to CachingSupplier<INPUT, OUTPUT> implements Supplier<OUTPUT>
.
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.
sounds good! changes made
...ava/org/springframework/cloud/gcp/data/spanner/core/ReadWriteTransactionSpannerTemplate.java
Outdated
Show resolved
Hide resolved
...ain/java/org/springframework/cloud/gcp/data/spanner/core/admin/CachingComposingSupplier.java
Show resolved
Hide resolved
* | ||
* @since 1.2 | ||
*/ | ||
public interface DatabaseIdProvider extends Supplier<DatabaseId> { |
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.
What was the reason for creating this wrapper around Supplier<DatabaseId>
? Is it better to just use Supplier<DatabaseId>
in the code?
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.
See a comment further up from Mike :P
...java/org/springframework/cloud/gcp/data/spanner/core/admin/SpannerDatabaseAdminTemplate.java
Show resolved
Hide resolved
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.
We probably should add an example or integration test for this feature.
@dmitry-s Done !! PTAL |
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.
Looks good!
related #1525
allows bean for Database ID provider to support multiple instances or databases