Skip to content
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

implement ConnectionProvider #8

Merged
merged 42 commits into from
Nov 14, 2024
Merged

implement ConnectionProvider #8

merged 42 commits into from
Nov 14, 2024

Conversation

NathanQingyangXu
Copy link
Contributor

@NathanQingyangXu NathanQingyangXu commented Oct 27, 2024

Copy link
Collaborator

@jyemin jyemin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

First round of feedback

Copy link
Collaborator

@jyemin jyemin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Round 2!

Copy link
Collaborator

@jyemin jyemin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looking good. Minor change request.


package com.mongodb.hibernate.jdbc;

import static org.hibernate.cfg.JdbcSettings.*;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Duplicate of #8 (comment): let's not use * imports.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

solved. Palantir won't complain so I think it is minor.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The more I learn about Palantir, the more inferior it seems to SpotBugs:

  • it's not configurable, so we can't enforce classes being final by default, for example;
  • it does not consider obviously bad practices like * imports to be bad (they may cause unnecessary name conflicts, and much worse, they may result in new name conflicts when upgrading dependencies, even when no code changes were made).

I wonder why was it chosen over SpotBugs.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Isn't Palantir just a formatter, more akin to Checkstyle than SpotBugs?

ErrorProne is the thing that is closer to Spotbugs, and I believe it is extensible.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am just judging based on what Nathan communicated at a catchup meeting: we can't configure the linter, at least, not nearly as flexibly as SpotBugs. If it is not Palantir but ErrorProne who does the checking, then my comment was about it.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I didn't quite know much about linter so my remarks in the meeting might be wrong.
I think Palantir belongs to Spotless ecosystem. From its doc, since v7 (currently still in BETA), it does support something you desire: https://github.com/diffplug/spotless/tree/main/plugin-gradle#linting
Also, the decision to put @Nullable into the same line was from Spotless as well:
https://github.com/diffplug/spotless/tree/main/plugin-gradle#formatannotations

Comment on lines 134 to 139
var database = connectionString.getDatabase();
if (database == null) {
throw new HibernateException(String.format(
"Database must be provided in ConnectionString from configuration [%s] with value [%s]",
JAKARTA_JDBC_URL, jdbcUrl));
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

After thinking more about this requirement, I don't think it is justified: we won't use the database name unless JAKARTA_JDBC_USER is also specified. Let's remove the requirement.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

deleted, together with testing case

Copy link
Collaborator

@jyemin jyemin Nov 13, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not so sure about this. In the POC, MongoConnectionProvider uses the database name to create a MongoDatabase and passes it to the MongoConnection constructor. This MongoDatabase is used as a factory for MongoCollection. e.g.

    var collection =
        mongoDatabase.getCollection(command.getString("aggregate").getValue(), BsonDocument.class)

Note that the collection name comes from the command created by the MongoDialect, and it does not include the database name. AFAIK there is no way for the dialect to know about the database name.

But this might be an issue with trying to use JAKARTA_JDBC_USER, since there is no notion of an "auth source" like we have in MongoDB, where you can do

mongodb://user:pwd@localhost/mydb/?authSource=admin

And the authSource of admin applies to the credential while the database name of mydb is only relevant to the application (in this case our dialect) but the driver ignores it otherwise.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was discussing with @stIncMale about this. Seems we should retain the db verification logic for in most of cases, our local or evergreen testing simply requires a db, but no need to provide user or password.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As we discussed on slack, we do need database name to kick of JDBC flow

Copy link
Member

@stIncMale stIncMale Nov 14, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

... avoid using these SQL-specific terms to map to MongoDB counterparts (which has database alone), for it incurs bad product experience (we need nontrivial documentation to explain we are using catalog as synonym of database in MongoDB ...

We don't have a choice but to do such mapping, because the whole idea of the project is to allow applications to use Hibernate ORM. That means, applications will still use Hibernate ORM API and properties, and Jakarta EE API. Those, in turn, are based on the JDBC API, which uses the "catalog" and "schema" terms. We will, for example, have to implement DatabaseMetadata.getCatalogTerm, and it will return "database". We will also have to implement DatabaseMetadata.getSchemaTerm, and it will also return "database".

My only concern is cross-db entity references (like EntityA resides in db1 and its association entities resides in db2). How to support table joining across-db? But that seems an edge case.

Yes, that cannot be implemented. Given that MongoDB database is nothing but a namespace from the MQL perspective, the $lookup.from limitation "collection in the same database" is weird.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Guess you meant the following two methods from db metadata:

  • DatabaseMetadata#getCatalogTerm()
  • DatabaseMetadata#getSchemaTerm()

However, I tried to search for their usage and found Hibernate ORM never used them at all (Hibernate only used a very small subset of the metadata).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

got it. you meant our MongoDB metadata should set these terms with value of database, even though Hibernate doesn't care about it at all.

Copy link
Member

@stIncMale stIncMale Nov 14, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I created HIBERNATE-38 Design, implement and document how an application can configure the product and HIBERNATE-39 Support @Table.schema, which are meant to make the things discussed here actionable.

I also made HIBERNATE-28 provide MongoClientSettings customization approach dependent on HIBERNATE-38 Design, implement and document how an application can configure the product. Though, I see a way to make them independent, and given that you have already created the add programmatic Mongo client building customization PR, I'll propose that approach there.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Guess you meant the following two methods from db metadata:

Yes, thank you. I fixed the text: Connection -> DatabaseMetadata

stIncMale
stIncMale previously approved these changes Nov 14, 2024
@NathanQingyangXu NathanQingyangXu merged commit caf4001 into main Nov 14, 2024
2 checks passed
@NathanQingyangXu NathanQingyangXu deleted the HIBERNATE-27 branch November 14, 2024 20:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants