Created
February 17, 2023 18:48
-
-
Save muhdkhokhar/6f346ec25266b654493f0ab1489066df to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<dependency> | |
<groupId>org.springframework.data</groupId> | |
<artifactId>spring-data-jdbc-core</artifactId> | |
<version>2.2.2.RELEASE</version> | |
</dependency> | |
<dependency> | |
<groupId>org.springframework.data</groupId> | |
<artifactId>spring-data-jdbc-ext</artifactId> | |
<version>2.2.2.RELEASE</version> | |
</dependency> | |
import org.springframework.data.annotation.Id; | |
import org.springframework.data.relational.core.mapping.Table; | |
@Table("customers") | |
public class Customer { | |
@Id | |
private Long id; | |
private String name; | |
private String email; | |
// getters and setters omitted for brevity | |
} | |
import org.springframework.data.jdbc.ext.AbstractJdbcEventListener; | |
import org.springframework.stereotype.Component; | |
@Component | |
public class CustomerEventListener extends AbstractJdbcEventListener<Customer> { | |
@Override | |
protected void onAfterInsert(Customer entity) { | |
// This method is called after a new customer is inserted into the customers table. | |
// Add your custom logic here. | |
System.out.println("New customer added: " + entity.getName()); | |
} | |
@Override | |
protected void onAfterUpdate(Customer entity) { | |
// This method is called after a customer is updated in the customers table. | |
// Add your custom logic here. | |
System.out.println("Customer updated: " + entity.getName()); | |
} | |
@Override | |
protected void onAfterDelete(Customer entity) { | |
// This method is called after a customer is deleted from the customers table. | |
// Add your custom logic here. | |
System.out.println("Customer deleted: " + entity.getName()); | |
} | |
} | |
import org.springframework.boot.SpringApplication; | |
import org.springframework.boot.autoconfigure.SpringBootApplication; | |
import org.springframework.data.jdbc.repository.config.EnableJdbcRepositories; | |
@SpringBootApplication | |
@EnableJdbcRepositories | |
public class MyApp { | |
public static void main(String[] args) { | |
SpringApplication.run(MyApp.class, args); | |
} | |
} | |
EXEC sys.sp_cdc_enable_db | |
EXEC sys.sp_cdc_enable_table | |
@source_schema = 'dbo', | |
@source_name = 'YourTableName', | |
@role_name = NULL, | |
@capture_instance = 'YourTableName_CDC' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment