Daobab Column is a base interface, represented DataBase column, which is a part of table.
The name and context of this library depends of column name and type.
Each column, identified by name and type has own interface created.
Interface may be inherited by every Entity.
This construction recreates relations between tables
Interface collects informations as follows:
public interface Name<E extends EntityMap, F> extends EntityRelationMap<E> {
default F getName() {
return getColumnParam("Name");
}
@SuppressWarnings("unchecked")
default E setName(F val) {
setColumnParam("Name", val);
return (E) this;
}
@SuppressWarnings({"rawtypes","unchecked"})
/*
table:CATEGORY,type:VARCHAR,size:25,nullable:false
table:LANGUAGE,type:VARCHAR,size:20,nullable:false
*/
default Column<E, F, Name> colName() {
return new Column<E, F, Name>() {
@Override
public String getColumnName() {
return "NAME";
}
@Override
public String getFieldName() {
return "Name";
}
@Override
public E getInstance(){
return getEntity();
}
@Override
public Class getFieldClass() {
return String.class;
}
@Override
public F getValue(Name entity) {
if (entity == null) throw new AttemptToReadFromNullEntityException(getEntityClass(), "Name");
return (F) entity.getName();
}
@Override
public void setValue(Name entity, F param) {
if (entity == null) throw new AttemptToWriteIntoNullEntityException(getEntityClass(), "Name");
entity.setName(param);
}
@Override
public int hashCode() {
return toString().hashCode();
}
@Override
public String toString(){
return getEntityName()+"."+getFieldName();
}
@Override
public boolean equals(Object obj)
{
if (this == obj)return true;
if (obj
== null)return false;
if (getClass()
!= obj.getClass())return
false;
Column other = (Column) obj;
return Objects.equals(hashCode(), other.hashCode());
}
};
}
}