Package org.mybatis.generator.api
Class MyBatisGenerator
java.lang.Object
org.mybatis.generator.api.MyBatisGenerator
This class is the main interface to MyBatis generator. A typical execution of the tool involves these steps:
- Create a Configuration object. The Configuration can be the result of a parsing the XML configuration file, or it can be created solely in Java.
- Create a MyBatisGenerator object
- Call one of the generate() methods
- See Also:
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final Configurationprivate final List<GeneratedJavaFile> private final List<GeneratedKotlinFile> private final List<GeneratedXmlFile> private static final ProgressCallbackprivate final List<GeneratedFile> Any kind of generated file generated by plugin methods contextGenerateAdditionalFiles.private final ShellCallback -
Constructor Summary
ConstructorsConstructorDescriptionMyBatisGenerator(Configuration configuration, ShellCallback shellCallback, List<String> warnings) Constructs a MyBatisGenerator object. -
Method Summary
Modifier and TypeMethodDescriptionvoidgenerate(ProgressCallback callback) This is the main method for generating code.voidgenerate(ProgressCallback callback, Set<String> contextIds) This is the main method for generating code.voidThis is the main method for generating code.voidgenerate(ProgressCallback callback, Set<String> contextIds, Set<String> fullyQualifiedTableNames, boolean writeFiles) This is the main method for generating code.Returns the list of generated Java files after a call to one of the generate methods.Returns the list of generated Kotlin files after a call to one of the generate methods.Returns the list of generated XML files after a call to one of the generate methods.private FilegetUniqueFileName(File directory, String fileName) Gets the unique file name.private voidWrites, or overwrites, the contents of the specified file.private voidwriteGeneratedFile(GeneratedFile gf, ProgressCallback callback) private voidwriteGeneratedJavaFile(GeneratedJavaFile gjf, ProgressCallback callback) private voidwriteGeneratedXmlFile(GeneratedXmlFile gxf, ProgressCallback callback)
-
Field Details
-
NULL_PROGRESS_CALLBACK
-
configuration
-
shellCallback
-
generatedJavaFiles
-
generatedXmlFiles
-
generatedKotlinFiles
-
otherGeneratedFiles
Any kind of generated file generated by plugin methods contextGenerateAdditionalFiles. -
warnings
-
projects
-
-
Constructor Details
-
MyBatisGenerator
public MyBatisGenerator(Configuration configuration, ShellCallback shellCallback, List<String> warnings) throws InvalidConfigurationException Constructs a MyBatisGenerator object.- Parameters:
configuration- The configuration for this invocationshellCallback- an instance of a ShellCallback interface. You may specifynullin which case the DefaultShellCallback will be used.warnings- Any warnings generated during execution will be added to this list. Warnings do not affect the running of the tool, but they may affect the results. A typical warning is an unsupported data type. In that case, the column will be ignored and generation will continue. You may specifynullif you do not want warnings returned.- Throws:
InvalidConfigurationException- if the specified configuration is invalid
-
-
Method Details
-
generate
public void generate(ProgressCallback callback) throws SQLException, IOException, InterruptedException This is the main method for generating code. This method is long running, but progress can be provided and the method can be canceled through the ProgressCallback interface. This version of the method runs all configured contexts.- Parameters:
callback- an instance of the ProgressCallback interface, ornullif you do not require progress information- Throws:
SQLException- the SQL exceptionIOException- Signals that an I/O exception has occurred.InterruptedException- if the method is canceled through the ProgressCallback
-
generate
public void generate(ProgressCallback callback, Set<String> contextIds) throws SQLException, IOException, InterruptedException This is the main method for generating code. This method is long running, but progress can be provided and the method can be canceled through the ProgressCallback interface.- Parameters:
callback- an instance of the ProgressCallback interface, ornullif you do not require progress informationcontextIds- a set of Strings containing context ids to run. Only the contexts with an id specified in this list will be run. If the list is null or empty, than all contexts are run.- Throws:
SQLException- the SQL exceptionIOException- Signals that an I/O exception has occurred.InterruptedException- if the method is canceled through the ProgressCallback
-
generate
public void generate(ProgressCallback callback, Set<String> contextIds, Set<String> fullyQualifiedTableNames) throws SQLException, IOException, InterruptedException This is the main method for generating code. This method is long running, but progress can be provided and the method can be cancelled through the ProgressCallback interface.- Parameters:
callback- an instance of the ProgressCallback interface, ornullif you do not require progress informationcontextIds- a set of Strings containing context ids to run. Only the contexts with an id specified in this list will be run. If the list is null or empty, than all contexts are run.fullyQualifiedTableNames- a set of table names to generate. The elements of the set must be Strings that exactly match what's specified in the configuration. For example, if table name = "foo" and schema = "bar", then the fully qualified table name is "foo.bar". If the Set is null or empty, then all tables in the configuration will be used for code generation.- Throws:
SQLException- the SQL exceptionIOException- Signals that an I/O exception has occurred.InterruptedException- if the method is canceled through the ProgressCallback
-
generate
public void generate(ProgressCallback callback, Set<String> contextIds, Set<String> fullyQualifiedTableNames, boolean writeFiles) throws SQLException, IOException, InterruptedException This is the main method for generating code. This method is long running, but progress can be provided and the method can be cancelled through the ProgressCallback interface.- Parameters:
callback- an instance of the ProgressCallback interface, ornullif you do not require progress informationcontextIds- a set of Strings containing context ids to run. Only the contexts with an id specified in this list will be run. If the list is null or empty, than all contexts are run.fullyQualifiedTableNames- a set of table names to generate. The elements of the set must be Strings that exactly match what's specified in the configuration. For example, if table name = "foo" and schema = "bar", then the fully qualified table name is "foo.bar". If the Set is null or empty, then all tables in the configuration will be used for code generation.writeFiles- if true, then the generated files will be written to disk. If false, then the generator runs but nothing is written- Throws:
SQLException- the SQL exceptionIOException- Signals that an I/O exception has occurred.InterruptedException- if the method is canceled through the ProgressCallback
-
writeGeneratedJavaFile
private void writeGeneratedJavaFile(GeneratedJavaFile gjf, ProgressCallback callback) throws InterruptedException, IOException - Throws:
InterruptedExceptionIOException
-
writeGeneratedFile
private void writeGeneratedFile(GeneratedFile gf, ProgressCallback callback) throws InterruptedException, IOException - Throws:
InterruptedExceptionIOException
-
writeGeneratedXmlFile
private void writeGeneratedXmlFile(GeneratedXmlFile gxf, ProgressCallback callback) throws InterruptedException, IOException - Throws:
InterruptedExceptionIOException
-
writeFile
Writes, or overwrites, the contents of the specified file.- Parameters:
file- the filecontent- the contentfileEncoding- the file encoding- Throws:
IOException- Signals that an I/O exception has occurred.
-
getUniqueFileName
Gets the unique file name.- Parameters:
directory- the directoryfileName- the file name- Returns:
- the unique file name
-
getGeneratedJavaFiles
Returns the list of generated Java files after a call to one of the generate methods. This is useful if you prefer to process the generated files yourself and do not want the generator to write them to disk.- Returns:
- the list of generated Java files
-
getGeneratedKotlinFiles
Returns the list of generated Kotlin files after a call to one of the generate methods. This is useful if you prefer to process the generated files yourself and do not want the generator to write them to disk.- Returns:
- the list of generated Kotlin files
-
getGeneratedXmlFiles
Returns the list of generated XML files after a call to one of the generate methods. This is useful if you prefer to process the generated files yourself and do not want the generator to write them to disk.- Returns:
- the list of generated XML files
-