Skip to content

Commit 2122ff1

Browse files
Improve code quality, documentation, and use modern Java practices
- Add null checks to DomaConfigBuilder methods with improved JavaDoc - Enhance exception handling in DomaAutoConfiguration with more descriptive messages - Convert DomaSpringBootSqlBuilderSettings to a Java 17 record - Update README with latest Doma version information - Update test to match new error message Co-Authored-By: [email protected] <[email protected]>
1 parent c04505e commit 2122ff1

File tree

6 files changed

+82
-39
lines changed

6 files changed

+82
-39
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ Spring Boot Support for [Doma](https://github.com/domaframework/doma)
2323
<dependency>
2424
<groupId>org.seasar.doma</groupId>
2525
<artifactId>doma-processor</artifactId>
26-
<version>3.6.0</version>
26+
<version>3.8.0</version>
2727
<optional>true</optional>
2828
</dependency>
2929
```

doma-spring-boot-autoconfigure/src/main/java/org/seasar/doma/boot/autoconfigure/DomaAutoConfiguration.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ public Dialect dialect(ObjectProvider<JdbcConnectionDetails> connectionDetailsPr
8585
JdbcConnectionDetails connectionDetails = connectionDetailsProvider.getIfAvailable();
8686
if (connectionDetails == null) {
8787
throw new BeanCreationException(
88-
"No connection details available. You will probably have to set 'doma.dialect' explicitly.");
88+
"No JdbcConnectionDetails available. Either configure a DataSource or explicitly set 'doma.dialect' property in your configuration.");
8989
}
9090
DatabaseDriver databaseDriver = DatabaseDriver.fromJdbcUrl(connectionDetails.getJdbcUrl());
9191
switch (databaseDriver) {

doma-spring-boot-autoconfigure/src/main/java/org/seasar/doma/boot/autoconfigure/DomaConfig.java

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,15 @@
77
import org.seasar.doma.jdbc.statistic.StatisticManager;
88

99
/**
10-
* {@link Config} implementation used in doma-spring-boot.
10+
* Implementation of {@link Config} used by the Doma Spring Boot integration.
11+
* <p>
12+
* This class encapsulates all configuration properties required by Doma,
13+
* such as {@link DataSource}, {@link Dialect}, and {@link JdbcLogger}.
14+
* <p>
15+
* The configuration is built using a builder pattern through {@link DomaConfigBuilder}.
1116
*
1217
* @author Toshiaki Maki
18+
* @see DomaConfigBuilder
1319
*/
1420
public class DomaConfig implements Config {
1521

doma-spring-boot-autoconfigure/src/main/java/org/seasar/doma/boot/autoconfigure/DomaConfigBuilder.java

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,8 +62,10 @@ public DataSource dataSource() {
6262
*
6363
* @param dataSource dataSource to use
6464
* @return chained builder
65+
* @throws NullPointerException if dataSource is null
6566
*/
6667
public DomaConfigBuilder dataSource(DataSource dataSource) {
68+
Objects.requireNonNull(dataSource, "dataSource must not be null");
6769
this.dataSource = new TransactionAwareDataSourceProxy(dataSource);
6870
return this;
6971
}
@@ -72,7 +74,15 @@ public Dialect dialect() {
7274
return dialect;
7375
}
7476

77+
/**
78+
* Set the Dialect.
79+
*
80+
* @param dialect the Dialect
81+
* @return this instance
82+
* @throws NullPointerException if dialect is null
83+
*/
7584
public DomaConfigBuilder dialect(Dialect dialect) {
85+
Objects.requireNonNull(dialect, "dialect must not be null");
7686
this.dialect = dialect;
7787
return this;
7888
}
@@ -81,7 +91,15 @@ public JdbcLogger jdbcLogger() {
8191
return jdbcLogger;
8292
}
8393

94+
/**
95+
* Set the JdbcLogger.
96+
*
97+
* @param jdbcLogger the JdbcLogger
98+
* @return this instance
99+
* @throws NullPointerException if jdbcLogger is null
100+
*/
84101
public DomaConfigBuilder jdbcLogger(JdbcLogger jdbcLogger) {
102+
Objects.requireNonNull(jdbcLogger, "jdbcLogger must not be null");
85103
this.jdbcLogger = jdbcLogger;
86104
return this;
87105
}
@@ -90,7 +108,15 @@ public SqlFileRepository sqlFileRepository() {
90108
return sqlFileRepository;
91109
}
92110

111+
/**
112+
* Set the SqlFileRepository.
113+
*
114+
* @param sqlFileRepository the SqlFileRepository
115+
* @return this instance
116+
* @throws NullPointerException if sqlFileRepository is null
117+
*/
93118
public DomaConfigBuilder sqlFileRepository(SqlFileRepository sqlFileRepository) {
119+
Objects.requireNonNull(sqlFileRepository, "sqlFileRepository must not be null");
94120
this.sqlFileRepository = sqlFileRepository;
95121
return this;
96122
}
@@ -146,7 +172,15 @@ public Naming naming() {
146172
return naming;
147173
}
148174

175+
/**
176+
* Set the Naming convention.
177+
*
178+
* @param naming the Naming convention
179+
* @return this instance
180+
* @throws NullPointerException if naming is null
181+
*/
149182
public DomaConfigBuilder naming(Naming naming) {
183+
Objects.requireNonNull(naming, "naming must not be null");
150184
this.naming = naming;
151185
return this;
152186
}
@@ -173,8 +207,16 @@ public EntityListenerProvider entityListenerProvider() {
173207
return entityListenerProvider;
174208
}
175209

210+
/**
211+
* Set the EntityListenerProvider.
212+
*
213+
* @param entityListenerProvider the EntityListenerProvider
214+
* @return this instance
215+
* @throws NullPointerException if entityListenerProvider is null
216+
*/
176217
public DomaConfigBuilder entityListenerProvider(
177218
EntityListenerProvider entityListenerProvider) {
219+
Objects.requireNonNull(entityListenerProvider, "entityListenerProvider must not be null");
178220
this.entityListenerProvider = entityListenerProvider;
179221
return this;
180222
}

doma-spring-boot-autoconfigure/src/test/java/org/seasar/doma/boot/autoconfigure/DomaAutoConfigurationTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -318,7 +318,7 @@ public void testDialectMissingJdbConnectionDetails() {
318318
BeanCreationException exception = assertThrows(BeanCreationException.class,
319319
() -> this.context.refresh());
320320
assertThat(exception.getMessage(), containsString(
321-
"No connection details available. You will probably have to set 'doma.dialect' explicitly."));
321+
"No JdbcConnectionDetails available. Either configure a DataSource or explicitly set 'doma.dialect' property in your configuration."));
322322
}
323323

324324
@Test

doma-spring-boot-core/src/main/java/org/seasar/doma/boot/DomaSpringBootSqlBuilderSettings.java

Lines changed: 30 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -4,39 +4,34 @@
44

55
import org.seasar.doma.jdbc.SqlBuilderSettings;
66

7-
public class DomaSpringBootSqlBuilderSettings implements SqlBuilderSettings {
8-
9-
private final Predicate<String> shouldRemoveBlockComment;
10-
private final Predicate<String> shouldRemoveLineComment;
11-
private final boolean shouldRemoveBlankLines;
12-
private final boolean shouldRequireInListPadding;
13-
14-
public DomaSpringBootSqlBuilderSettings(Predicate<String> shouldRemoveBlockComment,
15-
Predicate<String> shouldRemoveLineComment, boolean shouldRemoveBlankLines,
16-
boolean shouldRequireInListPadding) {
17-
this.shouldRemoveBlockComment = shouldRemoveBlockComment;
18-
this.shouldRemoveLineComment = shouldRemoveLineComment;
19-
this.shouldRemoveBlankLines = shouldRemoveBlankLines;
20-
this.shouldRequireInListPadding = shouldRequireInListPadding;
21-
}
22-
23-
@Override
24-
public boolean shouldRemoveBlockComment(String comment) {
25-
return shouldRemoveBlockComment.test(comment);
26-
}
27-
28-
@Override
29-
public boolean shouldRemoveLineComment(String comment) {
30-
return shouldRemoveLineComment.test(comment);
31-
}
32-
33-
@Override
34-
public boolean shouldRemoveBlankLines() {
35-
return shouldRemoveBlankLines;
36-
}
37-
38-
@Override
39-
public boolean shouldRequireInListPadding() {
40-
return shouldRequireInListPadding;
41-
}
7+
/**
8+
* Implementation of {@link SqlBuilderSettings} for Spring Boot.
9+
* <p>
10+
* This record encapsulates the SQL builder settings used by Doma in a Spring Boot application.
11+
*/
12+
public record DomaSpringBootSqlBuilderSettings(
13+
Predicate<String> shouldRemoveBlockComment,
14+
Predicate<String> shouldRemoveLineComment,
15+
boolean shouldRemoveBlankLines,
16+
boolean shouldRequireInListPadding) implements SqlBuilderSettings {
17+
18+
@Override
19+
public boolean shouldRemoveBlockComment(String comment) {
20+
return shouldRemoveBlockComment.test(comment);
21+
}
22+
23+
@Override
24+
public boolean shouldRemoveLineComment(String comment) {
25+
return shouldRemoveLineComment.test(comment);
26+
}
27+
28+
@Override
29+
public boolean shouldRemoveBlankLines() {
30+
return shouldRemoveBlankLines;
31+
}
32+
33+
@Override
34+
public boolean shouldRequireInListPadding() {
35+
return shouldRequireInListPadding;
36+
}
4237
}

0 commit comments

Comments
 (0)