Jac4e

Annotation processor to improve Enums usage in JPA

Лицензия

Лицензия

Группа

Группа

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

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

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

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

0.0.5
Дата

Дата

Тип

Тип

pom
Описание

Описание

Jac4e
Annotation processor to improve Enums usage in JPA
Ссылка на сайт

Ссылка на сайт

https://github.com/microtweak/jac4e
Система контроля версий

Система контроля версий

https://github.com/microtweak/jac4e

Скачать jac4e

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

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

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

Зависимости

Библиотека не имеет зависимостей. Это самодостаточное приложение, которое не зависит ни от каких других библиотек.

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

  • core
  • processor
  • test

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