From 8e5eb594dac31552c08d8df85ece100e6a7c7f2d Mon Sep 17 00:00:00 2001 From: Nathan Xu Date: Fri, 8 Nov 2024 21:38:44 -0500 Subject: [PATCH] update MongoConnectionProvider as per code review comments --- .../jdbc/MongoConnectionProvider.java | 39 ++++++++++++++----- 1 file changed, 30 insertions(+), 9 deletions(-) diff --git a/src/main/java/com/mongodb/hibernate/jdbc/MongoConnectionProvider.java b/src/main/java/com/mongodb/hibernate/jdbc/MongoConnectionProvider.java index 90b9c5d..83e569a 100644 --- a/src/main/java/com/mongodb/hibernate/jdbc/MongoConnectionProvider.java +++ b/src/main/java/com/mongodb/hibernate/jdbc/MongoConnectionProvider.java @@ -16,7 +16,9 @@ package com.mongodb.hibernate.jdbc; -import static org.hibernate.cfg.JdbcSettings.*; +import static org.hibernate.cfg.JdbcSettings.JAKARTA_JDBC_PASSWORD; +import static org.hibernate.cfg.JdbcSettings.JAKARTA_JDBC_URL; +import static org.hibernate.cfg.JdbcSettings.JAKARTA_JDBC_USER; import com.mongodb.ConnectionString; import com.mongodb.MongoClientSettings; @@ -42,12 +44,31 @@ *

{@link MongoConnectionProvider} uses the following Hibernate properties: * *

- * - *

{@value org.hibernate.cfg.JdbcSettings#JAKARTA_JDBC_URL} property is mandatory and it maps to MongoDB's + * as follows: + *

+ * + * + * + * + * + * + * + * + * + * + * + * + * + * + *
PropertyDescription
{@linkplain JdbcSettings#JAKARTA_JDBC_URL jakarta.persistence.jdbc.url}MongoDB + * connection string
{@linkplain JdbcSettings#JAKARTA_JDBC_USER jakarta.persistence.jdbc.user}{@code userName} for {@link com.mongodb.MongoCredential#createCredential(String, String, char[])}
{@linkplain JdbcSettings#JAKARTA_JDBC_PASSWORD jakarta.persistence.jdbc.password}{@code password} for {@link com.mongodb.MongoCredential#createCredential(String, String, char[])}
+ *

+ * {@value JdbcSettings#JAKARTA_JDBC_URL} property is mandatory and it maps to MongoDB's connection string, in which database name * must be provided to align with JDBC URL's convention. The other two JDBC properties are optional. * @@ -100,7 +121,7 @@ public void configure(Map configValues) { } if (!(jdbcUrl instanceof String)) { throw new HibernateException( - String.format("Configuration ('%s') value ('%s') not of string type", JAKARTA_JDBC_URL, jdbcUrl)); + String.format("Configuration [%s] value [%s] not of string type", JAKARTA_JDBC_URL, jdbcUrl)); } ConnectionString connectionString; try { @@ -108,14 +129,14 @@ public void configure(Map configValues) { } catch (RuntimeException e) { throw new HibernateException( String.format( - "Failed to create ConnectionString from configuration ('%s') with value ('%s')", + "Failed to create ConnectionString from configuration [%s] with value [%s]", JAKARTA_JDBC_URL, jdbcUrl), e); } var database = connectionString.getDatabase(); if (database == null) { throw new HibernateException(String.format( - "Database must be provided in ConnectionString from configuration ('%s') with value ('%s')", + "Database must be provided in ConnectionString from configuration [%s] with value [%s]", JAKARTA_JDBC_URL, jdbcUrl)); }