/** * Validates that a table definition (annotated, interface, or both) matches the current state of * the table and indexes in the database. Results are returned as a list of validation remarks * which includes recommendations, warnings, and errors about the model. The caller may choose to * have validate throw an exception on any validation ERROR. * * @param def the table definition * @param throwError whether or not to throw an exception if an error was found * @return a list if validation remarks */ <T> List<ValidationRemark> validate(TableDefinition<T> def, boolean throwError) { List<ValidationRemark> remarks = Utils.newArrayList(); // model class definition validation if (!Modifier.isPublic(def.getModelClass().getModifiers())) { remarks.add( error( table, "SCHEMA", format("Class {0} MUST BE PUBLIC!", def.getModelClass().getCanonicalName())) .throwError(throwError)); } // Schema Validation if (!isNullOrEmpty(schema)) { if (isNullOrEmpty(def.schemaName)) { remarks.add( consider( table, "SCHEMA", format("@{0}(\"{1}\")", IQSchema.class.getSimpleName(), schema))); } else if (!schema.equalsIgnoreCase(def.schemaName)) { remarks.add( error( table, "SCHEMA", format( "@{0}(\"{1}\") != {2}", IQSchema.class.getSimpleName(), def.schemaName, schema)) .throwError(throwError)); } } // index validation for (IndexInspector index : indexes.values()) { validate(remarks, def, index, throwError); } // field column validation for (FieldDefinition fieldDef : def.getFields()) { validate(remarks, fieldDef, throwError); } return remarks; }