Class GenericDataProvider

java.lang.Object
org.fastnate.data.files.GenericDataProvider
All Implemented Interfaces:
DataProvider
Direct Known Subclasses:
GenericXmlDataProvider

public abstract class GenericDataProvider extends Object implements DataProvider
Imports all entities from all files in $dataFolder/entities that match a specific pattern. The subclasses define the pattern (and type) of the imported files.
Author:
Tobias Liefke
  • Constructor Details

    • GenericDataProvider

      public GenericDataProvider()
  • Method Details

    • buildEntities

      public void buildEntities() throws IOException
      Description copied from interface: DataProvider
      Builds the entities that are accessed later using DataProvider.writeEntities(EntitySqlGenerator).
      Specified by:
      buildEntities in interface DataProvider
      Throws:
      IOException - if something happens during any possible import of the generated entities
    • findEntityClass

      protected org.fastnate.generator.context.EntityClass<?> findEntityClass(DataFile importFile)
      Tries to guess the class of the imported entities from the file or directory name. If the file name matches an entity name, that entity class is returned, otherwise the directory tree is walked up until the root is found or an entity name is found.
      Parameters:
      importFile - the file that is imported
      Returns:
      the class according to the file or directory name
    • importFile

      protected abstract Collection<?> importFile(DataFile importFile) throws DataImportException, IOException
      Tries to import the given file.
      Parameters:
      importFile - the file that contains the entities
      Returns:
      the imported entities or null if the file was not imported
      Throws:
      IOException - if the file was not accessible
      DataImportException - if the file content was invalid
    • isImportFile

      protected abstract boolean isImportFile(DataFile file)
      Indicates that the given file is imported. Most implementations will check the suffix of the file.
      Parameters:
      file - the file to check
      Returns:
      true if that file needs to be imported by this data provider
    • writeEntities

      public void writeEntities(org.fastnate.generator.EntitySqlGenerator sqlGenerator) throws IOException
      Description copied from interface: DataProvider
      Adds all entities to the SQL file using the given generator.
      Specified by:
      writeEntities in interface DataProvider
      Parameters:
      sqlGenerator - the SQL file generator
      Throws:
      IOException - if the generator throws one
    • getContext

      protected org.fastnate.generator.context.GeneratorContext getContext()
      The context of the current generator, with the description of the entity classes and settings.
    • getEntityRegistration

      protected EntityRegistration getEntityRegistration()
      Contains all already discovered entities with their unique property.