Search in sources :

Example 1 with ColumnNames

use of net.javacrumbs.shedlock.provider.jdbctemplate.JdbcTemplateLockProvider.ColumnNames in project ShedLock by lukas-krecan.

the class HsqlJdbcTemplateLockProviderIntegrationTest method shouldBeAbleToSetCustomColumnNames.

@Test
public void shouldBeAbleToSetCustomColumnNames() throws SQLException {
    try (Connection conn = dbConfig.getDataSource().getConnection();
        Statement statement = conn.createStatement()) {
        statement.execute("CREATE TABLE shdlck(n VARCHAR(64), lck_untl TIMESTAMP(3), lckd_at TIMESTAMP(3), lckd_by  VARCHAR(255), PRIMARY KEY (n))");
    }
    JdbcTemplateLockProvider provider = new JdbcTemplateLockProvider(builder().withTableName("shdlck").withColumnNames(new ColumnNames("n", "lck_untl", "lckd_at", "lckd_by")).withJdbcTemplate(new JdbcTemplate(dbConfig.getDataSource())).withLockedByValue("my-value").build());
    Optional<SimpleLock> lock = provider.lock(new LockConfiguration(now(), "test", Duration.ofSeconds(10), Duration.ZERO));
    lock.get().unlock();
}
Also used : ColumnNames(net.javacrumbs.shedlock.provider.jdbctemplate.JdbcTemplateLockProvider.ColumnNames) Statement(java.sql.Statement) LockConfiguration(net.javacrumbs.shedlock.core.LockConfiguration) SimpleLock(net.javacrumbs.shedlock.core.SimpleLock) Connection(java.sql.Connection) JdbcTemplate(org.springframework.jdbc.core.JdbcTemplate) Test(org.junit.jupiter.api.Test)

Aggregations

Connection (java.sql.Connection)1 Statement (java.sql.Statement)1 LockConfiguration (net.javacrumbs.shedlock.core.LockConfiguration)1 SimpleLock (net.javacrumbs.shedlock.core.SimpleLock)1 ColumnNames (net.javacrumbs.shedlock.provider.jdbctemplate.JdbcTemplateLockProvider.ColumnNames)1 Test (org.junit.jupiter.api.Test)1 JdbcTemplate (org.springframework.jdbc.core.JdbcTemplate)1