You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

240 lines
5.1 KiB

6 years ago
package xyz.wbsite.dbtool.javafx.po;
import javafx.scene.control.TreeItem;
import xyz.wbsite.dbtool.javafx.manger.ManagerFactory;
import xyz.wbsite.dbtool.javafx.manger.ProjectManager;
6 years ago
import xyz.wbsite.dbtool.javafx.tool.Tool;
import java.util.ArrayList;
import java.util.List;
public class Table extends TreeItem {
private Module dBhandle;
public Table() {
}
public Table(String tableName) {
this.tableName = tableName;
setValue(tableName);
setExpanded(true);
}
public Table(String tableName, String tableComment) {
this.tableName = tableName;
this.tableComment = tableComment;
setValue(tableName);
setExpanded(true);
6 years ago
}
/**
*
*/
private String tableName;
/**
*
*/
private String tableComment;
6 years ago
private boolean create = true;
private boolean delete = true;
private boolean update = true;
private boolean find = true;
private boolean get = true;
private boolean search = false;
5 years ago
private boolean html = false;
private boolean sys = true;
6 years ago
/**
*
*/
private List<Field> fields = new ArrayList();
public boolean has(String type) {
for (Field field : fields) {
if (field.getFieldType().name().equals(type) && !field.getIsSystem()) {
return true;
}
}
return false;
}
public String getImport() {
StringBuilder sb = new StringBuilder("");
if (has("Date")) {
sb.append("import java.util.Date;\n");
}
if (has("BigDecimal")) {
sb.append("import java.math.BigDecimal;\n");
}
return sb.toString();
}
public boolean putField(Field field) {
if (fields == null) {
fields = new ArrayList<Field>();
}
fields.add(field);
return true;
}
public boolean putFirstField(Field field) {
if (fields == null) {
fields = new ArrayList<Field>();
}
fields.add(0, field);
return true;
}
public String getCName() {
return Tool.ABB2Abb(this.tableName);
6 years ago
}
public String getFName() {
return Tool.lineToFieldName(this.tableName);
}
public String getLName() {
return Tool.lineToLPoint(this.tableName);
}
public String getTableName() {
return tableName;
}
public void setTableName(String tableName) {
this.tableName = tableName;
setValue(tableName);
}
public String getTableComment() {
return tableComment;
}
public void setTableComment(String tableComment) {
6 years ago
this.tableComment = tableComment != null ? tableComment : "";
6 years ago
}
public List<Field> getFields() {
return fields;
}
public void setFields(List<Field> fields) {
this.fields = fields;
}
public Module getdBhandle() {
return dBhandle;
}
public void setdBhandle(Module dBhandle) {
this.dBhandle = dBhandle;
}
6 years ago
public boolean getCreate() {
return create;
6 years ago
}
6 years ago
public void setCreate(boolean create) {
6 years ago
this.create = create;
}
6 years ago
public boolean getDelete() {
return delete;
6 years ago
}
6 years ago
public void setDelete(boolean delete) {
6 years ago
this.delete = delete;
}
6 years ago
public boolean getUpdate() {
return update;
6 years ago
}
6 years ago
public void setUpdate(boolean update) {
6 years ago
this.update = update;
}
6 years ago
public boolean getFind() {
return find;
6 years ago
}
6 years ago
public void setFind(boolean find) {
6 years ago
this.find = find;
}
6 years ago
public boolean getGet() {
return get;
6 years ago
}
6 years ago
public void setGet(boolean get) {
6 years ago
this.get = get;
}
6 years ago
public boolean getSearch() {
return search;
6 years ago
}
6 years ago
public void setSearch(boolean search) {
6 years ago
this.search = search;
}
5 years ago
public boolean getHtml() {
return html;
}
public void setHtml(boolean html) {
this.html = html;
}
public boolean getSys() {
return sys;
}
public void setSys(boolean sys) {
this.sys = sys;
ProjectManager projectManager = ManagerFactory.getProjectManager();
if (projectManager != null) projectManager.checkSysFields(this);
}
public boolean hasPrimaryKey() {
for (Field field : fields) {
if (field.getIsPrimaryKey()) {
return true;
}
}
return false;
}
public List<Field> primaryKeyList() {
ArrayList<Field> list = new ArrayList<>();
for (Field field : this.fields) {
if (field.getIsPrimaryKey()) {
list.add(field);
}
}
return list;
}
public List<Field> searchKeyList() {
ArrayList<Field> list = new ArrayList<>();
for (Field field : this.fields) {
if (field.getIsSearch()) {
list.add(field);
}
}
return list;
}
public boolean hasSearchKey() {
for (Field field : fields) {
if (field.getIsSearch()) {
return true;
}
}
return false;
}
6 years ago
}

Powered by TurnKey Linux.