Skip to content

Conversation

@NathanQingyangXu
Copy link
Contributor

@NathanQingyangXu NathanQingyangXu commented Jan 16, 2025

https://jira.mongodb.org/browse/HIBERNATE-13

Implementing java.sql.PreparedStataement is the last blocker to go about CRUD MQL translation (R or aggregate has to be postponed later as planned). We decided to use the { $undefined: true } as the MQL parameter placeholder (later PR will deal with how to generate it during MQL translation) as opposed to the standardized JDBC ? marker.

Both unit testing and a simple integration testing case are included.

setParameter(parameterIndex, BsonNull.VALUE);
}

private void setBsonDateTimeParameter(int parameterIndex, java.util.@Nullable Date date) throws SQLException {
Copy link
Contributor Author

@NathanQingyangXu NathanQingyangXu Jan 16, 2025

Choose a reason for hiding this comment

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

It is very weird that the following @Nullable is disallowed:

@Nullable java.util.Date date

No clue on jspecify doc.

@Override
public int executeUpdate() throws SQLException {
checkClosed();
return executeUpdate(command);
Copy link
Contributor Author

Choose a reason for hiding this comment

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

In POC (and in tech doc), we implemented by invoking parent class or MongoStatement's executeUpdate(String mql) but I think it is not the best for some reasons:

  • we need to parse mql again unnecessarily; passing command directly to a new protected method accepting a parsed command makes more sense
  • we had to solve the parameters in Statement class which should know nothing about PreparedStatement parameter concern; passing a command with all parameters resolved makes more sense

Copy link
Member

@stIncMale stIncMale left a comment

Choose a reason for hiding this comment

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

The last reviewed commit is 5c63de4.

Copy link
Member

@stIncMale stIncMale left a comment

Choose a reason for hiding this comment

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

The last reviewed commit is 17dd554.

@NathanQingyangXu
Copy link
Contributor Author

The last reviewed commit is 5c63de4.

Thanks. I'd learned to avoid the mistake of missing the middle 'hidden part' so I think I might well not rely on this manual marker any more, :).


private void checkParameterIndex(int parameterIndex) throws SQLException {
if (parameterValueSetters.isEmpty()) {
throw new SQLException("No parameter exists");
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 found an edge. case above. If the parameter list is empty, the below exception message would be invalid.

Copy link
Member

@stIncMale stIncMale left a comment

Choose a reason for hiding this comment

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

The last reviewed commit is 96692d6.

Copy link
Member

@stIncMale stIncMale left a comment

Choose a reason for hiding this comment

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

The last reviewed commit is 412f38f.

jyemin
jyemin previously approved these changes Jan 24, 2025
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.

I don't plan to review this further so LGTM-ing to allow merge when Valentin approves.

Copy link
Member

@stIncMale stIncMale left a comment

Choose a reason for hiding this comment

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

The last reviewed commit is 30004df.

There is only one unaddressed concern left.

Co-authored-by: Valentin Kovalenko <valentin.male.kovalenko@gmail.com>
@NathanQingyangXu
Copy link
Contributor Author

The last reviewed commit is 30004df.

There is only one unaddressed concern left.

I overlooked the comment regarding the removal of protected keyword in MongoStatement#checkClosed(). Now it seems all comments addressed?

Copy link
Member

@stIncMale stIncMale left a comment

Choose a reason for hiding this comment

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

The last reviewed commit is 038ec75.

@NathanQingyangXu NathanQingyangXu merged commit 193f25f into mongodb:main Jan 27, 2025
6 checks passed
@NathanQingyangXu NathanQingyangXu deleted the HIBERNATE-13-preparedStatement branch January 27, 2025 21:33
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