Jac4e Test Suite

Annotation processor to improve Enums usage in JPA

Лицензия

Лицензия

Группа

Группа

com.github.microtweak
Идентификатор

Идентификатор

jac4e-test
Последняя версия

Последняя версия

0.0.5
Дата

Дата

Тип

Тип

jar
Описание

Описание

Jac4e Test Suite
Annotation processor to improve Enums usage in JPA

Скачать jac4e-test

Имя Файла Размер
jac4e-test-0.0.5.pom
jac4e-test-0.0.5.jar 1 KB
Обзор

Как подключить последнюю версию

<!-- https://jarcasting.com/artifacts/com.github.microtweak/jac4e-test/ -->
<dependency>
    <groupId>com.github.microtweak</groupId>
    <artifactId>jac4e-test</artifactId>
    <version>0.0.5</version>
</dependency>
// https://jarcasting.com/artifacts/com.github.microtweak/jac4e-test/
implementation 'com.github.microtweak:jac4e-test:0.0.5'
// https://jarcasting.com/artifacts/com.github.microtweak/jac4e-test/
implementation ("com.github.microtweak:jac4e-test:0.0.5")
'com.github.microtweak:jac4e-test:jar:0.0.5'
<dependency org="com.github.microtweak" name="jac4e-test" rev="0.0.5">
  <artifact name="jac4e-test" type="jar" />
</dependency>
@Grapes(
@Grab(group='com.github.microtweak', module='jac4e-test', version='0.0.5')
)
libraryDependencies += "com.github.microtweak" % "jac4e-test" % "0.0.5"
[com.github.microtweak/jac4e-test "0.0.5"]

Зависимости

compile (2)

Идентификатор библиотеки Тип Версия
com.github.microtweak : jac4e-core jar 0.0.5
javax.persistence : javax.persistence-api jar 2.2

provided (1)

Идентификатор библиотеки Тип Версия
org.projectlombok : lombok jar 1.18.8

test (7)

Идентификатор библиотеки Тип Версия
org.junit.jupiter : junit-jupiter-engine jar 5.4.2
org.junit.jupiter : junit-jupiter-params jar 5.4.2
org.hibernate : hibernate-core jar 4.3.11.Final
org.hibernate : hibernate-entitymanager jar 4.3.11.Final
com.h2database : h2 jar 1.4.199
com.github.dadrus.jpa-unit : jpa-unit5 jar 0.5.0
com.github.dadrus.jpa-unit : jpa-unit-rdbms jar 0.5.0

Модули Проекта

Данный проект не имеет модулей.

Jac4e - Jpa Attribute Converter for Enum

Annotation processor to improve Enums usage in JPA.

Problem

JPA 2.1 introduced the AttributeConverter interface allowing the use of custom types in JPA entities. This feature brought an alternative to the well-known @Enumerated.

However, implementing a new AttributeConverter for each enum is a bit annoying and tiring. Even implementing a generic converter, the problem still continues.

Solution

Introduced an annotation processor that generates the implementation of the AttributeConverter for each enum annotated with @EnumAttributeConverter. This implementation uses a property declared in the enum to do the conversion.

Usage

  1. Setup your pom.xml
<project>
    <properties>
        <jac4e.version>0.0.2</jac4e.version>
    </properties>

    <dependencies>
        <!-- Other dependencies -->

        <dependency>
            <groupId>com.github.microtweak</groupId>
            <artifactId>jac4e-core</artifactId>
            <version>${jac4e.version}</version>
        </dependency>
    </dependencies>

    <build>
        <plugins>
            <!-- Other plugins -->

            <plugin>
                <groupId>com.mysema.maven</groupId>
                <artifactId>apt-maven-plugin</artifactId>
                <version>1.1.3</version>
                <dependencies>
                    <dependency>
                        <groupId>com.github.microtweak</groupId>
                        <artifactId>jac4e-processor</artifactId>
                        <version>${jac4e.version}</version>
                    </dependency>
                </dependencies>
                <executions>
                    <execution>
                        <goals>
                            <goal>process</goal>
                        </goals>
                        <configuration>
                            <outputDirectory>target/generated-sources/java</outputDirectory>
                            <processor>com.github.microtweak.jac4e.processor.Jac4eProcessor</processor>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>
</project>
  1. Annotate your enum and create the "value" property. The type and content of this property will be persisted in the database.
@EnumAttributeConverter
public enum Status {

    PENDING('P'),

    SHIPPED('S'),

    COMPLETED('C');

    private char value; // Pay attention: the APT uses it for conversion
    
    Status(char value) {
        this.value = value;
    }
}
  1. Declare the enum in the entity as a common property
@Entity
public class Order {

    @Id
    private Long id;

    private Payment paymentMode; // Now you should NOT use @Enumerated

    private double total;

    // Getters and Setters

}
com.github.microtweak

Microtweak

Small libraries for micro tweaking (or small features) in frameworks you already know

Версии библиотеки

Версия
0.0.5
0.0.4
0.0.3
0.0.2
0.0.1