Package org.fastnate.data
Class EntityImporter
java.lang.Object
org.fastnate.data.EntityImporter
Main class for importing entities.
Discovers all implementations of
DataProvider and creates one big SQL file for the
generated entities.- Author:
- Andreas Penski, Tobias Liefke
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final StringSettings key for the folder that contains any data to import.static final StringSettings key for the packages to scan for entity classes on startup (separated by ';', ',', ':' or whitespaces).static final StringSettings key for the fully qualified name of a class that scans and instantiates theDataProvider.static final StringThe String in the SQL, if the generation was aborted.static final StringSettings key for the encoding of the generated SQL file.static final StringSettings key for the generated SQL file.static final StringSettings key for the packages to scan (separated by ';', ',', ':' or whitespaces).static final StringSettings key for a part to write into the output file after the generated content.static final StringSettings key for a part to write into the output file before the generated content.static final StringSettings key that indicates the type of the usedStatementsWriter. -
Constructor Summary
ConstructorsConstructorDescriptionCreates a new default instance of an EntityImporter.EntityImporter(Properties settings) Creates a new instance of an EntityImporter.EntityImporter(org.fastnate.generator.context.GeneratorContext context) Creates a new instance of an EntityImporter. -
Method Summary
Modifier and TypeMethodDescriptionvoidaddDataProvider(DataProvider provider) Adds a provider to the list of available providers.voidaddDataProvider(DataProvider provider, int maximumOrderOfDepenendencies) Adds a provider to the list of available providers.<P extends DataProvider>
PfindDataProvider(Class<P> providerClass) Resolves the first provider that is an instance of the given class.org.fastnate.generator.context.GeneratorContextThesettingsof thecontext.voidImports the data and creates the SQL.voidimportData(File targetFile) Imports the data and creates the given SQL file.voidimportData(Writer writer) Asks the data providers to generate their entities and writes the SQL to a file at the end.voidimportData(Connection connection) Asks the data providers to generate their entities and writes the SQL to a database connection at the end.voidimportData(org.fastnate.generator.EntitySqlGenerator generator) Asks the data providers to generate their entities and writes the SQL afterwards.static voidStarts the entity importer from the command line.
-
Field Details
-
GENERATION_ABORTED_MESSAGE
The String in the SQL, if the generation was aborted. Can be used by other utilities that perform further modifications on the generated files.- See Also:
-
DATA_FOLDER_KEY
Settings key for the folder that contains any data to import. May point to a package name, which indicates that the folder is part of the class path. This setting may be overriden by the optional first command line argument of the importer. For importing entities with generic data providers, there has to be an "entities" folder in that folder, which contains the generic data files.- See Also:
-
OUTPUT_FILE_KEY
Settings key for the generated SQL file.- See Also:
-
OUTPUT_ENCODING_KEY
Settings key for the encoding of the generated SQL file.- See Also:
-
PREFIX_KEY
Settings key for a part to write into the output file before the generated content.- See Also:
-
POSTFIX_KEY
Settings key for a part to write into the output file after the generated content.- See Also:
-
FACTORY_KEY
Settings key for the fully qualified name of a class that scans and instantiates theDataProvider. Defaults toDefaultDataProviderFactory.- See Also:
-
PACKAGES_KEY
Settings key for the packages to scan (separated by ';', ',', ':' or whitespaces).- See Also:
-
ENTITY_PACKAGES_KEY
Settings key for the packages to scan for entity classes on startup (separated by ';', ',', ':' or whitespaces).- See Also:
-
STATEMENTS_WRITER_KEY
Settings key that indicates the type of the usedStatementsWriter. Allowed values of the setting:- FileStatementsWriter (default)
- PostgreSqlBulkWriter
- ConnectedStatementsWriter
- LiquibaseStatementsWriter
- any fully qualified class which has a constructor that accepts a
GeneratorContext
- See Also:
-
-
Constructor Details
-
EntityImporter
public EntityImporter()Creates a new default instance of an EntityImporter. -
EntityImporter
public EntityImporter(org.fastnate.generator.context.GeneratorContext context) Creates a new instance of an EntityImporter.- Parameters:
context- the current generator context
-
EntityImporter
Creates a new instance of an EntityImporter.- Parameters:
settings- the settings of this importer, the data providers and the SQL generator
-
-
Method Details
-
main
Starts the entity importer from the command line. Command line arguments:- (optional) the name or path of the generated file - defaults to "data.sql"
- (optional) the path / package of the base folder for reading input files (only used by DataProviders) -
defaults to the setting of
DATA_FOLDER_KEY.
EntityImporter(Properties)orGeneratorContextwith system properties.- Parameters:
args- the command line arguments (see above)- Throws:
IOException- the exception
-
addDataProvider
Adds a provider to the list of available providers. The provider will be added after the last provider with the same or a smaller order criteria.- Parameters:
provider- the provider
-
addDataProvider
Adds a provider to the list of available providers. The provider will be added after the last provider with the same or a smaller order criteria.- Parameters:
provider- the providermaximumOrderOfDepenendencies- the maximumorderingof dependencies of the provider
-
findDataProvider
Resolves the first provider that is an instance of the given class.- Parameters:
providerClass- the provider class- Returns:
- the provider with that class or
nullif no such provider exists
-
getSettings
Thesettingsof thecontext.- Returns:
- settings used by this importer
-
importData
Imports the data and creates the SQL. Depending on the settingSTATEMENTS_WRITER_KEY, this will either create a file or execute the SQL against a connection.- Throws:
IOException- if one of the data importers or the file writer throws one
-
importData
Asks the data providers to generate their entities and writes the SQL to a database connection at the end.- Parameters:
connection- the target connection for the SQL statements- Throws:
SQLException- if the connection throws an exceptionIOException- if the generator throws an exception
-
importData
Asks the data providers to generate their entities and writes the SQL afterwards.- Parameters:
generator- the current entity SQL generator- Throws:
IOException- if the generator throws an exception
-
importData
Imports the data and creates the given SQL file.- Parameters:
targetFile- the SQL file to generate- Throws:
IOException- if one of the data importers or the file writer throws one
-
importData
Asks the data providers to generate their entities and writes the SQL to a file at the end.- Parameters:
writer- the target writer for the SQL statements- Throws:
IOException- if the generator or writer throws an exception
-
getDataFolder
-
getContext
public org.fastnate.generator.context.GeneratorContext getContext() -
getDataProviders
-