Добавил генерацию schema-name
This commit is contained in:
parent
59ce9db326
commit
5dc69b034f
@ -1,6 +1,5 @@
|
|||||||
package dev.struchkov.haiti.utils.fieldconstants.creator;
|
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.ClassTableDto;
|
||||||
import dev.struchkov.haiti.utils.fieldconstants.domain.mode.table.JoinElemCollectionDto;
|
import dev.struchkov.haiti.utils.fieldconstants.domain.mode.table.JoinElemCollectionDto;
|
||||||
import dev.struchkov.haiti.utils.fieldconstants.domain.mode.table.JoinFieldDto;
|
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_DEFAULT = "TABLE_NAME";
|
||||||
private static final String TABLE_NAME_DB = "DB_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() {
|
private CreatorClassTableMode() {
|
||||||
utilityClass();
|
utilityClass();
|
||||||
}
|
}
|
||||||
@ -35,7 +39,7 @@ public final class CreatorClassTableMode {
|
|||||||
public static void record(ClassTableDto classDto, ProcessingEnvironment environment) {
|
public static void record(ClassTableDto classDto, ProcessingEnvironment environment) {
|
||||||
JavaFileObject builderFile = null;
|
JavaFileObject builderFile = null;
|
||||||
try {
|
try {
|
||||||
builderFile = environment.getFiler().createSourceFile(classDto.getClassPackage() +"." + classDto.getClassName());
|
builderFile = environment.getFiler().createSourceFile(classDto.getClassPackage() + "." + classDto.getClassName());
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
@ -49,6 +53,8 @@ public final class CreatorClassTableMode {
|
|||||||
out.println();
|
out.println();
|
||||||
out.println();
|
out.println();
|
||||||
generateTableName(classDto.getTableName(), classDto.getSimpleFields(), out);
|
generateTableName(classDto.getTableName(), classDto.getSimpleFields(), out);
|
||||||
|
generateTableSchema(classDto.getTableSchema(), classDto.getSimpleFields(), out);
|
||||||
|
generateTableSchemaAndTable(classDto.getTableSchema(), classDto.getTableName(), out);
|
||||||
generateSimpleNames(classDto.getSimpleFields(), out);
|
generateSimpleNames(classDto.getSimpleFields(), out);
|
||||||
generateJoinNames(classDto.getJoinFields(), out);
|
generateJoinNames(classDto.getJoinFields(), out);
|
||||||
generateElementCollectionNames(classDto.getJoinElemCollections(), out);
|
generateElementCollectionNames(classDto.getJoinElemCollections(), out);
|
||||||
@ -69,11 +75,26 @@ public final class CreatorClassTableMode {
|
|||||||
if (tableName != null) {
|
if (tableName != null) {
|
||||||
final boolean isTableNameField = fields.stream().anyMatch(simpleFieldTableDto -> simpleFieldTableDto.getFieldStringName().equalsIgnoreCase(TABLE_NAME_DEFAULT));
|
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(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) {
|
private static void generateSimpleNames(Collection<SimpleTableFieldDto> fields, PrintWriter out) {
|
||||||
|
if (checkNotEmpty(fields)) {
|
||||||
|
out.println();
|
||||||
|
}
|
||||||
for (SimpleTableFieldDto field : fields) {
|
for (SimpleTableFieldDto field : fields) {
|
||||||
out.println(format(" public static final String {0} = \"{1}\";", field.getFieldStringName(), field.getFieldName()));
|
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) {
|
private static void generateJoinNames(List<JoinFieldDto> joinFields, PrintWriter out) {
|
||||||
|
if (checkNotEmpty(joinFields)) {
|
||||||
|
out.println();
|
||||||
|
}
|
||||||
for (JoinFieldDto joinField : joinFields) {
|
for (JoinFieldDto joinField : joinFields) {
|
||||||
final JoinTableContainer container = joinField.getContainer();
|
final JoinTableContainer container = joinField.getContainer();
|
||||||
out.println(
|
out.println(
|
||||||
@ -98,6 +122,9 @@ public final class CreatorClassTableMode {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private static void generateElementCollectionNames(List<JoinElemCollectionDto> joinElemCollections, PrintWriter out) {
|
private static void generateElementCollectionNames(List<JoinElemCollectionDto> joinElemCollections, PrintWriter out) {
|
||||||
|
if (checkNotEmpty(joinElemCollections)) {
|
||||||
|
out.println();
|
||||||
|
}
|
||||||
for (JoinElemCollectionDto element : joinElemCollections) {
|
for (JoinElemCollectionDto element : joinElemCollections) {
|
||||||
final String fieldName = element.getFieldName();
|
final String fieldName = element.getFieldName();
|
||||||
final JoinTableContainer firstContainer = element.getFirstContainer();
|
final JoinTableContainer firstContainer = element.getFirstContainer();
|
||||||
|
@ -7,6 +7,7 @@ public class ClassTableDto {
|
|||||||
private String classPackage;
|
private String classPackage;
|
||||||
private String className;
|
private String className;
|
||||||
private String tableName;
|
private String tableName;
|
||||||
|
private String tableSchema;
|
||||||
private List<SimpleTableFieldDto> simpleFields;
|
private List<SimpleTableFieldDto> simpleFields;
|
||||||
private List<JoinFieldDto> joinFields;
|
private List<JoinFieldDto> joinFields;
|
||||||
private List<JoinElemCollectionDto> joinElemCollections;
|
private List<JoinElemCollectionDto> joinElemCollections;
|
||||||
@ -35,6 +36,14 @@ public class ClassTableDto {
|
|||||||
this.tableName = tableName;
|
this.tableName = tableName;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public String getTableSchema() {
|
||||||
|
return tableSchema;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setTableSchema(String tableSchema) {
|
||||||
|
this.tableSchema = tableSchema;
|
||||||
|
}
|
||||||
|
|
||||||
public List<SimpleTableFieldDto> getSimpleFields() {
|
public List<SimpleTableFieldDto> getSimpleFields() {
|
||||||
return simpleFields;
|
return simpleFields;
|
||||||
}
|
}
|
||||||
|
@ -49,6 +49,7 @@ public class GeneratorTableMode {
|
|||||||
newClass.setJoinElemCollections(elementCollectionFields);
|
newClass.setJoinElemCollections(elementCollectionFields);
|
||||||
newClass.setClassPackage(Generator.getPackage(annotatedElement));
|
newClass.setClassPackage(Generator.getPackage(annotatedElement));
|
||||||
newClass.setTableName(checkNotNull(anTable) ? anTable.name() : null);
|
newClass.setTableName(checkNotNull(anTable) ? anTable.name() : null);
|
||||||
|
newClass.setTableSchema(checkNotNull(anTable) ? anTable.schema() : null);
|
||||||
CreatorClassTableMode.record(newClass, processingEnv);
|
CreatorClassTableMode.record(newClass, processingEnv);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -57,8 +58,8 @@ public class GeneratorTableMode {
|
|||||||
return allFields.stream()
|
return allFields.stream()
|
||||||
.filter(
|
.filter(
|
||||||
field -> field.getAnnotation(ElementCollectionField.class) != null &&
|
field -> field.getAnnotation(ElementCollectionField.class) != null &&
|
||||||
field.getAnnotation(CollectionTable.class) != null &&
|
field.getAnnotation(CollectionTable.class) != null &&
|
||||||
field.getAnnotation(Column.class) != null
|
field.getAnnotation(Column.class) != null
|
||||||
)
|
)
|
||||||
.map(field -> {
|
.map(field -> {
|
||||||
final String fieldName = field.getSimpleName().toString();
|
final String fieldName = field.getSimpleName().toString();
|
||||||
@ -78,7 +79,7 @@ public class GeneratorTableMode {
|
|||||||
return allFields.stream()
|
return allFields.stream()
|
||||||
.filter(
|
.filter(
|
||||||
field -> field.getAnnotation(JoinField.class) != null &&
|
field -> field.getAnnotation(JoinField.class) != null &&
|
||||||
field.getAnnotation(ElementCollection.class) == null
|
field.getAnnotation(ElementCollection.class) == null
|
||||||
)
|
)
|
||||||
.map(field -> {
|
.map(field -> {
|
||||||
final String fieldName = field.getSimpleName().toString();
|
final String fieldName = field.getSimpleName().toString();
|
||||||
@ -95,7 +96,7 @@ public class GeneratorTableMode {
|
|||||||
allFields.stream()
|
allFields.stream()
|
||||||
.filter(
|
.filter(
|
||||||
field -> field.getAnnotation(Column.class) != null &&
|
field -> field.getAnnotation(Column.class) != null &&
|
||||||
field.getAnnotation(ElementCollection.class) == null
|
field.getAnnotation(ElementCollection.class) == null
|
||||||
)
|
)
|
||||||
.forEach(
|
.forEach(
|
||||||
field -> {
|
field -> {
|
||||||
|
Loading…
Reference in New Issue
Block a user