Skip to content

Commit e45d35e

Browse files
committed
#952; Better error message or default connection manager
1 parent c3de8f1 commit e45d35e

File tree

3 files changed

+17
-4
lines changed

3 files changed

+17
-4
lines changed

project/jimmer-sql/src/main/java/org/babyfish/jimmer/sql/JSqlClientImpl.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1618,13 +1618,13 @@ public Builder addExceptionTranslator(ExceptionTranslator<?> translator) {
16181618

16191619
@Override
16201620
public JSqlClient.Builder setExplicitBatchEnabled(boolean enabled) {
1621-
explicitBatchEnabled = true;
1621+
explicitBatchEnabled = enabled;
16221622
return this;
16231623
}
16241624

16251625
@Override
16261626
public JSqlClient.Builder setDumbBatchAcceptable(boolean acceptable) {
1627-
dumbBatchAcceptable = true;
1627+
dumbBatchAcceptable = acceptable;
16281628
return this;
16291629
}
16301630

project/jimmer-sql/src/main/java/org/babyfish/jimmer/sql/runtime/ConnectionManager.java

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,17 @@ default <R> R execute(Function<Connection, R> block) {
2222
ConnectionManager EXTERNAL_ONLY = new ConnectionManager() {
2323
@Override
2424
public <R> R execute(@Nullable Connection con, Function<Connection, R> block) {
25-
Objects.requireNonNull(con, "External connection cannot be null");
25+
if (con == null) {
26+
throw new IllegalArgumentException(
27+
"The connection manager is not specified " +
28+
"so \"ConnectionManager.EXTERNAL_ONLY\" " +
29+
"which does not support no explicit JDBC " +
30+
"connection execution is used as default. " +
31+
"There are 2 choices: " +
32+
"1. Specify the connection when execute statement/command" +
33+
"2. Specify the connection manager"
34+
);
35+
}
2636
return block.apply(con);
2737
}
2838
};

project/jimmer-sql/src/test/java/org/babyfish/jimmer/sql/mutation/IdentityTest.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,10 @@ public void testInsertMySql() {
127127
NativeDatabases.assumeNativeDatabase();
128128
resetIdentity(NativeDatabases.MYSQL_DATA_SOURCE);
129129

130-
JSqlClient sqlClient = getSqlClient(it -> it.setDialect(new MySqlDialect()));
130+
JSqlClient sqlClient = getSqlClient(it ->
131+
it.setDialect(new MySqlDialect())
132+
.setExplicitBatchEnabled(true)
133+
);
131134
Department department1 = DepartmentDraft.$.produce(draft -> {
132135
draft.setName("Develop");
133136
draft.addIntoEmployees(emp -> {

0 commit comments

Comments
 (0)