Skip to content

Commit

Permalink
round #2 code review comments
Browse files Browse the repository at this point in the history
  • Loading branch information
NathanQingyangXu committed Nov 4, 2024
1 parent b816075 commit e151069
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 27 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,18 @@
*/
public class NotYetImplementedException extends RuntimeException {

/**
* Default constructor.
*
* @deprecated use {@link NotYetImplementedException(String)} instead.
*/
public NotYetImplementedException() {}

/**
* Constructor with message parameter.
*
* @param message explanation on when the feature is to be implemented
*/
public NotYetImplementedException(String message) {
super(message);
}
Expand Down
8 changes: 4 additions & 4 deletions src/main/java/com/mongodb/hibernate/dialect/MongoDialect.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,17 +21,17 @@
import org.hibernate.engine.jdbc.dialect.spi.DialectResolutionInfo;

/**
* A MongoDB {@linkplain Dialect dialect} for version 6.0 and above.
* A MongoDB {@linkplain Dialect dialect}.
*
* <p>Usually Hibernate dialect represents some SQL RDBMS and speaks SQL with vendor-specific difference. MongoDB is a
* document NoSQL DB and speaks <i>MQL</i> (<b>M</b>ongoDB <b>Q</b>uery <b>L</b>anguage) in JSON format, but it is still possible to integrate with Hibernate seamlessly by
* creating a JDBC adaptor on top of MongoDB's Java client library.
* document DB and speaks <i>MQL</i> (MongoDB Query Language) in JSON format, but it is still possible to integrate with
* Hibernate seamlessly by creating a JDBC adaptor on top of MongoDB's Java client library.
*
* <p>Some MongoDB-specific customization examples include:
*
* <ul>
* <li>MQL translation extension point
* <li>SQL {@linkplain java.sql.Types#ARRAY Array} and {@linkplain java.sql.Types#STRUCT Struct} extension points to
* <li>SQL {@linkplain java.sql.Types#ARRAY ARRAY} and {@linkplain java.sql.Types#STRUCT STRUCT} extension points to
* support MongoDB's embedding array and document
* <li>MQL parameterization customization
* </ul>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,31 +16,27 @@

package com.mongodb.hibernate.jdbc;

import static org.hibernate.cfg.JdbcSettings.*;
import static org.hibernate.cfg.JdbcSettings.JAKARTA_JDBC_URL;

import com.mongodb.ConnectionString;
import com.mongodb.MongoClientSettings;
import com.mongodb.MongoCredential;
import com.mongodb.client.MongoClient;
import com.mongodb.client.MongoClients;
import com.mongodb.hibernate.NotYetImplementedException;
import com.mongodb.hibernate.cfg.ConfigurationException;
import com.mongodb.hibernate.cfg.ConfigurationHelper;
import java.sql.Connection;
import java.util.Map;
import org.hibernate.cfg.JdbcSettings;
import org.hibernate.engine.jdbc.connections.spi.ConnectionProvider;
import org.hibernate.service.UnknownUnwrapTypeException;
import org.hibernate.service.spi.Configurable;
import org.hibernate.service.spi.Stoppable;
import org.jspecify.annotations.Nullable;

/**
* MongoDB dialect's customized JDBC {@link ConnectionProvider} SPI implementation, whose class name is supposed to be
* provided as the following Hibernate property to kick off MongoDB dialect's JDBC flow:
*
* <ul>
* <li>{@linkplain org.hibernate.cfg.JdbcSettings#CONNECTION_PROVIDER hibernate.connection.provider_class}
* </ul>
* MongoDB dialect's customized JDBC {@link ConnectionProvider} SPI implementation, whose class name could be provided
* using configuration property {@value org.hibernate.cfg.JdbcSettings#CONNECTION_PROVIDER}.
*
* <p>The following Hibernate JDBC properties will be relied upon by Hibernate's {@link Configurable} SPI mechanism:
*
Expand All @@ -50,26 +46,28 @@
* <li>{@linkplain org.hibernate.cfg.JdbcSettings#JAKARTA_JDBC_PASSWORD jakarta.persistence.jdbc.password}
* </ul>
*
* <p>{@linkplain org.hibernate.cfg.JdbcSettings#JAKARTA_JDBC_URL jakarta.persistence.jdbc.url} property is mandatory
* and it maps to MongoDB's <a href="https://www.mongodb.com/docs/manual/reference/connection-string/">connection
* string</a>, in which database name must be provided to align with JDBC URL's convention. The other two JDBC
* properties are optional.
* <p>{@value org.hibernate.cfg.JdbcSettings#JAKARTA_JDBC_URL} property is mandatory and it maps to MongoDB's <a
* href="https://www.mongodb.com/docs/manual/reference/connection-string/">connection string</a>, in which database name
* must be provided to align with JDBC URL's convention. The other two JDBC properties are optional.
*
* @see ConnectionProvider
* @see Configurable
* @see JdbcSettings#JAKARTA_JDBC_URL
* @see JdbcSettings#JAKARTA_JDBC_USER
* @see JdbcSettings#JAKARTA_JDBC_PASSWORD
*/
public class MongoConnectionProvider implements ConnectionProvider, Configurable, Stoppable {

private @Nullable MongoClient mongoClient;

@Override
public Connection getConnection() {
throw new NotYetImplementedException();
throw new NotYetImplementedException("to be implemented at https://jira.mongodb.org/browse/HIBERNATE-29");
}

@Override
public void closeConnection(Connection connection) {
throw new NotYetImplementedException();
throw new NotYetImplementedException("to be implemented at https://jira.mongodb.org/browse/HIBERNATE-29");
}

@Override
Expand Down Expand Up @@ -103,14 +101,6 @@ public void configure(Map<String, Object> configurationValues) {

var clientSettingsBuilder = MongoClientSettings.builder().applyConnectionString(connectionString);

var user = ConfigurationHelper.getOptionalConfiguration(configurationValues, JAKARTA_JDBC_USER);
if (user != null) {
var password = ConfigurationHelper.getOptionalConfiguration(configurationValues, JAKARTA_JDBC_PASSWORD);
var credential =
MongoCredential.createCredential(user, database, password == null ? null : password.toCharArray());
clientSettingsBuilder.credential(credential);
}

var clientSettings = clientSettingsBuilder.build();
this.mongoClient = MongoClients.create(clientSettings);
}
Expand Down
2 changes: 1 addition & 1 deletion src/test/resources/hibernate.properties
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
jakarta.persistence.jdbc.url=mongodb://localhost/test/?directConnection=false
jakarta.persistence.jdbc.url=mongodb://localhost/mongo-hibernate-test/?directConnection=false
hibernate.dialect=com.mongodb.hibernate.dialect.MongoDialect
hibernate.connection.provider_class=com.mongodb.hibernate.jdbc.MongoConnectionProvider

0 comments on commit e151069

Please sign in to comment.