Column

Unique name and type

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:

  1. DataBase column name
    to communicate with database
  2. Java field name
    A key into Entity map
  3. Object Type
    Class Type for column values
  4. Relation to Entity
    Which Entity contains the column.
    This information is generic, provided through Class type during Entity initialisation.


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());
            }
        };
    }

}

 

© Copyright 2018-2023 Elephant Software Klaudiusz Wojtkowiak 
e-mail: contact@daobab.io