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 com.baomidou.mybatisplus.annotation.TableName;
import java.util.Date; import java.util.Date;
import java.util.Objects;
@TableName("t_ds_access_token") @TableName("t_ds_access_token")
public class AccessToken { public class AccessToken {
/**
* primary key
*/
@TableId(value = "id", type = IdType.AUTO) @TableId(value = "id", type = IdType.AUTO)
private int id; private int id;
/**
* user_id
@TableField("user_id") */
@TableField(value = "user_id")
private int userId; private int userId;
/**
@TableField("token") * token
*/
@TableField(value = "token")
private String token; private String token;
/**
@TableField(exist = false) * expire_time
private String userName; */
@TableField(value = "expire_time")
@TableField("expire_time")
private Date expireTime; private Date expireTime;
/**
@TableField("create_time") * create_time
*/
@TableField(value = "create_time")
private Date createTime; private Date createTime;
/**
@TableField("update_time") * update_time
*/
@TableField(value = "update_time")
private Date updateTime; private Date updateTime;
@TableField(exist = false)
private String userName;
public int getId() { public int getId() {
return id; return id;
@ -107,17 +116,48 @@ public class AccessToken {
@Override @Override
public boolean equals(Object o) { public boolean equals(Object o) {
if (this == o) return true; if (this == o) {
if (o == null || getClass() != o.getClass()) return false; return true;
}
if (o == null || getClass() != o.getClass()) {
return false;
}
AccessToken that = (AccessToken) o; 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 @Override
public int hashCode() { 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 @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.HashMap;
import java.util.Map; import java.util.Map;
/**
* alert
*/
@TableName("t_ds_alert") @TableName("t_ds_alert")
public class Alert { public class Alert {
/** /**
* id * primary key
*/ */
@TableId(value = "id", type = IdType.AUTO) @TableId(value = "id", type = IdType.AUTO)
private int id; private int id;
/** /**
* title * title
*/ */
@TableField(value = "title")
private String title; private String title;
/** /**
* show type * show_type
*/ */
@TableField(value = "show_type")
private ShowType showType; private ShowType showType;
/** /**
* content * content
*/ */
@TableField(value = "content")
private String content; private String content;
/** /**
* alert type * alert_type
*/ */
@TableField(value = "alert_type")
private AlertType alertType; private AlertType alertType;
/** /**
* alert status * alert_status
*/ */
@TableField(value = "alert_status")
private AlertStatus alertStatus; private AlertStatus alertStatus;
/** /**
* log * log
*/ */
@TableField(value = "log")
private String log; private String log;
/** /**
* alert group id * alertgroup_id
*/ */
@TableField("alertgroup_id") @TableField("alertgroup_id")
private int alertGroupId; private int alertGroupId;
/** /**
* receivers * receivers
*/ */
@TableField("receivers")
private String receivers; private String receivers;
/** /**
* receivers cc * receivers_cc
*/ */
@TableField("receivers_cc")
private String receiversCc; private String receiversCc;
/** /**
* create time * create_time
*/ */
@TableField("create_time")
private Date createTime; private Date createTime;
/** /**
* update time * update_time
*/ */
@TableField("update_time")
private Date updateTime; private Date updateTime;
@TableField(exist = false) @TableField(exist = false)
private Map<String, Object> info = new HashMap<>(); 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() {
} }
public Alert(int id, String title) {
this.id = id;
this.title = title;
}
public int getId() { public int getId() {
return id; return id;
} }
@ -158,7 +136,6 @@ public class Alert {
this.alertType = alertType; this.alertType = alertType;
} }
public AlertStatus getAlertStatus() { public AlertStatus getAlertStatus() {
return alertStatus; return alertStatus;
} }
@ -183,10 +160,6 @@ public class Alert {
this.alertGroupId = alertGroupId; this.alertGroupId = alertGroupId;
} }
public Date getCreateTime() {
return createTime;
}
public String getReceivers() { public String getReceivers() {
return receivers; return receivers;
} }
@ -203,6 +176,10 @@ public class Alert {
this.receiversCc = receiversCc; this.receiversCc = receiversCc;
} }
public Date getCreateTime() {
return createTime;
}
public void setCreateTime(Date createTime) { public void setCreateTime(Date createTime) {
this.createTime = createTime; this.createTime = createTime;
} }
@ -215,6 +192,14 @@ public class Alert {
this.updateTime = updateTime; this.updateTime = updateTime;
} }
public Map<String, Object> getInfo() {
return info;
}
public void setInfo(Map<String, Object> info) {
this.info = info;
}
@Override @Override
public boolean equals(Object o) { public boolean equals(Object o) {
if (this == 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; package org.apache.dolphinscheduler.dao.entity;
import com.baomidou.mybatisplus.annotation.TableField;
import org.apache.dolphinscheduler.common.enums.AlertType; import org.apache.dolphinscheduler.common.enums.AlertType;
import com.baomidou.mybatisplus.annotation.IdType; import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableId; import com.baomidou.mybatisplus.annotation.TableId;
@ -25,37 +26,35 @@ import java.util.Date;
@TableName("t_ds_alertgroup") @TableName("t_ds_alertgroup")
public class AlertGroup { public class AlertGroup {
/** /**
* primary key * primary key
*/ */
@TableId(value = "id", type = IdType.AUTO) @TableId(value = "id", type = IdType.AUTO)
private int id; private int id;
/** /**
* alert group name * group_name
*/ */
@TableField(value = "group_name")
private String groupName; private String groupName;
/** /**
* alert group type * group_type
*/ */
@TableField(value = "group_type")
private AlertType groupType; private AlertType groupType;
/** /**
* alert group description * description
*/ */
@TableField(value = "description")
private String description; private String description;
/** /**
* create time * create_time
*/ */
@TableField(value = "create_time")
private Date createTime; private Date createTime;
/** /**
* update time * update_time
*/ */
@TableField(value = "update_time")
private Date updateTime; private Date updateTime;
public int getId() { 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.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.greaterThan; import static org.hamcrest.Matchers.greaterThan;
import static org.junit.Assert.assertEquals; import static org.junit.Assert.*;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
/** /**
* AccessToken mapper test * AccessToken mapper test
@ -77,14 +75,34 @@ public class AccessTokenMapperTest {
@Test @Test
public void testSelectById() throws Exception{ public void testSelectById() throws Exception{
Integer userId = 1; Integer userId = 1;
AccessToken accessToken = createAccessToken(userId); AccessToken accessToken = createAccessToken(userId);
AccessToken resultAccessToken = accessTokenMapper.selectById(accessToken.getId());
AccessToken resultAccessToken
= accessTokenMapper.selectById(accessToken.getId());
assertEquals(accessToken, resultAccessToken); 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 offset = 2;
Integer size = 2; Integer size = 2;
Map<Integer, AccessToken> accessTokenMap = createAccessTokens(count, userName); Map<Integer, AccessToken> accessTokenMap = createAccessTokens(count, userName);
Page page = new Page(offset, size); Page page = new Page(offset, size);
@ -106,7 +123,6 @@ public class AccessTokenMapperTest {
assertEquals(Integer.valueOf(accessTokenPage.getRecords().size()),size); assertEquals(Integer.valueOf(accessTokenPage.getRecords().size()),size);
for (AccessToken accessToken : accessTokenPage.getRecords()){ for (AccessToken accessToken : accessTokenPage.getRecords()){
AccessToken resultAccessToken = accessTokenMap.get(accessToken.getId()); AccessToken resultAccessToken = accessTokenMap.get(accessToken.getId());
assertEquals(accessToken,resultAccessToken); assertEquals(accessToken,resultAccessToken);
@ -120,15 +136,12 @@ public class AccessTokenMapperTest {
@Test @Test
public void testUpdate() throws Exception{ public void testUpdate() throws Exception{
Integer userId = 1; Integer userId = 1;
AccessToken accessToken = createAccessToken(userId); AccessToken accessToken = createAccessToken(userId);
//update //update
accessToken.setToken("56789"); accessToken.setToken("56789");
accessToken.setExpireTime(DateUtils.getCurrentDate()); accessToken.setExpireTime(DateUtils.getCurrentDate());
accessToken.setUpdateTime(DateUtils.getCurrentDate()); accessToken.setUpdateTime(DateUtils.getCurrentDate());
accessTokenMapper.updateById(accessToken); accessTokenMapper.updateById(accessToken);
AccessToken resultAccessToken = accessTokenMapper.selectById(accessToken.getId()); AccessToken resultAccessToken = accessTokenMapper.selectById(accessToken.getId());
assertEquals(accessToken, resultAccessToken); assertEquals(accessToken, resultAccessToken);
} }

Loading…
Cancel
Save