public class EntityImporter extends Object
DataProvider
and creates one big SQL file for the
generated entities
.Modifier and Type | Field and Description |
---|---|
private GeneratorContext |
context |
static String |
DATA_FOLDER_KEY
Settings key for the folder that contains any data to import.
|
private DataFolder |
dataFolder |
private List<DataProvider> |
dataProviders |
static String |
ENTITY_PACKAGES_KEY
Settings key for the packages to scan for entity classes on startup (separated by ';', ',', ':' or whitespaces).
|
static String |
FACTORY_KEY
Settings key for the fully qualified name of a class that scans and instantiates the
DataProvider . |
static String |
GENERATION_ABORTED_MESSAGE
The String in the SQL, if the generation was aborted.
|
private static org.slf4j.Logger |
log |
static String |
OUTPUT_ENCODING_KEY
Settings key for the encoding of the generated SQL file.
|
static String |
OUTPUT_FILE_KEY
Settings key for the generated SQL file.
|
static String |
PACKAGES_KEY
Settings key for the packages to scan (separated by ';', ',', ':' or whitespaces).
|
static String |
POSTFIX_KEY
Settings key for a part to write into the output file after the generated content.
|
static String |
PREFIX_KEY
Settings key for a part to write into the output file before the generated content.
|
static String |
STATEMENTS_WRITER_KEY
Settings key that indicates the type of the used
StatementsWriter . |
Constructor and Description |
---|
EntityImporter()
Creates a new default instance of an EntityImporter.
|
EntityImporter(GeneratorContext context)
Creates a new instance of an EntityImporter.
|
EntityImporter(Properties settings)
Creates a new instance of an EntityImporter.
|
Modifier and Type | Method and Description |
---|---|
void |
addDataProvider(DataProvider provider)
Adds a provider to the list of available providers.
|
void |
addDataProvider(DataProvider provider,
int maximumOrderOfDepenendencies)
Adds a provider to the list of available providers.
|
private static DataFolder |
findDataFolder(GeneratorContext context) |
<P extends DataProvider> |
findDataProvider(Class<P> providerClass)
Resolves the first provider that is an instance of the given class.
|
GeneratorContext |
getContext() |
DataFolder |
getDataFolder() |
List<DataProvider> |
getDataProviders() |
private Charset |
getEncoding() |
Properties |
getSettings()
|
void |
importData()
Imports the data and creates the SQL.
|
void |
importData(Connection connection)
Asks the data providers to generate their entities and writes the SQL to a database connection at the end.
|
void |
importData(EntitySqlGenerator generator)
Asks the data providers to generate their entities and writes the SQL afterwards.
|
private void |
importData(EntitySqlGenerator generator,
Connection connection) |
void |
importData(File targetFile)
Imports the data and creates the given SQL file.
|
void |
importData(Writer writer)
Asks the data providers to generate their entities and writes the SQL to a file at the end.
|
static void |
main(String[] args)
Starts the entity importer from the command line.
|
private void |
writePropertyPart(EntitySqlGenerator generator,
String property)
Writes a section from a property to the writer of the SQL generator.
|
@Generated(value="lombok") private static final org.slf4j.Logger log
public static final String GENERATION_ABORTED_MESSAGE
public static final String DATA_FOLDER_KEY
public static final String OUTPUT_FILE_KEY
public static final String OUTPUT_ENCODING_KEY
public static final String PREFIX_KEY
public static final String POSTFIX_KEY
public static final String FACTORY_KEY
DataProvider
.
Defaults to DefaultDataProviderFactory
.public static final String PACKAGES_KEY
public static final String ENTITY_PACKAGES_KEY
public static final String STATEMENTS_WRITER_KEY
StatementsWriter
.
Allowed values of the setting:
GeneratorContext
private final DataFolder dataFolder
private final GeneratorContext context
private final List<DataProvider> dataProviders
public EntityImporter()
public EntityImporter(GeneratorContext context)
context
- the current generator contextpublic EntityImporter(Properties settings)
settings
- the settings of this importer, the data providers and the SQL generatorprivate static DataFolder findDataFolder(GeneratorContext context)
public static void main(String[] args) throws IOException
DATA_FOLDER_KEY
.
EntityImporter(Properties)
or GeneratorContext
with system
properties.args
- the command line arguments (see above)IOException
- the exceptionpublic void addDataProvider(DataProvider provider)
provider
- the providerpublic void addDataProvider(DataProvider provider, int maximumOrderOfDepenendencies)
provider
- the providermaximumOrderOfDepenendencies
- the maximum ordering
of dependencies of the providerpublic <P extends DataProvider> P findDataProvider(Class<P> providerClass)
providerClass
- the provider classnull
if no such provider existsprivate Charset getEncoding()
public Properties getSettings()
public void importData() throws IOException
STATEMENTS_WRITER_KEY
, this will either create a file or execute the SQL
against a connection.IOException
- if one of the data importers or the file writer throws onepublic void importData(Connection connection) throws IOException, SQLException
connection
- the target connection for the SQL statementsSQLException
- if the connection throws an exceptionIOException
- if the generator throws an exceptionpublic void importData(EntitySqlGenerator generator) throws IOException
generator
- the current entity SQL generatorIOException
- if the generator throws an exceptionprivate void importData(EntitySqlGenerator generator, Connection connection) throws SQLException, IOException
SQLException
IOException
public void importData(File targetFile) throws IOException
targetFile
- the SQL file to generateIOException
- if one of the data importers or the file writer throws onepublic void importData(Writer writer) throws IOException
writer
- the target writer for the SQL statementsIOException
- if the generator or writer throws an exceptionprivate void writePropertyPart(EntitySqlGenerator generator, String property) throws IOException
generator
- the current generatorproperty
- name of the property to write, contains either a list of file names (separated by ',' and ending with
".sql"), or an SQL statementIOException
- if the writer or reader throws one@Generated(value="lombok") public DataFolder getDataFolder()
@Generated(value="lombok") public GeneratorContext getContext()
@Generated(value="lombok") public List<DataProvider> getDataProviders()
Copyright © 2022 fastnate.org. All rights reserved.