Class SchemaModelValidatorTask

java.lang.Object
ch.tocco.nice2.model.entity.impl.schema.SchemaModelValidatorTask
All Implemented Interfaces:
Callable<SchemaModelValidator.Result>

public class SchemaModelValidatorTask extends Object implements Callable<SchemaModelValidator.Result>
Compares the jdbc metadata against the data model. This class will find matches between the jdbc and the data model and delegate those to contributed SchemaChecks for specific validation. Any missing matches (no table for entity model, no column for fields etc) are reported from within this class. Relation models are iterated through independently since they may be mapped to tables and columns or columns only. Here is the pseudo code, as it explains it better than words:

 T = all_tables
 C = all_columns (prefixed by tablename)
 for em in EntityModels
   table = findTable(em)
   if (table) T-table; triggerCheck(em, table)
   else triggerEvent(em) //no table for entitymodel

   if (table) for fm in em.fields
     col = findColumn(fm)
     if (col) C - col; triggerCheck(fm, col)
     else triggerEvent(fm) //no column for field

 for rm in RelationModels(not-reverse)
   if (rm.isToMany)
     table = findTable(rm.getLink)
     source = findTable(rm.source)
     target = findTable(rm.target)
     if (table & source & target) T-table; triggerCheck(rm, table)
     if (!table) triggerEvent(rm)//no table for relationmodel
   else
     columns = findColumns(rm) //may return too less or no columns
     C - columns; triggerCheck(rm, columns)

 //columns/tables left are unused
 triggerEvent(T); //unused tables
 triggerEvent(C); //unused columns
 
The bodies of the two main for loops may be executed in parallel. All checks are reported using an Reporter. The reporter runs in its own thread waiting for incoming events and delegates them to all contributed Reporters. Events are processed in FIFO manner, there is no defined order for those events.