Daobab Column is a base interface, representing DataBase column, being a part of table.
Each column, identified by name and type has own interface created. Entity class inretites as many column interfaces as the related database table has column.
This construction help to recreate the relations between tables. For example when a table has a PrimaryKey and an other table has a ForeignKey to first table, both inherites the same column.
Column interface exposes proper getter and setter to the column value.
Each column-related table is generated by Daobab generator. Contains an unique name and is located into column package.
Apart of getter and setter, the interface expose a method with 'col' prefix which provides a cached object describing the real column and Java related objects such as:
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());
}
};
}
}