Добавил генерацию schema-name

This commit is contained in:
Struchkov Mark 2023-01-23 16:41:13 +03:00
parent 59ce9db326
commit 5dc69b034f
Signed by: upagge
GPG Key ID: D3018BE7BA428CA6
3 changed files with 44 additions and 7 deletions

View File

@ -1,6 +1,5 @@
package dev.struchkov.haiti.utils.fieldconstants.creator;
import dev.struchkov.haiti.utils.Checker;
import dev.struchkov.haiti.utils.fieldconstants.domain.mode.table.ClassTableDto;
import dev.struchkov.haiti.utils.fieldconstants.domain.mode.table.JoinElemCollectionDto;
import dev.struchkov.haiti.utils.fieldconstants.domain.mode.table.JoinFieldDto;
@ -28,6 +27,11 @@ public final class CreatorClassTableMode {
private static final String TABLE_NAME_DEFAULT = "TABLE_NAME";
private static final String TABLE_NAME_DB = "DB_TABLE_NAME";
private static final String SCHEMA_NAME_DEFAULT = "SCHEMA_NAME";
private static final String SCHEMA_NAME_DB = "DB_SCHEMA_NAME";
private static final String SCHEMA_AND_TABLE = "SCHEMA_AND_TABLE";
private CreatorClassTableMode() {
utilityClass();
}
@ -35,7 +39,7 @@ public final class CreatorClassTableMode {
public static void record(ClassTableDto classDto, ProcessingEnvironment environment) {
JavaFileObject builderFile = null;
try {
builderFile = environment.getFiler().createSourceFile(classDto.getClassPackage() +"." + classDto.getClassName());
builderFile = environment.getFiler().createSourceFile(classDto.getClassPackage() + "." + classDto.getClassName());
} catch (IOException e) {
e.printStackTrace();
}
@ -49,6 +53,8 @@ public final class CreatorClassTableMode {
out.println();
out.println();
generateTableName(classDto.getTableName(), classDto.getSimpleFields(), out);
generateTableSchema(classDto.getTableSchema(), classDto.getSimpleFields(), out);
generateTableSchemaAndTable(classDto.getTableSchema(), classDto.getTableName(), out);
generateSimpleNames(classDto.getSimpleFields(), out);
generateJoinNames(classDto.getJoinFields(), out);
generateElementCollectionNames(classDto.getJoinElemCollections(), out);
@ -69,11 +75,26 @@ public final class CreatorClassTableMode {
if (tableName != null) {
final boolean isTableNameField = fields.stream().anyMatch(simpleFieldTableDto -> simpleFieldTableDto.getFieldStringName().equalsIgnoreCase(TABLE_NAME_DEFAULT));
out.println(format(" public static final String {0} = \"{1}\";", isTableNameField ? TABLE_NAME_DB : TABLE_NAME_DEFAULT, tableName));
out.println();
}
}
private static void generateTableSchema(String tableSchema, Collection<SimpleTableFieldDto> fields, PrintWriter out) {
if (tableSchema != null && !"".equals(tableSchema)) {
final boolean isTableSchemaField = fields.stream().anyMatch(simpleFieldTableDto -> simpleFieldTableDto.getFieldStringName().equalsIgnoreCase(TABLE_NAME_DEFAULT));
out.println(format(" public static final String {0} = \"{1}\";", isTableSchemaField ? SCHEMA_NAME_DB : SCHEMA_NAME_DEFAULT, tableSchema));
}
}
private static void generateTableSchemaAndTable(String tableSchema, String tableName, PrintWriter out) {
if (tableSchema != null && tableName != null && !"".equals(tableSchema)) {
out.println(format(" public static final String {0} = \"{1}\";", SCHEMA_AND_TABLE, tableSchema + "." + tableName));
}
}
private static void generateSimpleNames(Collection<SimpleTableFieldDto> fields, PrintWriter out) {
if (checkNotEmpty(fields)) {
out.println();
}
for (SimpleTableFieldDto field : fields) {
out.println(format(" public static final String {0} = \"{1}\";", field.getFieldStringName(), field.getFieldName()));
}
@ -83,6 +104,9 @@ public final class CreatorClassTableMode {
}
private static void generateJoinNames(List<JoinFieldDto> joinFields, PrintWriter out) {
if (checkNotEmpty(joinFields)) {
out.println();
}
for (JoinFieldDto joinField : joinFields) {
final JoinTableContainer container = joinField.getContainer();
out.println(
@ -98,6 +122,9 @@ public final class CreatorClassTableMode {
}
private static void generateElementCollectionNames(List<JoinElemCollectionDto> joinElemCollections, PrintWriter out) {
if (checkNotEmpty(joinElemCollections)) {
out.println();
}
for (JoinElemCollectionDto element : joinElemCollections) {
final String fieldName = element.getFieldName();
final JoinTableContainer firstContainer = element.getFirstContainer();

View File

@ -7,6 +7,7 @@ public class ClassTableDto {
private String classPackage;
private String className;
private String tableName;
private String tableSchema;
private List<SimpleTableFieldDto> simpleFields;
private List<JoinFieldDto> joinFields;
private List<JoinElemCollectionDto> joinElemCollections;
@ -35,6 +36,14 @@ public class ClassTableDto {
this.tableName = tableName;
}
public String getTableSchema() {
return tableSchema;
}
public void setTableSchema(String tableSchema) {
this.tableSchema = tableSchema;
}
public List<SimpleTableFieldDto> getSimpleFields() {
return simpleFields;
}

View File

@ -49,6 +49,7 @@ public class GeneratorTableMode {
newClass.setJoinElemCollections(elementCollectionFields);
newClass.setClassPackage(Generator.getPackage(annotatedElement));
newClass.setTableName(checkNotNull(anTable) ? anTable.name() : null);
newClass.setTableSchema(checkNotNull(anTable) ? anTable.schema() : null);
CreatorClassTableMode.record(newClass, processingEnv);
}