release-0.0.3

This commit is contained in:
Struchkov Mark 2022-02-17 16:19:18 +03:00
parent bedeb1a51e
commit e55eae854e
5 changed files with 31 additions and 10 deletions

View File

@ -11,7 +11,7 @@
<groupId>dev.struchkov.haiti.utils</groupId> <groupId>dev.struchkov.haiti.utils</groupId>
<artifactId>haiti-utils-field-constants</artifactId> <artifactId>haiti-utils-field-constants</artifactId>
<version>0.0.3-SNAPSHOT</version> <version>0.0.3</version>
<name>Haiti Field Name Constants Utils</name> <name>Haiti Field Name Constants Utils</name>
<description>Generating class field names</description> <description>Generating class field names</description>

View File

@ -1,5 +1,6 @@
package dev.struchkov.haiti.utils.fieldconstants.annotation; 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 dev.struchkov.haiti.utils.fieldconstants.domain.Mode;
import java.lang.annotation.ElementType; import java.lang.annotation.ElementType;
@ -13,4 +14,6 @@ public @interface FieldNames {
Mode[] mode() default {Mode.SIMPLE}; Mode[] mode() default {Mode.SIMPLE};
TableModeSettings tableSettings() default @TableModeSettings(prefixTableForColumn = false);
} }

View File

@ -0,0 +1,7 @@
package dev.struchkov.haiti.utils.fieldconstants.annotation.setting;
public @interface TableModeSettings {
boolean prefixTableForColumn();
}

View File

@ -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.ElementCollectionField;
import dev.struchkov.haiti.utils.fieldconstants.annotation.field.IgnoreField; 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.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;
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;
@ -26,6 +27,7 @@ import javax.persistence.CollectionTable;
import javax.persistence.Column; import javax.persistence.Column;
import javax.persistence.ElementCollection; import javax.persistence.ElementCollection;
import javax.persistence.Table; import javax.persistence.Table;
import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
import java.util.List; import java.util.List;
import java.util.Set; import java.util.Set;
@ -47,14 +49,15 @@ public class FieldNameProcessor extends AbstractProcessor {
final Set<Mode> modes = Arrays.stream(settings.mode()).collect(Collectors.toUnmodifiableSet()); final Set<Mode> modes = Arrays.stream(settings.mode()).collect(Collectors.toUnmodifiableSet());
if (modes.contains(Mode.TABLE)) { if (modes.contains(Mode.TABLE)) {
generateTableMode(annotatedElement, mirror, annotatedElementName); final TableModeSettings tableSettings = settings.tableSettings();
generateTableMode(tableSettings, annotatedElement, mirror, annotatedElementName);
} }
} }
} }
return true; 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 Table anTable = annotatedElement.getAnnotation(Table.class);
final String newClassName = annotatedElementName + Mode.TABLE.getDefaultPostfix(); final String newClassName = annotatedElementName + Mode.TABLE.getDefaultPostfix();
@ -63,7 +66,7 @@ public class FieldNameProcessor extends AbstractProcessor {
.filter(this::isNotIgnoreField) .filter(this::isNotIgnoreField)
.collect(Collectors.toList()); .collect(Collectors.toList());
final List<SimpleFieldTableDto> simpleFields = getSimpleFields(allFields); final List<SimpleFieldTableDto> simpleFields = getSimpleFields(allFields, anTable, tableSettings);
final List<JoinFieldDto> joinFields = getJoinFields(allFields); final List<JoinFieldDto> joinFields = getJoinFields(allFields);
final List<JoinElemCollectionDto> elementCollectionFields = getElementCollectionsFields(allFields); final List<JoinElemCollectionDto> elementCollectionFields = getElementCollectionsFields(allFields);
@ -111,19 +114,26 @@ public class FieldNameProcessor extends AbstractProcessor {
.collect(Collectors.toList()); .collect(Collectors.toList());
} }
private List<SimpleFieldTableDto> getSimpleFields(List<? extends Element> allFields) { private List<SimpleFieldTableDto> getSimpleFields(List<? extends Element> allFields, Table anTable, TableModeSettings tableSettings) {
return allFields.stream() final boolean prefixTableForColumn = tableSettings.prefixTableForColumn();
final List<SimpleFieldTableDto> resultList = new ArrayList<>();
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
) )
.map( .forEach(
field -> { field -> {
final String fieldName = field.getSimpleName().toString(); final String fieldName = field.getSimpleName().toString();
final String columnName = field.getAnnotation(Column.class).name(); 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) { private boolean isNotIgnoreField(Element element) {

View File

@ -1,7 +1,8 @@
module haiti.utils.fieldconstants { module haiti.utils.fieldconstants {
exports dev.struchkov.haiti.utils.fieldconstants.annotation; 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.field;
exports dev.struchkov.haiti.utils.fieldconstants.annotation.setting;
exports dev.struchkov.haiti.utils.fieldconstants.domain;
requires java.compiler; requires java.compiler;
requires com.google.auto.service; requires com.google.auto.service;