Class GenerateTableDaoClasses
java.lang.Object
com.northconcepts.datapipeline.foundations.tools.GenerateTableDaoClasses
A utility class for generating data access Java beans using the metadata from a live database.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classThe class name, package and output file used to generate the class for one table. -
Constructor Summary
ConstructorsConstructorDescriptionGenerateTableDaoClasses(JdbcConnection jdbcConnection, File baseFolder, String targetPackage) -
Method Summary
Modifier and TypeMethodDescriptionaddExcludedTables(String... tables) Adds names of tables to skip, matched exactly against unqualified table names.protected voidaddImports(JavaCodeBuilder code, boolean serializable, boolean recordSerializable, List<String> implementsList) Adds a generated class's imports, and the interfaces it implements toimplementsList; the flags tell if the superclass is alreadySerializableorRecordSerializable.protected GenerateTableDaoClasses.TableConfigcreateTableConfig(JdbcTable table) Creates the class name, package and file settings used to generate a table's class; override to change them per table.voidGenerates a data access class for each non-excluded table matching the givenDatabaseMetaData.getTablesarguments; when writing files, code below the custom code marker comment of an existing file is kept.Class<?> Returns the superclass of the generated entities, or null for none; the fields, getters and setters it already declares are reused.Returns the names of the tables to skip, matched exactly against unqualified table names.Returns the writer that receives the generated source when not writing files (standard output if not set).booleanIndicates if the catalog is left out of the generated@Tableannotation (default false).booleanIndicates if the schema is left out of the generated@Tableannotation (default false).booleanIndicates if each generated entity includes a TemplateMasterFORM_DEFdescribing its columns (default false).booleanIndicates if entity class names are made singular, such asCustomerfor acustomerstable (default false).booleanIndicates if generated setters clean text values with the Jsoup basic whitelist to remove unsafe HTML (default false).booleanReturns whether to use database identifiers as display names in generated form definitions.booleanIndicates if generated classes are written as files under the base folder instead of printed to the print writer (default true).setEntitySuperClass(Class<?> entitySuperClass) Sets the superclass of the generated entities, or null for none; the fields, getters and setters it already declares are reused.setExcludeCatalogAnnotation(boolean excludeCatalogAnnotation) Indicates if the catalog is left out of the generated@Tableannotation (default false).setExcludeSchemaAnnotation(boolean excludeSchemaAnnotation) Indicates if the schema is left out of the generated@Tableannotation (default false).setIncludeTemplateMasterFormDef(boolean includeTemplateMasterFormDef) Indicates if each generated entity includes a TemplateMasterFORM_DEFdescribing its columns (default false).setMakeIdentifiersSingular(boolean makeIdentifiersSingular) Indicates if entity class names are made singular, such asCustomerfor acustomerstable (default false).setPrintWriter(PrintWriter printWriter) Sets the writer that receives the generated source when not writing files (standard output if not set).setSanitizeInput(boolean sanitizeInput) Indicates if generated setters clean text values with the Jsoup basic whitelist to remove unsafe HTML (default false).setUseDatabaseIdentifiersAsDisplayNames(boolean useDatabaseIdentifiersAsDisplayNames) Sets whether to use database identifiers as display names in generated form definitions.setWriteToFile(boolean writeToFile) Indicates if generated classes are written as files under the base folder instead of printed to the print writer (default true).
-
Constructor Details
-
GenerateTableDaoClasses
public GenerateTableDaoClasses(JdbcConnection jdbcConnection, File baseFolder, String targetPackage)
-
-
Method Details
-
isMakeIdentifiersSingular
public boolean isMakeIdentifiersSingular()Indicates if entity class names are made singular, such asCustomerfor acustomerstable (default false). -
setMakeIdentifiersSingular
Indicates if entity class names are made singular, such asCustomerfor acustomerstable (default false). -
getEntitySuperClass
Returns the superclass of the generated entities, or null for none; the fields, getters and setters it already declares are reused. -
setEntitySuperClass
Sets the superclass of the generated entities, or null for none; the fields, getters and setters it already declares are reused. -
isExcludeCatalogAnnotation
public boolean isExcludeCatalogAnnotation()Indicates if the catalog is left out of the generated@Tableannotation (default false). -
setExcludeCatalogAnnotation
Indicates if the catalog is left out of the generated@Tableannotation (default false). -
isExcludeSchemaAnnotation
public boolean isExcludeSchemaAnnotation()Indicates if the schema is left out of the generated@Tableannotation (default false). -
setExcludeSchemaAnnotation
Indicates if the schema is left out of the generated@Tableannotation (default false). -
getExcludedTables
Returns the names of the tables to skip, matched exactly against unqualified table names. -
addExcludedTables
Adds names of tables to skip, matched exactly against unqualified table names. -
isSanitizeInput
public boolean isSanitizeInput()Indicates if generated setters clean text values with the Jsoup basic whitelist to remove unsafe HTML (default false). -
setSanitizeInput
Indicates if generated setters clean text values with the Jsoup basic whitelist to remove unsafe HTML (default false). -
isIncludeTemplateMasterFormDef
public boolean isIncludeTemplateMasterFormDef()Indicates if each generated entity includes a TemplateMasterFORM_DEFdescribing its columns (default false). -
setIncludeTemplateMasterFormDef
public GenerateTableDaoClasses setIncludeTemplateMasterFormDef(boolean includeTemplateMasterFormDef) Indicates if each generated entity includes a TemplateMasterFORM_DEFdescribing its columns (default false). -
isUseDatabaseIdentifiersAsDisplayNames
public boolean isUseDatabaseIdentifiersAsDisplayNames()Returns whether to use database identifiers as display names in generated form definitions.When
true, the actual database column names are used as display names. Whenfalse(default), Java-style class names are used as display names.- Returns:
trueif database identifiers should be used as display names,falseotherwise
-
setUseDatabaseIdentifiersAsDisplayNames
public GenerateTableDaoClasses setUseDatabaseIdentifiersAsDisplayNames(boolean useDatabaseIdentifiersAsDisplayNames) Sets whether to use database identifiers as display names in generated form definitions.When
true, the actual database column names are used as display names. Whenfalse(default), Java-style class names are used as display names.- Parameters:
useDatabaseIdentifiersAsDisplayNames-trueto use database identifiers as display names,falseotherwise- Returns:
- this instance for method chaining
-
generate
public void generate(String catalog, String schemaPattern, String tableNamePattern, String... types) Generates a data access class for each non-excluded table matching the givenDatabaseMetaData.getTablesarguments; when writing files, code below the custom code marker comment of an existing file is kept. -
createTableConfig
Creates the class name, package and file settings used to generate a table's class; override to change them per table. -
addImports
protected void addImports(JavaCodeBuilder code, boolean serializable, boolean recordSerializable, List<String> implementsList) Adds a generated class's imports, and the interfaces it implements toimplementsList; the flags tell if the superclass is alreadySerializableorRecordSerializable. -
getPrintWriter
Returns the writer that receives the generated source when not writing files (standard output if not set). -
setPrintWriter
Sets the writer that receives the generated source when not writing files (standard output if not set). -
isWriteToFile
public boolean isWriteToFile()Indicates if generated classes are written as files under the base folder instead of printed to the print writer (default true). -
setWriteToFile
Indicates if generated classes are written as files under the base folder instead of printed to the print writer (default true).
-