Newer
Older
import com.ic.er.Exception.ERException;
import com.ic.er.common.RelatedObjType;
import com.ic.er.common.DataType;
import com.ic.er.common.Utils;
import lombok.Getter;
import org.apache.ibatis.exceptions.PersistenceException;
import java.util.Date;
import java.util.List;
private Long ID;
private String name;
private Long viewID;
private List<Attribute> attributeList;
protected Entity(Long ID, String name, Long viewID, List<Attribute> attributeList, LayoutInfo layoutInfo, Double layoutX, Double layoutY, Date gmtCreate, Date gmtModified) {
this.ID = ID;
this.name = name;
this.viewID = viewID;
this.attributeList = attributeList;
this.gmtCreate = gmtCreate;
this.gmtModified = gmtModified;
if (this.ID == 0) {
if (ER.useDB) {
this.layoutInfo = new LayoutInfo(0L, this.ID, RelatedObjType.ENTITY, layoutX, layoutY, 0.0, 0.0);
public Attribute addAttribute(String attributeName, DataType dataType, int isPrimary) {
Attribute attribute = new Attribute(0L, this.ID, this.viewID, attributeName, dataType, isPrimary, null, 0.0, 0.0, new Date(), new Date());
this.attributeList.add(attribute);
return attribute;
}
public Attribute addAttribute(String attributeName, DataType dataType, int isPrimary, Double layoutX, Double layoutY) {
Attribute attribute = new Attribute(0L, this.ID, this.viewID, attributeName, dataType, isPrimary, null, layoutX, layoutY, new Date(), new Date());
this.attributeList.add(attribute);
return attribute;
}
this.attributeList.remove(attribute);
if (ER.useDB) {
private void insertDB() {
try {
EntityDO entityDO = new EntityDO(0L, this.name, this.viewID, 0, this.gmtCreate, this.gmtModified);
int ret = ER.entityMapper.insert(entityDO);
if (ret == 0) {
throw new ERException("insertDB fail");
}
this.ID = entityDO.getID();
} catch (PersistenceException e) {
throw new ERException("insertDB fail", e);
}
for (Attribute attribute : attributeList) {
attribute.deleteDB();
}
public void updateInfo(String name) throws ERException {
if (name != null) {
this.name = name;
}
int ret = ER.entityMapper.updateByID(new EntityDO(this.ID, this.name, this.viewID, 0, this.gmtCreate, new Date()));
if (ret == 0) {
throw new ERException(String.format("cannot find Attribute with ID: %d", this.ID));
public void updateLayoutInfo(Double layoutX, Double layoutY, Double height, Double width) {
this.layoutInfo.update(layoutX, layoutY, height, width);
}
public static List<Entity> queryByEntity(EntityDO entityDO) {
List<EntityDO> entityDOList = ER.entityMapper.selectByEntity(entityDO);
return Trans.TransEntityListFormFromDB(entityDOList);
}
public static Entity queryByID(Long ID) {
List<Entity> entityDOList = queryByEntity(new EntityDO(ID));
if (entityDOList.size() == 0) {
throw new ERException(String.format("Entity with ID: %d not found ", ID));
} else {
return entityDOList.get(0);
}
}