29 Eylül 2023 Cuma

SpringScheduling Shedlock JdbcTemplateLockProvider Sınıfı

Giriş
Şu satırı dahil ederiz
import net.javacrumbs.shedlock.provider.jdbctemplate.JdbcTemplateLockProvider;
constructor
JdbcTemplateLockProvider.Configuration .builder()...build() şeklinde kullanılır


JdbcTemplateLockProvider.Configuration.Builder Sınıfı
Bu sınıf hemen hemen her yerde aynı şekilde kullanılıyor

withJdbcTemplate metodu
Örnek
Şöyle yaparız
import net.javacrumbs.shedlock.core.LockProvider;
import net.javacrumbs.shedlock.provider.jdbctemplate.JdbcTemplateLockProvider;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.jdbc.core.JdbcTemplate;
import javax.sql.DataSource;

@Configuration
public class ShedLockConfig {

  @Bean
  public LockProvider lockProvider(DataSource dataSource) {
    return new JdbcTemplateLockProvider(JdbcTemplateLockProvider.Configuration
      .builder()
      .withJdbcTemplate(new JdbcTemplate(dataSource))
      .usingDbTime() // Use database time for locks
      .build());
  }
}
Örnek
Şöyle yaparız
@Bean
@SuppressWarnings("unused")
public LockProvider lockProvider(DataSource dataSource) {
  return new JdbcTemplateLockProvider(
    JdbcTemplateLockProvider.Configuration.builder()
      .withJdbcTemplate(new JdbcTemplate(datasource))
      .usingDbTime ()
      .build ()
  );
}
Örnek
Şöyle yaparız
@Bean
public LockProvider lockProvider(DataSource dataSource) {  
  return new JdbcTemplateLockProvider(  
    JdbcTemplateLockProvider.Configuration.builder()  
      .withJdbcTemplate(new JdbcTemplate(dataSource))  
      .usingDbTime() // Works on Postgres, MySQL, MariaDb, MS SQL, Oracle, DB2, HSQL, H2  
      .build()  
  );  
}

Hiç yorum yok:

Yorum Gönder