mirror of
https://github.com/alibaba/canal.git
synced 2026-11-04 00:30:15 +08:00
fix modified_time null value error (#2157)
* template config load * compile vue frontend for product * fix modified_time null value error * modify
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
package com.alibaba.otter.canal.admin.model;
|
||||
|
||||
import io.ebean.Finder;
|
||||
import io.ebean.annotation.WhenModified;
|
||||
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.Id;
|
||||
@@ -34,6 +35,7 @@ public class CanalCluster extends Model {
|
||||
private Long id;
|
||||
private String name;
|
||||
private String zkHosts;
|
||||
@WhenModified
|
||||
private Date modifiedTime;
|
||||
|
||||
public Long getId() {
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package com.alibaba.otter.canal.admin.model;
|
||||
|
||||
import io.ebean.Finder;
|
||||
import io.ebean.annotation.WhenModified;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
@@ -37,6 +38,7 @@ public class CanalConfig extends Model {
|
||||
private String content;
|
||||
private String contentMd5;
|
||||
private String status;
|
||||
@WhenModified
|
||||
private Date modifiedTime;
|
||||
|
||||
public void init() {
|
||||
|
||||
@@ -5,6 +5,7 @@ import java.util.Date;
|
||||
import javax.persistence.*;
|
||||
|
||||
import io.ebean.Finder;
|
||||
import io.ebean.annotation.WhenModified;
|
||||
|
||||
/**
|
||||
* Canal实例配置信息实体类
|
||||
@@ -44,6 +45,7 @@ public class CanalInstanceConfig extends Model {
|
||||
private String content;
|
||||
private String contentMd5;
|
||||
private String status; // 1: 正常 0: 停止
|
||||
@WhenModified
|
||||
private Date modifiedTime;
|
||||
|
||||
@Transient
|
||||
|
||||
@@ -1,16 +1,13 @@
|
||||
package com.alibaba.otter.canal.admin.model;
|
||||
|
||||
import io.ebean.Ebean;
|
||||
import io.ebean.EbeanServer;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
|
||||
import javax.persistence.Id;
|
||||
import javax.persistence.MappedSuperclass;
|
||||
import javax.persistence.OptimisticLockException;
|
||||
|
||||
import org.apache.commons.beanutils.PropertyUtils;
|
||||
|
||||
import io.ebean.Ebean;
|
||||
import io.ebean.EbeanServer;
|
||||
|
||||
/**
|
||||
* EBean Model扩展类
|
||||
*
|
||||
@@ -35,21 +32,10 @@ public abstract class Model extends io.ebean.Model {
|
||||
|
||||
public void saveOrUpdate() {
|
||||
try {
|
||||
Field idField = null;
|
||||
// find id field
|
||||
Field[] fields = this.getClass().getDeclaredFields();
|
||||
for (Field field : fields) {
|
||||
Id idAnn = field.getAnnotation(Id.class);
|
||||
if (idAnn != null) {
|
||||
idField = field;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (idField == null) {
|
||||
return;
|
||||
}
|
||||
Object idVal = PropertyUtils.getProperty(this, idField.getName());
|
||||
if (idVal == null) {
|
||||
EbeanServer ebeanServer = Ebean.getDefaultServer();
|
||||
Object id = ebeanServer.getBeanId(this);
|
||||
if (id == null) {
|
||||
init();
|
||||
this.save();
|
||||
} else {
|
||||
this.update();
|
||||
@@ -63,7 +49,13 @@ public abstract class Model extends io.ebean.Model {
|
||||
try {
|
||||
EbeanServer ebeanServer = Ebean.getDefaultServer();
|
||||
Object id = ebeanServer.getBeanId(this);
|
||||
if (id == null) {
|
||||
return;
|
||||
}
|
||||
Object model = ebeanServer.createQuery(this.getClass()).where().idEq(id).findOne();
|
||||
if (model == null) {
|
||||
return;
|
||||
}
|
||||
for (String propertyName : propertiesNames) {
|
||||
if (propertyName.startsWith("nn:")) { // not null
|
||||
propertyName = propertyName.substring(3);
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package com.alibaba.otter.canal.admin.model;
|
||||
|
||||
import io.ebean.Finder;
|
||||
import io.ebean.annotation.WhenModified;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
@@ -42,6 +43,7 @@ public class NodeServer extends Model {
|
||||
private Integer metricPort;
|
||||
private Integer tcpPort;
|
||||
private String status;
|
||||
@WhenModified
|
||||
private Date modifiedTime;
|
||||
|
||||
public void init() {
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package com.alibaba.otter.canal.admin.model;
|
||||
|
||||
import io.ebean.Finder;
|
||||
import io.ebean.annotation.WhenCreated;
|
||||
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.Id;
|
||||
@@ -36,6 +37,7 @@ public class User extends Model {
|
||||
private String introduction;
|
||||
private String avatar;
|
||||
private String name;
|
||||
@WhenCreated
|
||||
private Date creationDate;
|
||||
|
||||
@Transient
|
||||
|
||||
Reference in New Issue
Block a user