Skip to content

Commit 9af493a

Browse files
authored
Merge pull request #39 from Mom0aut/update-jdk21
updated to jdk 21 and bumped all spring updated to the latest lts
2 parents 30626c9 + 8095fad commit 9af493a

10 files changed

Lines changed: 150 additions & 102 deletions

File tree

.github/workflows/maven-pr.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,10 @@ jobs:
1616
with:
1717
token: ${{ secrets.GITHUB_TOKEN || secrets.TOKEN}}
1818
fetch-depth: 0
19-
- name: Set up JDK 17
19+
- name: Set up JDK 21
2020
uses: actions/setup-java@v3
2121
with:
22-
java-version: '17'
22+
java-version: '21'
2323
distribution: 'temurin'
2424
cache: maven
2525
- name: Build with Maven

.github/workflows/maven.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,10 @@ jobs:
1818
with:
1919
token: ${{ secrets.TOKEN}}
2020
fetch-depth: 0
21-
- name: Set up JDK 17
21+
- name: Set up JDK 21
2222
uses: actions/setup-java@v3
2323
with:
24-
java-version: '17'
24+
java-version: '21'
2525
distribution: 'temurin'
2626
cache: maven
2727
- name: Build with Maven
Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,18 @@
11
package at.drm.dao;
22

3+
import at.drm.model.RelationIdentity;
34
import at.drm.model.RelationLink;
5+
import java.util.List;
46
import org.springframework.data.repository.CrudRepository;
57
import org.springframework.data.repository.NoRepositoryBean;
68

7-
import java.util.List;
8-
99
@NoRepositoryBean
1010
public interface RelationDao<DRM extends RelationLink, L extends Long> extends CrudRepository<DRM, L> {
1111

12-
RelationLink findBySourceObjectAndTargetIdAndTargetType(Object sourceObject, Long targetId, String targetType);
12+
RelationLink findBySourceObjectAndTargetIdAndTargetType(RelationIdentity sourceObject, Long targetId,
13+
String targetType);
1314

14-
List<RelationLink> findBySourceObject(Object sourceObject);
15+
List<RelationLink> findBySourceObject(RelationIdentity sourceObject);
1516

1617
List<RelationLink> findByTargetIdAndTargetType(Long targetId, String targetType);
1718
}

dynamic-relations/src/main/java/at/drm/processor/ReleationProcessor.java

Lines changed: 69 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -5,20 +5,41 @@
55
import at.drm.model.RelationLink;
66
import at.drm.model.RelationMetaData;
77
import com.google.auto.service.AutoService;
8-
import com.squareup.javapoet.*;
9-
import jakarta.persistence.*;
10-
11-
import javax.annotation.processing.*;
8+
import com.squareup.javapoet.AnnotationSpec;
9+
import com.squareup.javapoet.ClassName;
10+
import com.squareup.javapoet.CodeBlock;
11+
import com.squareup.javapoet.FieldSpec;
12+
import com.squareup.javapoet.JavaFile;
13+
import com.squareup.javapoet.MethodSpec;
14+
import com.squareup.javapoet.ParameterizedTypeName;
15+
import com.squareup.javapoet.TypeName;
16+
import com.squareup.javapoet.TypeSpec;
17+
import com.squareup.javapoet.TypeVariableName;
18+
import jakarta.persistence.Column;
19+
import jakarta.persistence.Entity;
20+
import jakarta.persistence.GeneratedValue;
21+
import jakarta.persistence.GenerationType;
22+
import jakarta.persistence.Id;
23+
import jakarta.persistence.JoinColumn;
24+
import jakarta.persistence.ManyToOne;
25+
import jakarta.persistence.Table;
26+
import jakarta.persistence.UniqueConstraint;
27+
import java.io.IOException;
28+
import java.util.LinkedHashSet;
29+
import java.util.Set;
30+
import javax.annotation.processing.AbstractProcessor;
31+
import javax.annotation.processing.Filer;
32+
import javax.annotation.processing.Messager;
33+
import javax.annotation.processing.ProcessingEnvironment;
34+
import javax.annotation.processing.Processor;
35+
import javax.annotation.processing.RoundEnvironment;
1236
import javax.lang.model.SourceVersion;
1337
import javax.lang.model.element.Element;
1438
import javax.lang.model.element.Modifier;
1539
import javax.lang.model.element.TypeElement;
1640
import javax.lang.model.type.MirroredTypeException;
1741
import javax.lang.model.type.TypeMirror;
1842
import javax.tools.Diagnostic;
19-
import java.io.IOException;
20-
import java.util.LinkedHashSet;
21-
import java.util.Set;
2243

2344
@AutoService(Processor.class)
2445
public class ReleationProcessor extends AbstractProcessor {
@@ -40,15 +61,15 @@ public Set<String> getSupportedAnnotationTypes() {
4061
Set<String> annotations = new LinkedHashSet<>();
4162
annotations.add(Relation.class.getCanonicalName());
4263
processingEnv.getMessager()
43-
.printMessage(Diagnostic.Kind.NOTE, "getSupportedAnnotationTypes: "
44-
+ annotations);
64+
.printMessage(Diagnostic.Kind.NOTE, "getSupportedAnnotationTypes: "
65+
+ annotations);
4566
return annotations;
4667
}
4768

4869
@Override
4970
public SourceVersion getSupportedSourceVersion() {
5071
processingEnv.getMessager().printMessage(Diagnostic.Kind.NOTE, "getSupportedSourceVersion");
51-
return SourceVersion.RELEASE_17;
72+
return SourceVersion.RELEASE_21;
5273
}
5374

5475
@Override
@@ -68,7 +89,7 @@ public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment
6889
private RelationMetaData createEntityMetaData(Element relationElement) {
6990
Relation relationAnnotation = relationElement.getAnnotation(Relation.class);
7091
String elementPackage = processingEnv.getElementUtils()
71-
.getPackageOf(relationElement).getQualifiedName().toString();
92+
.getPackageOf(relationElement).getQualifiedName().toString();
7293
TypeName sourceObjectName = getSourceObjectTypeName(relationAnnotation);
7394
String sourceObjectWithoutPackages = sourceObjectName.toString().replace(elementPackage + ".", "");
7495
String generatedEntityName = sourceObjectWithoutPackages + "Relation";
@@ -80,13 +101,14 @@ private void createDynamicRelationDao(RelationMetaData entityMetaData) {
80101
String generatedName = entityMetaData.generatedName();
81102
ClassName entityClassName = ClassName.get(packageName, generatedName);
82103
TypeName longTypeName = TypeVariableName.get(Long.class);
83-
TypeSpec relationDao = TypeSpec.interfaceBuilder(entityMetaData.generatedName().replace("Relation", "RelationDao"))
84-
.addModifiers(Modifier.PUBLIC)
85-
.addSuperinterface(
86-
ParameterizedTypeName.get(ClassName.get(RelationDao.class), entityClassName, longTypeName))
87-
.build();
104+
TypeSpec relationDao = TypeSpec.interfaceBuilder(
105+
entityMetaData.generatedName().replace("Relation", "RelationDao"))
106+
.addModifiers(Modifier.PUBLIC)
107+
.addSuperinterface(
108+
ParameterizedTypeName.get(ClassName.get(RelationDao.class), entityClassName, longTypeName))
109+
.build();
88110
JavaFile javaFileDao = JavaFile.builder(packageName, relationDao)
89-
.build();
111+
.build();
90112
createJavaClass(javaFileDao);
91113
}
92114

@@ -152,26 +174,26 @@ private void createDynamicRelationEntity(RelationMetaData entityMetaData) {
152174
.build())
153175
.build();
154176
JavaFile entityJavaFile = JavaFile.builder(packageName, relationEntity)
155-
.build();
177+
.build();
156178
createJavaClass(entityJavaFile);
157179
}
158180

159181
private static FieldSpec createTargetTypeField() {
160182
return FieldSpec.builder(String.class, "targetType", Modifier.PRIVATE)
161-
.addAnnotation(AnnotationSpec.builder(Column.class)
162-
.addMember("name", "$S", "target_type")
163-
.addMember("nullable", "$L", false)
164-
.build())
165-
.build();
183+
.addAnnotation(AnnotationSpec.builder(Column.class)
184+
.addMember("name", "$S", "target_type")
185+
.addMember("nullable", "$L", false)
186+
.build())
187+
.build();
166188
}
167189

168190
private static FieldSpec createTargetIdField() {
169191
return FieldSpec.builder(Long.class, "targetId", Modifier.PRIVATE)
170-
.addAnnotation(AnnotationSpec.builder(Column.class)
171-
.addMember("name", "$S", "target_id")
172-
.addMember("nullable", "$L", false)
173-
.build())
174-
.build();
192+
.addAnnotation(AnnotationSpec.builder(Column.class)
193+
.addMember("name", "$S", "target_id")
194+
.addMember("nullable", "$L", false)
195+
.build())
196+
.build();
175197
}
176198

177199
private TypeName getSourceObjectTypeName(Relation annotation) {
@@ -182,48 +204,48 @@ private TypeName getSourceObjectTypeName(Relation annotation) {
182204

183205
private FieldSpec createSourceObjectField(TypeName typeName) {
184206
return FieldSpec.builder(typeName, "sourceObject", Modifier.PRIVATE)
185-
.addAnnotation(ManyToOne.class)
186-
.addAnnotation(createJoinColumnAnnotaion())
187-
.build();
207+
.addAnnotation(ManyToOne.class)
208+
.addAnnotation(createJoinColumnAnnotaion())
209+
.build();
188210
}
189211

190212
private FieldSpec createIdAnnotation() {
191213
return FieldSpec.builder(Long.class, "id", Modifier.PRIVATE)
192-
.addAnnotation(Id.class)
193-
.addAnnotation(createGeneratedValueAnnotation())
194-
.build();
214+
.addAnnotation(Id.class)
215+
.addAnnotation(createGeneratedValueAnnotation())
216+
.build();
195217
}
196218

197219
private AnnotationSpec createJoinColumnAnnotaion() {
198220
return AnnotationSpec.builder(JoinColumn.class)
199-
.addMember("name", "$S", "source_object")
200-
.build();
221+
.addMember("name", "$S", "source_object")
222+
.build();
201223
}
202224

203225
private AnnotationSpec createGeneratedValueAnnotation() {
204226
return AnnotationSpec.builder(GeneratedValue.class)
205-
.addMember("strategy", "$T.$L", GenerationType.class, GenerationType.IDENTITY.name())
206-
.build();
227+
.addMember("strategy", "$T.$L", GenerationType.class, GenerationType.IDENTITY.name())
228+
.build();
207229
}
208230

209231
private AnnotationSpec createTableAnnotation(String generatedName) {
210232
return AnnotationSpec.builder(Table.class)
211-
.addMember("name", "$S", generatedName)
212-
.addMember("uniqueConstraints", CodeBlock.builder()
213-
.add("{ @$T(name = " + "\"unique_$L\", columnNames = " +
214-
"{ \"target_id\", \"target_type\",\"source_object\" })}",
215-
UniqueConstraint.class, generatedName)
216-
.build())
217-
.build();
233+
.addMember("name", "$S", generatedName)
234+
.addMember("uniqueConstraints", CodeBlock.builder()
235+
.add("{ @$T(name = " + "\"unique_$L\", columnNames = " +
236+
"{ \"target_id\", \"target_type\",\"source_object\" })}",
237+
UniqueConstraint.class, generatedName)
238+
.build())
239+
.build();
218240
}
219241

220242
private void createJavaClass(JavaFile javaFile) {
221243
try {
222244
javaFile.writeTo(filer);
223245
} catch (IOException e) {
224246
processingEnv.getMessager()
225-
.printMessage(Diagnostic.Kind.ERROR, "ERROR ON write file: " +
226-
e.getMessage());
247+
.printMessage(Diagnostic.Kind.ERROR, "ERROR ON write file: " +
248+
e.getMessage());
227249
}
228250
}
229251

dynamic-relations/src/main/java/at/drm/service/RelationService.java

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,14 @@
55
import at.drm.factory.RelationDaoFactory;
66
import at.drm.model.RelationIdentity;
77
import at.drm.model.RelationLink;
8+
import java.util.HashSet;
9+
import java.util.List;
10+
import java.util.Set;
811
import lombok.NonNull;
9-
import lombok.RequiredArgsConstructor;
1012
import org.springframework.beans.BeanUtils;
1113
import org.springframework.core.ResolvableType;
1214
import org.springframework.stereotype.Service;
1315

14-
import java.util.HashSet;
15-
import java.util.List;
16-
import java.util.Set;
17-
1816
@Service
1917
public class RelationService {
2018

@@ -28,7 +26,7 @@ public RelationLink createRelation(@NonNull Object sourceObject, @NonNull Relati
2826
Long targetId = targetObect.getId();
2927
String targetType = targetObect.getType();
3028
RelationDao<RelationLink, Long> daoFromSourceObject =
31-
relationDaoFactory.getDaoFromSourceObjectClass(sourceObject.getClass());
29+
relationDaoFactory.getDaoFromSourceObjectClass(sourceObject.getClass());
3230
RelationLink relationLink = createRelationModelFromGenericParameter(daoFromSourceObject);
3331
relationLink.setSourceObject(sourceObject);
3432
relationLink.setTargetId(targetId);
@@ -38,36 +36,38 @@ public RelationLink createRelation(@NonNull Object sourceObject, @NonNull Relati
3836

3937
public void deleteRelation(RelationLink relationLink) {
4038
RelationDao<RelationLink, Long> daoFromSourceObjectClass =
41-
relationDaoFactory.getDaoFromSourceObjectClass(relationLink.getSourceObject().getClass());
39+
relationDaoFactory.getDaoFromSourceObjectClass(relationLink.getSourceObject().getClass());
4240
daoFromSourceObjectClass.delete(relationLink);
4341
}
4442

45-
public RelationLink findRelationBySourceObjectAndRelationIdentity(@NonNull Object sourceObject, @NonNull RelationIdentity targetObect) {
43+
public RelationLink findRelationBySourceObjectAndRelationIdentity(@NonNull RelationIdentity sourceObject,
44+
@NonNull RelationIdentity targetObect) {
4645
RelationDao<RelationLink, Long> daoFromSourceObject =
47-
relationDaoFactory.getDaoFromSourceObjectClass(sourceObject.getClass());
46+
relationDaoFactory.getDaoFromSourceObjectClass(sourceObject.getClass());
4847
RelationLink relationLink = daoFromSourceObject.
49-
findBySourceObjectAndTargetIdAndTargetType(sourceObject, targetObect.getId(), targetObect.getType());
48+
findBySourceObjectAndTargetIdAndTargetType(sourceObject, targetObect.getId(), targetObect.getType());
5049
return relationLink;
5150
}
5251

53-
public List<RelationLink> findRelationBySourceObject(@NonNull Object sourceObject) {
52+
public List<RelationLink> findRelationBySourceObject(@NonNull RelationIdentity sourceObject) {
5453
RelationDao<RelationLink, Long> daoFromSourceObject =
55-
relationDaoFactory.getDaoFromSourceObjectClass(sourceObject.getClass());
54+
relationDaoFactory.getDaoFromSourceObjectClass(sourceObject.getClass());
5655
List<RelationLink> relationLinks = daoFromSourceObject.findBySourceObject(sourceObject);
5756
return relationLinks;
5857
}
5958

6059
public Set<RelationLink> findRelationByTargetRelationIdentity(@NonNull RelationIdentity targetObect) {
6160
Set<RelationDao> allDaos = relationDaoFactory.getAllDaos();
6261
Set<RelationLink> relations = new HashSet<>();
63-
allDaos.forEach(dao -> relations.addAll(dao.findByTargetIdAndTargetType(targetObect.getId(), targetObect.getType())));
62+
allDaos.forEach(
63+
dao -> relations.addAll(dao.findByTargetIdAndTargetType(targetObect.getId(), targetObect.getType())));
6464
return relations;
6565
}
6666

6767
private static RelationLink createRelationModelFromGenericParameter(RelationDao<RelationLink,
68-
Long> daoFromSourceObjectClass) {
68+
Long> daoFromSourceObjectClass) {
6969
ResolvableType resolvableType = ResolvableType.forClass(daoFromSourceObjectClass.getClass())
70-
.as(RelationDao.class);
70+
.as(RelationDao.class);
7171
ResolvableType generic = resolvableType.getGeneric(0);
7272
Class<?> resolve = generic.resolve();
7373
return (RelationLink) BeanUtils.instantiateClass(resolve);

dynamic-relations/src/test/java/at/drm/processor/ReleationProcessorTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ void getSupportedSourceVersion() {
5252
Mockito.when(processingEnvironment.getMessager()).thenReturn(messager);
5353
releationProcessorUnderTest.init(processingEnvironment);
5454
SourceVersion supportedSourceVersion = releationProcessorUnderTest.getSupportedSourceVersion();
55-
assertThat(supportedSourceVersion).isEqualTo(SourceVersion.RELEASE_17);
55+
assertThat(supportedSourceVersion).isEqualTo(SourceVersion.RELEASE_21);
5656
}
5757

5858
@Test

jacoco-report/pom.xml

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<?xml version="1.0" encoding="UTF-8"?>
22
<project xmlns="http://maven.apache.org/POM/4.0.0"
3-
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4-
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
3+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
55
<parent>
66
<groupId>io.github.Mom0aut</groupId>
77
<artifactId>jdr</artifactId>
@@ -15,7 +15,6 @@
1515
<code.coverage.project.folder>${basedir}/../</code.coverage.project.folder>
1616
<code.coverage.overall.data.folder>${basedir}/../target/aggregate.exec</code.coverage.overall.data.folder>
1717
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
18-
<jacoco-maven-plugin.version>0.8.8</jacoco-maven-plugin.version>
1918
</properties>
2019

2120
<dependencies>

0 commit comments

Comments
 (0)