Skip to content

Commit 4f4e201

Browse files
authored
Merge pull request #388 from domaframework/comment-context
Enhance the CommentContext class to accept a message
2 parents d0fa30d + 83f3ce9 commit 4f4e201

File tree

4 files changed

+39
-3
lines changed

4 files changed

+39
-3
lines changed

doma-core/src/main/java/org/seasar/doma/jdbc/CommentContext.java

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,15 +16,19 @@ public class CommentContext {
1616

1717
protected final Optional<Method> method;
1818

19+
protected final Optional<String> message;
20+
1921
/**
2022
* Creates an instance.
2123
*
2224
* @param className the class name that executes the SQL
2325
* @param methodName the method name that executes the SQL
2426
* @param config the configuration
2527
* @param method the DAO method
28+
* @param message the message
2629
*/
27-
public CommentContext(String className, String methodName, Config config, Method method) {
30+
public CommentContext(
31+
String className, String methodName, Config config, Method method, String message) {
2832
if (className == null) {
2933
throw new DomaNullPointerException("className");
3034
}
@@ -38,6 +42,7 @@ public CommentContext(String className, String methodName, Config config, Method
3842
this.methodName = methodName;
3943
this.config = config;
4044
this.method = Optional.ofNullable(method);
45+
this.message = Optional.ofNullable(message);
4146
}
4247

4348
/**
@@ -76,4 +81,13 @@ public Config getConfig() {
7681
public Optional<Method> getMethod() {
7782
return method;
7883
}
84+
85+
/**
86+
* Returns the message or {@link Optional#empty()}.
87+
*
88+
* @return the message or {@link Optional#empty()} if it does not exit
89+
*/
90+
public Optional<String> getMessage() {
91+
return message;
92+
}
7993
}

doma-core/src/main/java/org/seasar/doma/jdbc/query/AbstractQuery.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ public void setQueryTimeout(int queryTimeout) {
7070
@Override
7171
public void prepare() {
7272
assertNotNull(callerClassName, callerMethodName, config);
73-
commentContext = new CommentContext(callerClassName, callerMethodName, config, method);
73+
commentContext = new CommentContext(callerClassName, callerMethodName, config, method, null);
7474
}
7575

7676
@Override

doma-core/src/test/java/org/seasar/doma/jdbc/CallerCommenterTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ public class CallerCommenterTest {
1111

1212
@Test
1313
public void testComment() throws Exception {
14-
CommentContext context = new CommentContext("class", "method", new MockConfig(), null);
14+
CommentContext context = new CommentContext("class", "method", new MockConfig(), null, null);
1515
String actual = commenter.comment("select * from emp", context);
1616
assertEquals("/** class.method */" + System.lineSeparator() + "select * from emp", actual);
1717
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
package org.seasar.doma.jdbc;
2+
3+
import static org.junit.jupiter.api.Assertions.assertEquals;
4+
import static org.junit.jupiter.api.Assertions.assertFalse;
5+
6+
import org.junit.jupiter.api.Test;
7+
import org.seasar.doma.internal.jdbc.mock.MockConfig;
8+
9+
class CommentContextTest {
10+
11+
@Test
12+
void getMessage() {
13+
CommentContext context = new CommentContext("class", "method", new MockConfig(), null, "hello");
14+
assertEquals("hello", context.getMessage().get());
15+
}
16+
17+
@Test
18+
void getMessage_empty() {
19+
CommentContext context = new CommentContext("class", "method", new MockConfig(), null, null);
20+
assertFalse(context.getMessage().isPresent());
21+
}
22+
}

0 commit comments

Comments
 (0)