Skip to content
This repository has been archived by the owner on Jan 3, 2023. It is now read-only.

fix some bugs and add more methods in Dao #864

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,12 @@ public ClusterConfig getById(long cid) {
new Object[]{cid}, new ClusterConfigRowMapper());
}

public ClusterConfig getByName(String name){
public long getCountByName(String name) {
JdbcTemplate jdbcTemplate = new JdbcTemplate(dataSource);
return jdbcTemplate.queryForObject("select COUNT(*) FROM cluster_config WHERE node_name = ?",Long.class);
}

public ClusterConfig getByName(String name) {
JdbcTemplate jdbcTemplate = new JdbcTemplate(dataSource);
return jdbcTemplate.queryForObject("select * from cluster_config WHERE node_name = ?",
new Object[]{name}, new ClusterConfigRowMapper());
Expand All @@ -84,9 +89,12 @@ public long insert(ClusterConfig clusterConfig) {
SimpleJdbcInsert simpleJdbcInsert = new SimpleJdbcInsert(dataSource);
simpleJdbcInsert.setTableName("cluster_config");
simpleJdbcInsert.usingGeneratedKeyColumns("cid");
return simpleJdbcInsert.executeAndReturnKey(toMap(clusterConfig)).longValue();
long cid = simpleJdbcInsert.executeAndReturnKey(toMap(clusterConfig)).longValue();
clusterConfig.setCid(cid);
return cid;
}

// TODO slove the increment of key
public void insert(ClusterConfig[] clusterConfigs) {
SimpleJdbcInsert simpleJdbcInsert = new SimpleJdbcInsert(dataSource);
simpleJdbcInsert.setTableName("cluster_config");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,9 +78,12 @@ public long insert(FileDiff fileDiff) {
simpleJdbcInsert.setTableName("file_diff");
simpleJdbcInsert.usingGeneratedKeyColumns("did");
// return did
return simpleJdbcInsert.executeAndReturnKey(toMap(fileDiff)).longValue();
long did = simpleJdbcInsert.executeAndReturnKey(toMap(fileDiff)).longValue();
fileDiff.setDiffId(did);
return did;
}

// TODO slove the increment of key
public void insert(FileDiff[] fileDiffs) {
SimpleJdbcInsert simpleJdbcInsert = new SimpleJdbcInsert(dataSource);
simpleJdbcInsert.setTableName("file_diff");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,9 +89,12 @@ public long insert(GlobalConfig globalConfig) {
SimpleJdbcInsert simpleJdbcInsert = new SimpleJdbcInsert(dataSource);
simpleJdbcInsert.setTableName("global_config");
simpleJdbcInsert.usingGeneratedKeyColumns("cid");
return simpleJdbcInsert.executeAndReturnKey(toMaps(globalConfig)).longValue();
long cid = simpleJdbcInsert.executeAndReturnKey(toMaps(globalConfig)).longValue();
globalConfig.setCid(cid);
return cid;
}

// TODO slove the increment of key
public void insert(GlobalConfig[] globalConfigs) {
SimpleJdbcInsert simpleJdbcInsert = new SimpleJdbcInsert(dataSource);
simpleJdbcInsert.setTableName("global_config");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,5 +57,11 @@ public void testUpdate() {
Assert.assertTrue(clusterConfigDao.getById(1).equals(clusterConfig));
}


@Test
public void testgetCountByName(){
Assert.assertTrue(clusterConfigDao.getCountByName("test") == 0);
ClusterConfig clusterConfig = new ClusterConfig(1, "test", "test1");
clusterConfigDao.insert(clusterConfig);
Assert.assertTrue(clusterConfigDao.getCountByName("test") == 0);
}
}