modify
This commit is contained in:
+15
@@ -0,0 +1,15 @@
|
||||
package com.alibaba.otter.canal.admin.config;
|
||||
|
||||
import org.apache.commons.dbutils.QueryRunner;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
|
||||
import javax.sql.DataSource;
|
||||
|
||||
@Configuration
|
||||
public class Config {
|
||||
@Bean
|
||||
public QueryRunner queryRunner(DataSource dataSource) {
|
||||
return new QueryRunner(dataSource);
|
||||
}
|
||||
}
|
||||
+16
-19
@@ -1,43 +1,40 @@
|
||||
package com.alibaba.otter.canal.admin.dao;
|
||||
|
||||
import com.alibaba.otter.canal.admin.model.CanalConfig;
|
||||
import com.alibaba.otter.canal.admin.model.Person;
|
||||
import org.apache.commons.dbutils.QueryRunner;
|
||||
import org.apache.commons.dbutils.handlers.BeanHandler;
|
||||
import org.javalite.activejdbc.Base;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.jdbc.core.JdbcTemplate;
|
||||
import org.springframework.stereotype.Repository;
|
||||
|
||||
import javax.annotation.PostConstruct;
|
||||
import javax.sql.DataSource;
|
||||
import java.sql.SQLException;
|
||||
import java.util.Date;
|
||||
|
||||
@Repository
|
||||
public class CanalConfigDao {
|
||||
@Autowired
|
||||
private DataSource dataSource;
|
||||
// public void open() {
|
||||
// Base.open(dataSource);
|
||||
// }
|
||||
private QueryRunner runner;
|
||||
|
||||
@PostConstruct
|
||||
public void init() {
|
||||
// CanalConfig canalConfig = new CanalConfig();
|
||||
// canalConfig.setId(1L);
|
||||
UpdateContent(1L);
|
||||
}
|
||||
|
||||
public void UpdateContent(Long id) {
|
||||
QueryRunner runner = new QueryRunner(dataSource);
|
||||
try {
|
||||
CanalConfig canalConfig = runner.query("select * from canal_config where id=1", new BeanHandler<>(CanalConfig.class));
|
||||
CanalConfig canalConfig = findById(1L);
|
||||
canalConfig = canalConfig;
|
||||
canalConfig.setContent(canalConfig.getContent()+" xxx");
|
||||
updateContent(canalConfig);
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
// Base.open(dataSource);
|
||||
// Person.where("id=?", id);
|
||||
// Base.close();
|
||||
}
|
||||
|
||||
public CanalConfig findById(Long id) throws SQLException {
|
||||
String sql = "select id,name,content,modified_time as modifiedTime" +
|
||||
" from canal_config where id=?";
|
||||
return runner.query(sql, new BeanHandler<>(CanalConfig.class), id);
|
||||
}
|
||||
|
||||
public void updateContent(CanalConfig canalConfig) throws SQLException {
|
||||
String sql = "update canal_config set content=?, modified_time=? where id=?";
|
||||
runner.update(sql, canalConfig.getContent(), new Date(), canalConfig.getId());
|
||||
}
|
||||
}
|
||||
|
||||
+3
-3
@@ -10,7 +10,7 @@ public class CanalConfig {
|
||||
private Long id;
|
||||
private String name;
|
||||
private String content;
|
||||
private Timestamp modifiedTime;
|
||||
private Date modifiedTime;
|
||||
|
||||
public Long getId() {
|
||||
return id;
|
||||
@@ -36,11 +36,11 @@ public class CanalConfig {
|
||||
this.content = content;
|
||||
}
|
||||
|
||||
public Timestamp getModifiedTime() {
|
||||
public Date getModifiedTime() {
|
||||
return modifiedTime;
|
||||
}
|
||||
|
||||
public void setModifiedTime(Timestamp modifiedTime) {
|
||||
public void setModifiedTime(Date modifiedTime) {
|
||||
this.modifiedTime = modifiedTime;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -126,6 +126,7 @@
|
||||
<module>example</module>
|
||||
<module>prometheus</module>
|
||||
<module>client-adapter</module>
|
||||
<module>canal-admin</module>
|
||||
</modules>
|
||||
|
||||
<dependencyManagement>
|
||||
@@ -253,7 +254,7 @@
|
||||
<dependency>
|
||||
<groupId>com.alibaba.fastsql</groupId>
|
||||
<artifactId>fastsql</artifactId>
|
||||
<version>2.0.0_preview_914</version>
|
||||
<version>2.0.0_preview_896</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.alibaba</groupId>
|
||||
|
||||
@@ -133,7 +133,7 @@ public class CanalKafkaProducer implements CanalMQProducer {
|
||||
canalDestination.getDynamicTopic());
|
||||
|
||||
for (Map.Entry<String, Message> entry : messageMap.entrySet()) {
|
||||
String topicName = entry.getKey().replace('.', '_');
|
||||
String topicName = entry.getKey(); //.replace('.', '_');
|
||||
Message messageSub = entry.getValue();
|
||||
if (logger.isDebugEnabled()) {
|
||||
logger.debug("## Send message to kafka topic: " + topicName);
|
||||
|
||||
Reference in New Issue
Block a user