feat(web): 增加type类型用于区分不同的子类
This commit is contained in:
@@ -1,22 +1,25 @@
|
||||
package com.eshore.gringotts.web.domain.resource.entity;
|
||||
|
||||
import com.eshore.gringotts.core.Constants;
|
||||
import com.eshore.gringotts.web.domain.entity.SimpleEntity;
|
||||
import com.eshore.gringotts.web.domain.base.entity.SimpleEntity;
|
||||
import com.eshore.gringotts.web.domain.resource.entity.format.ResourceFormat;
|
||||
import com.eshore.gringotts.web.domain.resource.entity.type.ResourceType;
|
||||
import com.eshore.gringotts.web.domain.upload.entity.DataFile;
|
||||
import javax.persistence.CascadeType;
|
||||
import javax.persistence.Column;
|
||||
import javax.persistence.EnumType;
|
||||
import javax.persistence.Enumerated;
|
||||
import javax.persistence.ConstraintMode;
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.EntityListeners;
|
||||
import javax.persistence.FetchType;
|
||||
import javax.persistence.ForeignKey;
|
||||
import javax.persistence.JoinColumn;
|
||||
import javax.persistence.OneToOne;
|
||||
import javax.persistence.Table;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
import lombok.ToString;
|
||||
import org.hibernate.annotations.DynamicUpdate;
|
||||
import org.springframework.data.jpa.domain.support.AuditingEntityListener;
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.EntityListeners;
|
||||
import javax.persistence.Table;
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
@@ -29,10 +32,16 @@ public class DataResource extends SimpleEntity {
|
||||
@Column(nullable = false)
|
||||
private String name;
|
||||
private String description;
|
||||
@OneToOne
|
||||
@OneToOne(cascade = CascadeType.DETACH, fetch = FetchType.LAZY)
|
||||
@JoinColumn(nullable = false)
|
||||
@ToString.Exclude
|
||||
private ResourceType type;
|
||||
@OneToOne
|
||||
@OneToOne(cascade = CascadeType.DETACH, fetch = FetchType.LAZY)
|
||||
@JoinColumn(nullable = false)
|
||||
@ToString.Exclude
|
||||
private ResourceFormat format;
|
||||
@OneToOne(cascade = CascadeType.DETACH, fetch = FetchType.LAZY)
|
||||
@JoinColumn(foreignKey = @ForeignKey(ConstraintMode.NO_CONSTRAINT))
|
||||
@ToString.Exclude
|
||||
private DataFile example;
|
||||
}
|
||||
|
||||
@@ -21,6 +21,11 @@ import lombok.ToString;
|
||||
@NoArgsConstructor
|
||||
@Entity
|
||||
@DiscriminatorValue("CSV")
|
||||
public class CsvResourceFormat extends ResourceFormat{
|
||||
public class CsvResourceFormat extends ResourceFormat {
|
||||
private String schema;
|
||||
|
||||
@Override
|
||||
public Type getFormatType() {
|
||||
return Type.CSV;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -21,6 +21,11 @@ import lombok.ToString;
|
||||
@NoArgsConstructor
|
||||
@Entity
|
||||
@DiscriminatorValue("JSON_LINE")
|
||||
public class JsonLineResourceFormat extends ResourceFormat{
|
||||
public class JsonLineResourceFormat extends ResourceFormat {
|
||||
private String schema;
|
||||
|
||||
@Override
|
||||
public Type getFormatType() {
|
||||
return Type.JSON_LINE;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
package com.eshore.gringotts.web.domain.resource.entity.format;
|
||||
|
||||
import javax.persistence.Column;
|
||||
import javax.persistence.DiscriminatorValue;
|
||||
import javax.persistence.Entity;
|
||||
import lombok.AllArgsConstructor;
|
||||
@@ -22,6 +21,11 @@ import lombok.ToString;
|
||||
@NoArgsConstructor
|
||||
@Entity
|
||||
@DiscriminatorValue("JSON")
|
||||
public class JsonResourceFormat extends ResourceFormat{
|
||||
public class JsonResourceFormat extends ResourceFormat {
|
||||
private String schema;
|
||||
|
||||
@Override
|
||||
public Type getFormatType() {
|
||||
return Type.JSON;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -17,5 +17,9 @@ import lombok.ToString;
|
||||
@ToString
|
||||
@Entity
|
||||
@DiscriminatorValue("LINE")
|
||||
public class LineResourceFormat extends ResourceFormat{
|
||||
public class LineResourceFormat extends ResourceFormat {
|
||||
@Override
|
||||
public Type getFormatType() {
|
||||
return Type.LINE;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -17,5 +17,9 @@ import lombok.ToString;
|
||||
@ToString
|
||||
@Entity
|
||||
@DiscriminatorValue("NONE")
|
||||
public class NoneResourceFormat extends ResourceFormat{
|
||||
public class NoneResourceFormat extends ResourceFormat {
|
||||
@Override
|
||||
public Type getFormatType() {
|
||||
return Type.NONE;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,12 +1,10 @@
|
||||
package com.eshore.gringotts.web.domain.resource.entity.format;
|
||||
|
||||
import com.eshore.gringotts.core.Constants;
|
||||
import com.eshore.gringotts.web.domain.entity.IdOnlyEntity;
|
||||
import com.eshore.gringotts.web.domain.base.entity.IdOnlyEntity;
|
||||
import javax.persistence.DiscriminatorColumn;
|
||||
import javax.persistence.DiscriminatorType;
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.EnumType;
|
||||
import javax.persistence.Enumerated;
|
||||
import javax.persistence.Inheritance;
|
||||
import javax.persistence.InheritanceType;
|
||||
import javax.persistence.Table;
|
||||
@@ -27,7 +25,7 @@ import lombok.ToString;
|
||||
@Table(name = Constants.TABLE_PREFIX + "resource_format")
|
||||
@Inheritance(strategy = InheritanceType.SINGLE_TABLE)
|
||||
@DiscriminatorColumn(name = "type", discriminatorType = DiscriminatorType.STRING)
|
||||
public class ResourceFormat extends IdOnlyEntity {
|
||||
public abstract class ResourceFormat extends IdOnlyEntity {
|
||||
public enum Type {
|
||||
NONE,
|
||||
LINE,
|
||||
@@ -35,4 +33,6 @@ public class ResourceFormat extends IdOnlyEntity {
|
||||
JSON_LINE,
|
||||
CSV,
|
||||
}
|
||||
|
||||
public abstract Type getFormatType();
|
||||
}
|
||||
|
||||
@@ -22,4 +22,9 @@ public class ApiResourceType extends ResourceType {
|
||||
private String url;
|
||||
private String username;
|
||||
private String password;
|
||||
|
||||
@Override
|
||||
public Type getResourceType() {
|
||||
return Type.API;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -26,9 +26,14 @@ public class DatabaseResourceType extends ResourceType {
|
||||
private String password;
|
||||
@Column(nullable = false)
|
||||
@Enumerated(EnumType.STRING)
|
||||
private Type type;
|
||||
private DatabaseType databaseType;
|
||||
|
||||
public enum Type {
|
||||
@Override
|
||||
public Type getResourceType() {
|
||||
return Type.DATABASE;
|
||||
}
|
||||
|
||||
public enum DatabaseType {
|
||||
MYSQL,
|
||||
POSTGRESQL,
|
||||
ORACLE,
|
||||
|
||||
@@ -1,7 +1,8 @@
|
||||
package com.eshore.gringotts.web.domain.resource.entity.type;
|
||||
|
||||
import com.eshore.gringotts.core.Constants;
|
||||
import javax.persistence.Column;
|
||||
import com.eshore.gringotts.web.domain.upload.entity.DataFile;
|
||||
import javax.persistence.ConstraintMode;
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.Table;
|
||||
import lombok.AllArgsConstructor;
|
||||
@@ -18,6 +19,12 @@ import lombok.ToString;
|
||||
@Entity
|
||||
@Table(name = Constants.TABLE_PREFIX + "resource_type_file")
|
||||
public class FileResourceType extends ResourceType {
|
||||
@Column(nullable = false)
|
||||
private String path;
|
||||
@OneToOne
|
||||
@JoinColumn(nullable = false, foreignKey = @ForeignKey(ConstraintMode.NO_CONSTRAINT))
|
||||
private DataFile file;
|
||||
|
||||
@Override
|
||||
public Type getResourceType() {
|
||||
return Type.FILE;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -24,4 +24,9 @@ public class FtpResourceType extends ResourceType {
|
||||
private String password;
|
||||
private String path;
|
||||
private String regexFilter;
|
||||
|
||||
@Override
|
||||
public Type getResourceType() {
|
||||
return Type.FTP;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,7 +1,8 @@
|
||||
package com.eshore.gringotts.web.domain.resource.entity.type;
|
||||
|
||||
import com.eshore.gringotts.core.Constants;
|
||||
import javax.persistence.Column;
|
||||
import com.eshore.gringotts.web.domain.upload.entity.DataFile;
|
||||
import javax.persistence.ConstraintMode;
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.Table;
|
||||
import lombok.AllArgsConstructor;
|
||||
@@ -18,8 +19,15 @@ import lombok.ToString;
|
||||
@Entity
|
||||
@Table(name = Constants.TABLE_PREFIX + "resource_type_hdfs")
|
||||
public class HDFSResourceType extends ResourceType {
|
||||
@Column(nullable = false)
|
||||
private String coreSite;
|
||||
@Column(nullable = false)
|
||||
private String hdfsSite;
|
||||
@OneToOne
|
||||
@JoinColumn(nullable = false, foreignKey = @ForeignKey(ConstraintMode.NO_CONSTRAINT))
|
||||
private DataFile coreSite;
|
||||
@OneToOne
|
||||
@JoinColumn(nullable = false, foreignKey = @ForeignKey(ConstraintMode.NO_CONSTRAINT))
|
||||
private DataFile hdfsSite;
|
||||
|
||||
@Override
|
||||
public Type getResourceType() {
|
||||
return Type.HDFS;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
package com.eshore.gringotts.web.domain.resource.entity.type;
|
||||
|
||||
import com.eshore.gringotts.core.Constants;
|
||||
import com.eshore.gringotts.web.domain.entity.IdOnlyEntity;
|
||||
import com.eshore.gringotts.web.domain.base.entity.IdOnlyEntity;
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.Inheritance;
|
||||
import javax.persistence.InheritanceType;
|
||||
@@ -22,5 +22,14 @@ import lombok.ToString;
|
||||
@Entity
|
||||
@Table(name = Constants.TABLE_PREFIX + "resource_type")
|
||||
@Inheritance(strategy = InheritanceType.JOINED)
|
||||
public class ResourceType extends IdOnlyEntity {
|
||||
public abstract class ResourceType extends IdOnlyEntity {
|
||||
public abstract Type getResourceType();
|
||||
|
||||
public enum Type {
|
||||
API,
|
||||
DATABASE,
|
||||
FILE,
|
||||
FTP,
|
||||
HDFS,
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user