1
0

feat(web): 增加type类型用于区分不同的子类

This commit is contained in:
2024-11-21 19:15:49 +08:00
parent a273f93f7a
commit ccbefb9bdf
13 changed files with 100 additions and 30 deletions

View File

@@ -1,22 +1,25 @@
package com.eshore.gringotts.web.domain.resource.entity; package com.eshore.gringotts.web.domain.resource.entity;
import com.eshore.gringotts.core.Constants; 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.format.ResourceFormat;
import com.eshore.gringotts.web.domain.resource.entity.type.ResourceType; 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.Column;
import javax.persistence.EnumType; import javax.persistence.ConstraintMode;
import javax.persistence.Enumerated; import javax.persistence.Entity;
import javax.persistence.EntityListeners;
import javax.persistence.FetchType;
import javax.persistence.ForeignKey;
import javax.persistence.JoinColumn; import javax.persistence.JoinColumn;
import javax.persistence.OneToOne; import javax.persistence.OneToOne;
import javax.persistence.Table;
import lombok.Getter; import lombok.Getter;
import lombok.Setter; import lombok.Setter;
import lombok.ToString; import lombok.ToString;
import org.hibernate.annotations.DynamicUpdate; import org.hibernate.annotations.DynamicUpdate;
import org.springframework.data.jpa.domain.support.AuditingEntityListener; import org.springframework.data.jpa.domain.support.AuditingEntityListener;
import javax.persistence.Entity;
import javax.persistence.EntityListeners;
import javax.persistence.Table;
@Getter @Getter
@Setter @Setter
@@ -29,10 +32,16 @@ public class DataResource extends SimpleEntity {
@Column(nullable = false) @Column(nullable = false)
private String name; private String name;
private String description; private String description;
@OneToOne @OneToOne(cascade = CascadeType.DETACH, fetch = FetchType.LAZY)
@JoinColumn(nullable = false) @JoinColumn(nullable = false)
@ToString.Exclude
private ResourceType type; private ResourceType type;
@OneToOne @OneToOne(cascade = CascadeType.DETACH, fetch = FetchType.LAZY)
@JoinColumn(nullable = false) @JoinColumn(nullable = false)
@ToString.Exclude
private ResourceFormat format; private ResourceFormat format;
@OneToOne(cascade = CascadeType.DETACH, fetch = FetchType.LAZY)
@JoinColumn(foreignKey = @ForeignKey(ConstraintMode.NO_CONSTRAINT))
@ToString.Exclude
private DataFile example;
} }

View File

@@ -23,4 +23,9 @@ import lombok.ToString;
@DiscriminatorValue("CSV") @DiscriminatorValue("CSV")
public class CsvResourceFormat extends ResourceFormat { public class CsvResourceFormat extends ResourceFormat {
private String schema; private String schema;
@Override
public Type getFormatType() {
return Type.CSV;
}
} }

View File

@@ -23,4 +23,9 @@ import lombok.ToString;
@DiscriminatorValue("JSON_LINE") @DiscriminatorValue("JSON_LINE")
public class JsonLineResourceFormat extends ResourceFormat { public class JsonLineResourceFormat extends ResourceFormat {
private String schema; private String schema;
@Override
public Type getFormatType() {
return Type.JSON_LINE;
}
} }

View File

@@ -1,6 +1,5 @@
package com.eshore.gringotts.web.domain.resource.entity.format; package com.eshore.gringotts.web.domain.resource.entity.format;
import javax.persistence.Column;
import javax.persistence.DiscriminatorValue; import javax.persistence.DiscriminatorValue;
import javax.persistence.Entity; import javax.persistence.Entity;
import lombok.AllArgsConstructor; import lombok.AllArgsConstructor;
@@ -24,4 +23,9 @@ import lombok.ToString;
@DiscriminatorValue("JSON") @DiscriminatorValue("JSON")
public class JsonResourceFormat extends ResourceFormat { public class JsonResourceFormat extends ResourceFormat {
private String schema; private String schema;
@Override
public Type getFormatType() {
return Type.JSON;
}
} }

View File

@@ -18,4 +18,8 @@ import lombok.ToString;
@Entity @Entity
@DiscriminatorValue("LINE") @DiscriminatorValue("LINE")
public class LineResourceFormat extends ResourceFormat { public class LineResourceFormat extends ResourceFormat {
@Override
public Type getFormatType() {
return Type.LINE;
}
} }

View File

@@ -18,4 +18,8 @@ import lombok.ToString;
@Entity @Entity
@DiscriminatorValue("NONE") @DiscriminatorValue("NONE")
public class NoneResourceFormat extends ResourceFormat { public class NoneResourceFormat extends ResourceFormat {
@Override
public Type getFormatType() {
return Type.NONE;
}
} }

View File

@@ -1,12 +1,10 @@
package com.eshore.gringotts.web.domain.resource.entity.format; package com.eshore.gringotts.web.domain.resource.entity.format;
import com.eshore.gringotts.core.Constants; 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.DiscriminatorColumn;
import javax.persistence.DiscriminatorType; import javax.persistence.DiscriminatorType;
import javax.persistence.Entity; import javax.persistence.Entity;
import javax.persistence.EnumType;
import javax.persistence.Enumerated;
import javax.persistence.Inheritance; import javax.persistence.Inheritance;
import javax.persistence.InheritanceType; import javax.persistence.InheritanceType;
import javax.persistence.Table; import javax.persistence.Table;
@@ -27,7 +25,7 @@ import lombok.ToString;
@Table(name = Constants.TABLE_PREFIX + "resource_format") @Table(name = Constants.TABLE_PREFIX + "resource_format")
@Inheritance(strategy = InheritanceType.SINGLE_TABLE) @Inheritance(strategy = InheritanceType.SINGLE_TABLE)
@DiscriminatorColumn(name = "type", discriminatorType = DiscriminatorType.STRING) @DiscriminatorColumn(name = "type", discriminatorType = DiscriminatorType.STRING)
public class ResourceFormat extends IdOnlyEntity { public abstract class ResourceFormat extends IdOnlyEntity {
public enum Type { public enum Type {
NONE, NONE,
LINE, LINE,
@@ -35,4 +33,6 @@ public class ResourceFormat extends IdOnlyEntity {
JSON_LINE, JSON_LINE,
CSV, CSV,
} }
public abstract Type getFormatType();
} }

View File

@@ -22,4 +22,9 @@ public class ApiResourceType extends ResourceType {
private String url; private String url;
private String username; private String username;
private String password; private String password;
@Override
public Type getResourceType() {
return Type.API;
}
} }

View File

@@ -26,9 +26,14 @@ public class DatabaseResourceType extends ResourceType {
private String password; private String password;
@Column(nullable = false) @Column(nullable = false)
@Enumerated(EnumType.STRING) @Enumerated(EnumType.STRING)
private Type type; private DatabaseType databaseType;
public enum Type { @Override
public Type getResourceType() {
return Type.DATABASE;
}
public enum DatabaseType {
MYSQL, MYSQL,
POSTGRESQL, POSTGRESQL,
ORACLE, ORACLE,

View File

@@ -1,7 +1,8 @@
package com.eshore.gringotts.web.domain.resource.entity.type; package com.eshore.gringotts.web.domain.resource.entity.type;
import com.eshore.gringotts.core.Constants; 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.Entity;
import javax.persistence.Table; import javax.persistence.Table;
import lombok.AllArgsConstructor; import lombok.AllArgsConstructor;
@@ -18,6 +19,12 @@ import lombok.ToString;
@Entity @Entity
@Table(name = Constants.TABLE_PREFIX + "resource_type_file") @Table(name = Constants.TABLE_PREFIX + "resource_type_file")
public class FileResourceType extends ResourceType { public class FileResourceType extends ResourceType {
@Column(nullable = false) @OneToOne
private String path; @JoinColumn(nullable = false, foreignKey = @ForeignKey(ConstraintMode.NO_CONSTRAINT))
private DataFile file;
@Override
public Type getResourceType() {
return Type.FILE;
}
} }

View File

@@ -24,4 +24,9 @@ public class FtpResourceType extends ResourceType {
private String password; private String password;
private String path; private String path;
private String regexFilter; private String regexFilter;
@Override
public Type getResourceType() {
return Type.FTP;
}
} }

View File

@@ -1,7 +1,8 @@
package com.eshore.gringotts.web.domain.resource.entity.type; package com.eshore.gringotts.web.domain.resource.entity.type;
import com.eshore.gringotts.core.Constants; 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.Entity;
import javax.persistence.Table; import javax.persistence.Table;
import lombok.AllArgsConstructor; import lombok.AllArgsConstructor;
@@ -18,8 +19,15 @@ import lombok.ToString;
@Entity @Entity
@Table(name = Constants.TABLE_PREFIX + "resource_type_hdfs") @Table(name = Constants.TABLE_PREFIX + "resource_type_hdfs")
public class HDFSResourceType extends ResourceType { public class HDFSResourceType extends ResourceType {
@Column(nullable = false) @OneToOne
private String coreSite; @JoinColumn(nullable = false, foreignKey = @ForeignKey(ConstraintMode.NO_CONSTRAINT))
@Column(nullable = false) private DataFile coreSite;
private String hdfsSite; @OneToOne
@JoinColumn(nullable = false, foreignKey = @ForeignKey(ConstraintMode.NO_CONSTRAINT))
private DataFile hdfsSite;
@Override
public Type getResourceType() {
return Type.HDFS;
}
} }

View File

@@ -1,7 +1,7 @@
package com.eshore.gringotts.web.domain.resource.entity.type; package com.eshore.gringotts.web.domain.resource.entity.type;
import com.eshore.gringotts.core.Constants; 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.Entity;
import javax.persistence.Inheritance; import javax.persistence.Inheritance;
import javax.persistence.InheritanceType; import javax.persistence.InheritanceType;
@@ -22,5 +22,14 @@ import lombok.ToString;
@Entity @Entity
@Table(name = Constants.TABLE_PREFIX + "resource_type") @Table(name = Constants.TABLE_PREFIX + "resource_type")
@Inheritance(strategy = InheritanceType.JOINED) @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,
}
} }