Skip to content

Commit a9d9a51

Browse files
committed
Do not allow both timeZone and serverTime
1 parent 675edbb commit a9d9a51

File tree

3 files changed

+27
-2
lines changed

3 files changed

+27
-2
lines changed

providers/jdbc/shedlock-provider-jdbc-template/src/main/java/net/javacrumbs/shedlock/provider/jdbctemplate/JdbcTemplateLockProvider.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,9 @@ public static final class Configuration {
111111
this.timeZone = timeZone;
112112
this.columnNames = requireNonNull(columnNames, "columnNames can not be null");
113113
this.lockedByValue = requireNonNull(lockedByValue, "lockedByValue can not be null");
114+
if (useServerTime && timeZone != null) {
115+
throw new IllegalArgumentException("Can not set both serverTime and timeZone");
116+
}
114117
this.useServerTime = useServerTime;
115118
}
116119

providers/jdbc/shedlock-provider-jdbc-template/src/main/java/net/javacrumbs/shedlock/provider/jdbctemplate/SqlStatementsSource.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,7 @@ static SqlStatementsSource create(Configuration configuration) {
4646
logger.debug("Using MySqlServerTimeStatementsSource (for MariaDB)");
4747
return new MySqlServerTimeStatementsSource(configuration);
4848
default:
49-
logger.debug("Using SqlStatementsSource");
50-
return new SqlStatementsSource(configuration);
49+
throw new UnsupportedOperationException("Server time is not supported for " + databaseProductName);
5150
}
5251
} else {
5352
if ("PostgreSQL".equals(databaseProductName)) {
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
package net.javacrumbs.shedlock.provider.jdbctemplate;
2+
3+
import org.junit.jupiter.api.Test;
4+
import org.springframework.jdbc.core.JdbcTemplate;
5+
6+
import java.util.TimeZone;
7+
8+
import static org.assertj.core.api.Assertions.assertThatThrownBy;
9+
import static org.mockito.Mockito.mock;
10+
11+
12+
class JdbcTemplateLockProviderTest {
13+
@Test
14+
void shouldNotEnableBothTimezoneAndServerTime() {
15+
assertThatThrownBy(
16+
() -> JdbcTemplateLockProvider.Configuration.builder()
17+
.withTimeZone(TimeZone.getTimeZone("Europe/Prague"))
18+
.withJdbcTemplate(mock(JdbcTemplate.class))
19+
.usingServerTime()
20+
.build()
21+
).isInstanceOf(IllegalArgumentException.class);
22+
}
23+
}

0 commit comments

Comments
 (0)