From e55eae854ec23ef0999e6c910927d3f0982a7309 Mon Sep 17 00:00:00 2001 From: Struchkov Mark Date: Thu, 17 Feb 2022 16:19:18 +0300 Subject: [PATCH] release-0.0.3 --- pom.xml | 2 +- .../fieldconstants/annotation/FieldNames.java | 3 +++ .../annotation/setting/TableModeSettings.java | 7 +++++ .../processor/FieldNameProcessor.java | 26 +++++++++++++------ src/main/java/module-info.java | 3 ++- 5 files changed, 31 insertions(+), 10 deletions(-) create mode 100644 src/main/java/dev/struchkov/haiti/utils/fieldconstants/annotation/setting/TableModeSettings.java diff --git a/pom.xml b/pom.xml index 2d0678a..7ef785e 100644 --- a/pom.xml +++ b/pom.xml @@ -11,7 +11,7 @@ dev.struchkov.haiti.utils haiti-utils-field-constants - 0.0.3-SNAPSHOT + 0.0.3 Haiti Field Name Constants Utils Generating class field names diff --git a/src/main/java/dev/struchkov/haiti/utils/fieldconstants/annotation/FieldNames.java b/src/main/java/dev/struchkov/haiti/utils/fieldconstants/annotation/FieldNames.java index a574944..110b788 100644 --- a/src/main/java/dev/struchkov/haiti/utils/fieldconstants/annotation/FieldNames.java +++ b/src/main/java/dev/struchkov/haiti/utils/fieldconstants/annotation/FieldNames.java @@ -1,5 +1,6 @@ package dev.struchkov.haiti.utils.fieldconstants.annotation; +import dev.struchkov.haiti.utils.fieldconstants.annotation.setting.TableModeSettings; import dev.struchkov.haiti.utils.fieldconstants.domain.Mode; import java.lang.annotation.ElementType; @@ -13,4 +14,6 @@ public @interface FieldNames { Mode[] mode() default {Mode.SIMPLE}; + TableModeSettings tableSettings() default @TableModeSettings(prefixTableForColumn = false); + } diff --git a/src/main/java/dev/struchkov/haiti/utils/fieldconstants/annotation/setting/TableModeSettings.java b/src/main/java/dev/struchkov/haiti/utils/fieldconstants/annotation/setting/TableModeSettings.java new file mode 100644 index 0000000..1b6414a --- /dev/null +++ b/src/main/java/dev/struchkov/haiti/utils/fieldconstants/annotation/setting/TableModeSettings.java @@ -0,0 +1,7 @@ +package dev.struchkov.haiti.utils.fieldconstants.annotation.setting; + +public @interface TableModeSettings { + + boolean prefixTableForColumn(); + +} diff --git a/src/main/java/dev/struchkov/haiti/utils/fieldconstants/processor/FieldNameProcessor.java b/src/main/java/dev/struchkov/haiti/utils/fieldconstants/processor/FieldNameProcessor.java index 17119b8..e5fda18 100644 --- a/src/main/java/dev/struchkov/haiti/utils/fieldconstants/processor/FieldNameProcessor.java +++ b/src/main/java/dev/struchkov/haiti/utils/fieldconstants/processor/FieldNameProcessor.java @@ -6,6 +6,7 @@ import dev.struchkov.haiti.utils.fieldconstants.annotation.FieldNames; import dev.struchkov.haiti.utils.fieldconstants.annotation.field.ElementCollectionField; import dev.struchkov.haiti.utils.fieldconstants.annotation.field.IgnoreField; import dev.struchkov.haiti.utils.fieldconstants.annotation.field.JoinField; +import dev.struchkov.haiti.utils.fieldconstants.annotation.setting.TableModeSettings; import dev.struchkov.haiti.utils.fieldconstants.domain.Mode; import dev.struchkov.haiti.utils.fieldconstants.domain.mode.table.ClassTableDto; import dev.struchkov.haiti.utils.fieldconstants.domain.mode.table.JoinElemCollectionDto; @@ -26,6 +27,7 @@ import javax.persistence.CollectionTable; import javax.persistence.Column; import javax.persistence.ElementCollection; import javax.persistence.Table; +import java.util.ArrayList; import java.util.Arrays; import java.util.List; import java.util.Set; @@ -47,14 +49,15 @@ public class FieldNameProcessor extends AbstractProcessor { final Set modes = Arrays.stream(settings.mode()).collect(Collectors.toUnmodifiableSet()); if (modes.contains(Mode.TABLE)) { - generateTableMode(annotatedElement, mirror, annotatedElementName); + final TableModeSettings tableSettings = settings.tableSettings(); + generateTableMode(tableSettings, annotatedElement, mirror, annotatedElementName); } } } return true; } - private void generateTableMode(Element annotatedElement, TypeMirror mirror, String annotatedElementName) { + private void generateTableMode(TableModeSettings tableSettings, Element annotatedElement, TypeMirror mirror, String annotatedElementName) { final Table anTable = annotatedElement.getAnnotation(Table.class); final String newClassName = annotatedElementName + Mode.TABLE.getDefaultPostfix(); @@ -63,7 +66,7 @@ public class FieldNameProcessor extends AbstractProcessor { .filter(this::isNotIgnoreField) .collect(Collectors.toList()); - final List simpleFields = getSimpleFields(allFields); + final List simpleFields = getSimpleFields(allFields, anTable, tableSettings); final List joinFields = getJoinFields(allFields); final List elementCollectionFields = getElementCollectionsFields(allFields); @@ -111,19 +114,26 @@ public class FieldNameProcessor extends AbstractProcessor { .collect(Collectors.toList()); } - private List getSimpleFields(List allFields) { - return allFields.stream() + private List getSimpleFields(List allFields, Table anTable, TableModeSettings tableSettings) { + final boolean prefixTableForColumn = tableSettings.prefixTableForColumn(); + final List resultList = new ArrayList<>(); + allFields.stream() .filter( field -> field.getAnnotation(Column.class) != null && field.getAnnotation(ElementCollection.class) == null ) - .map( + .forEach( field -> { final String fieldName = field.getSimpleName().toString(); final String columnName = field.getAnnotation(Column.class).name(); - return SimpleFieldTableDto.of(fieldName, columnName); + if (prefixTableForColumn) { + final String tableNameAndColumnName = anTable.name() + "." + columnName; + resultList.add(SimpleFieldTableDto.of("t_" + fieldName, tableNameAndColumnName)); + } + resultList.add(SimpleFieldTableDto.of(fieldName, columnName)); } - ).collect(Collectors.toList()); + ); + return resultList; } private boolean isNotIgnoreField(Element element) { diff --git a/src/main/java/module-info.java b/src/main/java/module-info.java index dea9191..5d6736f 100644 --- a/src/main/java/module-info.java +++ b/src/main/java/module-info.java @@ -1,7 +1,8 @@ module haiti.utils.fieldconstants { exports dev.struchkov.haiti.utils.fieldconstants.annotation; - exports dev.struchkov.haiti.utils.fieldconstants.domain; exports dev.struchkov.haiti.utils.fieldconstants.annotation.field; + exports dev.struchkov.haiti.utils.fieldconstants.annotation.setting; + exports dev.struchkov.haiti.utils.fieldconstants.domain; requires java.compiler; requires com.google.auto.service;