Browse Source

Remove @Data annotation and add @TableField annotation (#1653)

* remove @Data

* Modify the test class

* remove assert

*  Add hashcode method  and equals method for AccessToken class

* remove code

* add ut test
pull/2/head
zjcnb 5 years ago committed by dailidong
parent
commit
a96e17ea4e
  1. 82
      dolphinscheduler-dao/src/main/java/org/apache/dolphinscheduler/dao/entity/AccessToken.java
  2. 75
      dolphinscheduler-dao/src/main/java/org/apache/dolphinscheduler/dao/entity/Alert.java
  3. 23
      dolphinscheduler-dao/src/main/java/org/apache/dolphinscheduler/dao/entity/AlertGroup.java
  4. 39
      dolphinscheduler-dao/src/test/java/org/apache/dolphinscheduler/dao/mapper/AccessTokenMapperTest.java

82
dolphinscheduler-dao/src/main/java/org/apache/dolphinscheduler/dao/entity/AccessToken.java

@ -22,32 +22,41 @@ import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import java.util.Date;
import java.util.Objects;
@TableName("t_ds_access_token")
public class AccessToken {
/**
* primary key
*/
@TableId(value = "id", type = IdType.AUTO)
private int id;
@TableField("user_id")
/**
* user_id
*/
@TableField(value = "user_id")
private int userId;
@TableField("token")
/**
* token
*/
@TableField(value = "token")
private String token;
@TableField(exist = false)
private String userName;
@TableField("expire_time")
/**
* expire_time
*/
@TableField(value = "expire_time")
private Date expireTime;
@TableField("create_time")
/**
* create_time
*/
@TableField(value = "create_time")
private Date createTime;
@TableField("update_time")
/**
* update_time
*/
@TableField(value = "update_time")
private Date updateTime;
@TableField(exist = false)
private String userName;
public int getId() {
return id;
@ -107,17 +116,48 @@ public class AccessToken {
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
if (this == o) {
return true;
}
if (o == null || getClass() != o.getClass()) {
return false;
}
AccessToken that = (AccessToken) o;
return id == that.id;
if (id != that.id) {
return false;
}
if (userId != that.userId) {
return false;
}
if (userName != null && !userName.equals(that.userName)) {
return false;
}
if (token != null && !token.equals(that.token)) {
return false;
}
if (expireTime != null && !expireTime.equals(that.expireTime)) {
return false;
}
if (createTime != null && !createTime.equals(that.createTime)) {
return false;
}
if (updateTime != null && !updateTime.equals(that.updateTime)) {
return false;
}
return true;
}
@Override
public int hashCode() {
return Objects.hash(id);
int result = id;
result = 31 * result + userId;
result = 31 * result + (userName != null ? userName.hashCode() : 0);
result = 31 * result + (token != null ? token.hashCode() : 0);
result = 31 * result + (expireTime != null ? expireTime.hashCode() : 0);
result = 31 * result + (createTime != null ? createTime.hashCode() : 0);
result = 31 * result + (updateTime != null ? updateTime.hashCode() : 0);
return result;
}
@Override

75
dolphinscheduler-dao/src/main/java/org/apache/dolphinscheduler/dao/entity/Alert.java

@ -28,96 +28,74 @@ import java.util.Date;
import java.util.HashMap;
import java.util.Map;
/**
* alert
*/
@TableName("t_ds_alert")
public class Alert {
/**
* id
* primary key
*/
@TableId(value = "id", type = IdType.AUTO)
private int id;
/**
* title
*/
@TableField(value = "title")
private String title;
/**
* show type
* show_type
*/
@TableField(value = "show_type")
private ShowType showType;
/**
* content
*/
@TableField(value = "content")
private String content;
/**
* alert type
* alert_type
*/
@TableField(value = "alert_type")
private AlertType alertType;
/**
* alert status
* alert_status
*/
@TableField(value = "alert_status")
private AlertStatus alertStatus;
/**
* log
*/
@TableField(value = "log")
private String log;
/**
* alert group id
* alertgroup_id
*/
@TableField("alertgroup_id")
private int alertGroupId;
/**
* receivers
*/
@TableField("receivers")
private String receivers;
/**
* receivers cc
* receivers_cc
*/
@TableField("receivers_cc")
private String receiversCc;
/**
* create time
* create_time
*/
@TableField("create_time")
private Date createTime;
/**
* update time
* update_time
*/
@TableField("update_time")
private Date updateTime;
@TableField(exist = false)
private Map<String, Object> info = new HashMap<>();
public Map<String, Object> getInfo() {
return info;
}
public void setInfo(Map<String, Object> info) {
this.info = info;
}
public Alert() {
}
public Alert(int id, String title) {
this.id = id;
this.title = title;
}
public int getId() {
return id;
}
@ -158,7 +136,6 @@ public class Alert {
this.alertType = alertType;
}
public AlertStatus getAlertStatus() {
return alertStatus;
}
@ -183,10 +160,6 @@ public class Alert {
this.alertGroupId = alertGroupId;
}
public Date getCreateTime() {
return createTime;
}
public String getReceivers() {
return receivers;
}
@ -203,6 +176,10 @@ public class Alert {
this.receiversCc = receiversCc;
}
public Date getCreateTime() {
return createTime;
}
public void setCreateTime(Date createTime) {
this.createTime = createTime;
}
@ -215,6 +192,14 @@ public class Alert {
this.updateTime = updateTime;
}
public Map<String, Object> getInfo() {
return info;
}
public void setInfo(Map<String, Object> info) {
this.info = info;
}
@Override
public boolean equals(Object o) {
if (this == o) {

23
dolphinscheduler-dao/src/main/java/org/apache/dolphinscheduler/dao/entity/AlertGroup.java

@ -16,6 +16,7 @@
*/
package org.apache.dolphinscheduler.dao.entity;
import com.baomidou.mybatisplus.annotation.TableField;
import org.apache.dolphinscheduler.common.enums.AlertType;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableId;
@ -25,37 +26,35 @@ import java.util.Date;
@TableName("t_ds_alertgroup")
public class AlertGroup {
/**
* primary key
*/
@TableId(value = "id", type = IdType.AUTO)
private int id;
/**
* alert group name
* group_name
*/
@TableField(value = "group_name")
private String groupName;
/**
* alert group type
* group_type
*/
@TableField(value = "group_type")
private AlertType groupType;
/**
* alert group description
* description
*/
@TableField(value = "description")
private String description;
/**
* create time
* create_time
*/
@TableField(value = "create_time")
private Date createTime;
/**
* update time
* update_time
*/
@TableField(value = "update_time")
private Date updateTime;
public int getId() {

39
dolphinscheduler-dao/src/test/java/org/apache/dolphinscheduler/dao/mapper/AccessTokenMapperTest.java

@ -37,9 +37,7 @@ import java.util.*;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.greaterThan;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.*;
/**
* AccessToken mapper test
@ -77,14 +75,34 @@ public class AccessTokenMapperTest {
@Test
public void testSelectById() throws Exception{
Integer userId = 1;
AccessToken accessToken = createAccessToken(userId);
AccessToken resultAccessToken
= accessTokenMapper.selectById(accessToken.getId());
AccessToken resultAccessToken = accessTokenMapper.selectById(accessToken.getId());
assertEquals(accessToken, resultAccessToken);
}
/**
* test hashCode method
* @throws Exception
*/
@Test
public void testHashCodeMethod() throws Exception {
Integer userId = 1;
AccessToken accessToken = createAccessToken(userId);
AccessToken resultAccessToken = accessTokenMapper.selectById(accessToken.getId());
boolean flag = accessToken.equals(resultAccessToken);
assertTrue(flag);
}
/**
* test equals method
* @throws Exception
*/
@Test
public void testEqualsMethod() throws Exception {
Integer userId = 1;
AccessToken accessToken = createAccessToken(userId);
int result = accessToken.hashCode();
assertNotNull(result);
}
/**
@ -98,7 +116,6 @@ public class AccessTokenMapperTest {
Integer offset = 2;
Integer size = 2;
Map<Integer, AccessToken> accessTokenMap = createAccessTokens(count, userName);
Page page = new Page(offset, size);
@ -106,7 +123,6 @@ public class AccessTokenMapperTest {
assertEquals(Integer.valueOf(accessTokenPage.getRecords().size()),size);
for (AccessToken accessToken : accessTokenPage.getRecords()){
AccessToken resultAccessToken = accessTokenMap.get(accessToken.getId());
assertEquals(accessToken,resultAccessToken);
@ -120,15 +136,12 @@ public class AccessTokenMapperTest {
@Test
public void testUpdate() throws Exception{
Integer userId = 1;
AccessToken accessToken = createAccessToken(userId);
//update
accessToken.setToken("56789");
accessToken.setExpireTime(DateUtils.getCurrentDate());
accessToken.setUpdateTime(DateUtils.getCurrentDate());
accessTokenMapper.updateById(accessToken);
AccessToken resultAccessToken = accessTokenMapper.selectById(accessToken.getId());
assertEquals(accessToken, resultAccessToken);
}

Loading…
Cancel
Save