Package org.fastnate.data.files
Class GenericDataProvider
java.lang.Object
org.fastnate.data.files.GenericDataProvider
- All Implemented Interfaces:
DataProvider
- Direct Known Subclasses:
GenericXmlDataProvider
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 Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidBuilds the entities that are accessed later usingDataProvider.writeEntities(EntitySqlGenerator).protected org.fastnate.generator.context.EntityClass<?> findEntityClass(DataFile importFile) Tries to guess the class of the imported entities from the file or directory name.protected org.fastnate.generator.context.GeneratorContextThe context of the current generator, with the description of the entity classes and settings.protected EntityRegistrationContains all already discovered entities with their unique property.protected abstract Collection<?> importFile(DataFile importFile) Tries to import the given file.protected abstract booleanisImportFile(DataFile file) Indicates that the given file is imported.voidwriteEntities(org.fastnate.generator.EntitySqlGenerator sqlGenerator) Adds allentitiesto the SQL file using the given generator.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface org.fastnate.data.DataProvider
getOrder
-
Constructor Details
-
GenericDataProvider
public GenericDataProvider()
-
-
Method Details
-
buildEntities
Description copied from interface:DataProviderBuilds the entities that are accessed later usingDataProvider.writeEntities(EntitySqlGenerator).- Specified by:
buildEntitiesin interfaceDataProvider- Throws:
IOException- if something happens during any possible import of the generated entities
-
findEntityClass
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
nullif the file was not imported - Throws:
IOException- if the file was not accessibleDataImportException- if the file content was invalid
-
isImportFile
Indicates that the given file is imported. Most implementations will check the suffix of the file.- Parameters:
file- the file to check- Returns:
trueif 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:DataProviderAdds allentitiesto the SQL file using the given generator.- Specified by:
writeEntitiesin interfaceDataProvider- 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
Contains all already discovered entities with their unique property.
-