com.founder.core.base.BaseDo Maven / Gradle / Ivy
package com.founder.core.base;
import javax.persistence.Id;
import javax.persistence.Table;
import java.io.Serializable;
import java.lang.reflect.Field;
import java.lang.reflect.ParameterizedType;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import static java.util.stream.Collectors.toList;
public class BaseDo implements Serializable{
private Class entity;
private String tableName;
private List fields;
private List whereFields;
private List primaryKeyList;
private ArrayList selectList = new ArrayList<>();
private ArrayList insertList = new ArrayList<>();
private ArrayList updateList = new ArrayList<>();
private ArrayList deleteList = new ArrayList<>();
public String getTableName() {
return tableName;
}
public void setTableName(String tableName) {
this.tableName = tableName;
}
public List getFields() {
return fields;
}
public List getWhereFields() {
return whereFields;
}
public List getprimaryKeyList() {
return primaryKeyList;
}
public void setprimaryKeyList(List primaryKeyList) {
this.primaryKeyList = primaryKeyList;
}
public ArrayList getSelectList() {
return selectList;
}
public ArrayList getInsertList() {
return insertList;
}
public ArrayList getUpdateList() {
return updateList;
}
public ArrayList getDeleteList() {
return deleteList;
}
public void setDeleteList(ArrayList deleteList) {
this.deleteList = deleteList;
}
public BaseDo() {
entity = (Class) ((ParameterizedType) this.getClass().getGenericSuperclass())
.getActualTypeArguments()[0];
if (this.entity != null) {
Table table = entity.getAnnotation(Table.class);
if (table != null) {
setTableName(table.name());
}
Field[] declaredFields = entity.getDeclaredFields();
primaryKeyList = Arrays.stream(declaredFields).filter(x->{
Id id =x.getAnnotation(Id.class);
return id !=null;
}).map(x->x.getName()).collect(toList());
fields = Arrays.stream(declaredFields).map(f -> {
BaseFieldInfo fieldInfo = new BaseFieldInfo();
fieldInfo.setFieldName(f.getName());
fieldInfo.setFieldKind(f.getType().getSimpleName().toString());
return fieldInfo;
}).collect(toList());
Arrays.stream(declaredFields).filter(
f-> f.getAnnotation(Table.class) != null
).map(f->f.getName()).collect(toList());
}
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy