From f9853c4e0260170446aaa5d54505fdd5d49dad33 Mon Sep 17 00:00:00 2001 From: Brian Sam-Bodden Date: Wed, 11 Sep 2024 15:52:29 -0700 Subject: [PATCH 1/2] release: 0.9.6-SNAPSHOT --- README.md | 4 ++-- demos/roms-documents/pom.xml | 2 +- demos/roms-hashes/pom.xml | 2 +- demos/roms-permits/pom.xml | 2 +- pom.xml | 2 +- .../src/main/java/com/redis/om/spring/RedisOMProperties.java | 2 +- 6 files changed, 7 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index cb641c84..2c0d1a86 100644 --- a/README.md +++ b/README.md @@ -457,7 +457,7 @@ inherited from the parent poms): com.redis.om redis-om-spring - 0.9.5 + 0.9.6-SNAPSHOT @@ -504,7 +504,7 @@ repositories { ```groovy ext { - redisOmVersion = '0.9.5' + redisOmVersion = '0.9.6-SNAPSHOT' } dependencies { diff --git a/demos/roms-documents/pom.xml b/demos/roms-documents/pom.xml index f7cfd078..284d05e5 100644 --- a/demos/roms-documents/pom.xml +++ b/demos/roms-documents/pom.xml @@ -31,7 +31,7 @@ com.redis.om redis-om-spring - 0.9.5 + 0.9.6-SNAPSHOT org.springframework.boot diff --git a/demos/roms-hashes/pom.xml b/demos/roms-hashes/pom.xml index fc1ae41a..abf4da49 100644 --- a/demos/roms-hashes/pom.xml +++ b/demos/roms-hashes/pom.xml @@ -30,7 +30,7 @@ com.redis.om redis-om-spring - 0.9.5 + 0.9.6-SNAPSHOT org.springframework.boot diff --git a/demos/roms-permits/pom.xml b/demos/roms-permits/pom.xml index 5b81282a..21b7dca1 100644 --- a/demos/roms-permits/pom.xml +++ b/demos/roms-permits/pom.xml @@ -34,7 +34,7 @@ com.redis.om redis-om-spring - 0.9.5 + 0.9.6-SNAPSHOT diff --git a/pom.xml b/pom.xml index df46425f..459f00d0 100644 --- a/pom.xml +++ b/pom.xml @@ -6,7 +6,7 @@ 4.0.0 com.redis.om redis-om-spring-parent - 0.9.5 + 0.9.6-SNAPSHOT redis-om-spring-parent pom diff --git a/redis-om-spring/src/main/java/com/redis/om/spring/RedisOMProperties.java b/redis-om-spring/src/main/java/com/redis/om/spring/RedisOMProperties.java index 1023711e..8ddf875c 100644 --- a/redis-om-spring/src/main/java/com/redis/om/spring/RedisOMProperties.java +++ b/redis-om-spring/src/main/java/com/redis/om/spring/RedisOMProperties.java @@ -12,7 +12,7 @@ prefix = "redis.om.spring", ignoreInvalidFields = true ) public class RedisOMProperties { - public static final String ROMS_VERSION = "0.9.5"; + public static final String ROMS_VERSION = "0.9.6-SNAPSHOT"; public static final int MAX_SEARCH_RESULTS = 10000; public static final double DEFAULT_DISTANCE = 0.0005; public static final Metrics DEFAULT_DISTANCE_METRIC = Metrics.MILES; From 38d2b925ff5040a6152694e00b7e33db0daf1a1a Mon Sep 17 00:00:00 2001 From: Brian Sam-Bodden Date: Wed, 11 Sep 2024 15:53:09 -0700 Subject: [PATCH 2/2] feature: Java 21 support --- .github/workflows/codeql-analysis.yml | 4 +- .github/workflows/integration.yml | 4 +- .github/workflows/snapshot.yml | 4 +- .github/workflows/version-and-release.yml | 2 +- demos/roms-documents/pom.xml | 14 +++--- demos/roms-hashes/pom.xml | 12 +++--- demos/roms-permits/pom.xml | 12 +++--- demos/roms-vss/pom.xml | 14 +++--- pom.xml | 12 +++--- redis-om-spring/pom.xml | 18 ++++---- .../spring/metamodel/MetamodelGenerator.java | 43 +++++++++++++++---- 11 files changed, 83 insertions(+), 56 deletions(-) diff --git a/.github/workflows/codeql-analysis.yml b/.github/workflows/codeql-analysis.yml index 2c5128c8..74168473 100644 --- a/.github/workflows/codeql-analysis.yml +++ b/.github/workflows/codeql-analysis.yml @@ -49,10 +49,10 @@ jobs: # Autobuild attempts to build any compiled languages (C/C++, C#, or Java). # If this step fails, then you should remove it and run the build manually (see below) - - name: Set up JDK 17 + - name: Set up JDK 21 uses: actions/setup-java@v2 with: - java-version: 17 + java-version: 21 distribution: 'zulu' - name: Autobuild uses: github/codeql-action/autobuild@v2 diff --git a/.github/workflows/integration.yml b/.github/workflows/integration.yml index 934e5b82..dea485cb 100644 --- a/.github/workflows/integration.yml +++ b/.github/workflows/integration.yml @@ -21,10 +21,10 @@ jobs: ~/.mv2/repository key: om-${{hashFiles('**/pom.xml')}} - - name: Set up JDK 17 + - name: Set up JDK 21 uses: actions/setup-java@v2 with: - java-version: 17 + java-version: 21 distribution: 'zulu' - run: mvn dependency:go-offline - name: Build diff --git a/.github/workflows/snapshot.yml b/.github/workflows/snapshot.yml index 4cd710d6..144f8a6f 100644 --- a/.github/workflows/snapshot.yml +++ b/.github/workflows/snapshot.yml @@ -23,10 +23,10 @@ jobs: path: | ~/.mv2/repository key: om-${{hashFiles('**/pom.xml')}} - - name: Set up JDK 17 + - name: Set up JDK 21 uses: actions/setup-java@v2 with: - java-version: 17 + java-version: 21 distribution: 'zulu' server-id: ossrh server-username: MAVEN_USERNAME diff --git a/.github/workflows/version-and-release.yml b/.github/workflows/version-and-release.yml index a88e20aa..5e4262d2 100644 --- a/.github/workflows/version-and-release.yml +++ b/.github/workflows/version-and-release.yml @@ -21,7 +21,7 @@ jobs: - name: Set up publishing to maven central uses: actions/setup-java@v2 with: - java-version: 17 + java-version: 21 distribution: 'zulu' server-id: ossrh server-username: MAVEN_USERNAME diff --git a/demos/roms-documents/pom.xml b/demos/roms-documents/pom.xml index 284d05e5..688712d8 100644 --- a/demos/roms-documents/pom.xml +++ b/demos/roms-documents/pom.xml @@ -17,12 +17,12 @@ Redis OM Spring Document Demo - 17 - 17 - 17 - 17 - 17 - 17 + 21 + 21 + 21 + 21 + 21 + 21 true 2.2.2 @@ -141,7 +141,7 @@ com.redis.om redis-om-spring - 0.9.5 + 0.9.6-SNAPSHOT diff --git a/demos/roms-hashes/pom.xml b/demos/roms-hashes/pom.xml index abf4da49..c35ab290 100644 --- a/demos/roms-hashes/pom.xml +++ b/demos/roms-hashes/pom.xml @@ -17,12 +17,12 @@ Redis OM Spring Enhanced RedisHash Demo - 17 - 17 - 17 - 17 - 17 - 17 + 21 + 21 + 21 + 21 + 21 + 21 true diff --git a/demos/roms-permits/pom.xml b/demos/roms-permits/pom.xml index 21b7dca1..f8cd63ab 100644 --- a/demos/roms-permits/pom.xml +++ b/demos/roms-permits/pom.xml @@ -17,12 +17,12 @@ Demo project for Spring Boot - 17 - 17 - 17 - 17 - 17 - 17 + 21 + 21 + 21 + 21 + 21 + 21 true diff --git a/demos/roms-vss/pom.xml b/demos/roms-vss/pom.xml index 8a81e571..fb1ed8b3 100644 --- a/demos/roms-vss/pom.xml +++ b/demos/roms-vss/pom.xml @@ -17,12 +17,12 @@ Redis OM Spring Vector Similarity Search Demo - 17 - 17 - 17 - 17 - 17 - 17 + 21 + 21 + 21 + 21 + 21 + 21 true @@ -30,7 +30,7 @@ com.redis.om redis-om-spring - 0.9.5 + 0.9.6-SNAPSHOT org.springframework.boot diff --git a/pom.xml b/pom.xml index 459f00d0..9606c247 100644 --- a/pom.xml +++ b/pom.xml @@ -12,12 +12,12 @@ UTF-8 - 17 - 17 - 17 - 17 - 17 - 17 + 21 + 21 + 21 + 21 + 21 + 21 diff --git a/redis-om-spring/pom.xml b/redis-om-spring/pom.xml index 69c190f9..95c4443d 100644 --- a/redis-om-spring/pom.xml +++ b/redis-om-spring/pom.xml @@ -7,7 +7,7 @@ com.redis.om redis-om-spring - 0.9.5 + 0.9.6-SNAPSHOT jar redis-om-spring @@ -55,12 +55,12 @@ UTF-8 - 17 - 17 - 17 - 17 - 17 - 17 + 21 + 21 + 21 + 21 + 21 + 21 3.3.2 3.3.2 5.0.2 @@ -374,8 +374,8 @@ maven-compiler-plugin 3.10.1 - ${maven.compiler.source} - ${maven.compiler.target} + 21 + 21 ${project.build.sourceEncoding} true diff --git a/redis-om-spring/src/main/java/com/redis/om/spring/metamodel/MetamodelGenerator.java b/redis-om-spring/src/main/java/com/redis/om/spring/metamodel/MetamodelGenerator.java index 72c0a5d6..2bc96796 100644 --- a/redis-om-spring/src/main/java/com/redis/om/spring/metamodel/MetamodelGenerator.java +++ b/redis-om-spring/src/main/java/com/redis/om/spring/metamodel/MetamodelGenerator.java @@ -44,7 +44,6 @@ @SupportedAnnotationTypes( value = { "com.redis.om.spring.annotations.Document", "org.springframework.data.redis.core.RedisHash" } ) -@SupportedSourceVersion(SourceVersion.RELEASE_17) @AutoService(Processor.class) public final class MetamodelGenerator extends AbstractProcessor { @@ -60,6 +59,11 @@ public final class MetamodelGenerator extends AbstractProcessor { public MetamodelGenerator() { } + @Override + public SourceVersion getSupportedSourceVersion() { + return SourceVersion.latest(); + } + private static TypeSpec getTypeSpecForMetamodelClass(String genEntityName, List interceptors, List fields, List nestedFieldsConstants, CodeBlock staticBlock) { return TypeSpec.classBuilder(genEntityName) // @@ -242,7 +246,7 @@ private List> processFieldMet TypeName entityField = TypeName.get(field.asType()); TypeMirror fieldType = field.asType(); - String fullTypeClassName = fieldType.toString(); + String fullTypeClassName = fieldType.toString().replace("@lombok.NonNull ", "").trim(); String cls = ObjectUtils.getTargetClassName(fullTypeClassName); if (field.asType().getKind().isPrimitive()) { @@ -575,20 +579,26 @@ private Map getInstanceFields(Element element) { // Only consider methods with no parameters .filter(ee -> ee.getEnclosedElements().stream().noneMatch(eee -> eee.getKind() == ElementKind.PARAMETER)) // Todo: Filter out methods that returns void or Void - .collect(Collectors.toMap(e -> e.getSimpleName().toString(), Function.identity())); + .collect(Collectors.toMap( + e -> e.getSimpleName().toString(), + Function.identity(), + (v1, v2) -> v1 // Merge function to handle duplicate keys + )); final Set isGetters = getters.values().stream() // todo: Filter out methods only returning boolean or Boolean .map(Element::getSimpleName).map(Object::toString).filter(n -> n.startsWith(IS_PREFIX)).map(n -> n.substring(2)) .map(ObjectUtils::toLowercaseFirstCharacter).collect(Collectors.toSet()); + // Use a mutable map to collect the results + Map results = new HashMap<>(); + // Retrieve all declared non-final instance fields of the annotated class - Map results = element.getEnclosedElements().stream() - .filter(ee -> ee.getKind().isField() && !ee.getModifiers().contains(Modifier.STATIC) // Ignore static - // fields + element.getEnclosedElements().stream() + .filter(ee -> ee.getKind().isField() && !ee.getModifiers().contains(Modifier.STATIC) // Ignore static fields && !ee.getModifiers().contains(Modifier.FINAL)) // Ignore final fields - .collect(Collectors.toMap(Function.identity(), - ee -> findGetter(ee, getters, isGetters, element.toString(), lombokGetterAvailable(element, ee)))); + .forEach(ee -> results.put(ee, + findGetter(ee, getters, isGetters, element.toString(), lombokGetterAvailable(element, ee)))); Types types = processingEnvironment.getTypeUtils(); List superTypes = types.directSupertypes(element.asType()); @@ -679,6 +689,23 @@ private String findGetter(final Element field, final Map getter return lambdaName + " -> " + lambdaName + "." + fieldName; } + // Handle specific cases for java.lang.String, java.lang.Enum, and java.util.Date + if (field.getEnclosingElement().toString().equals("java.lang.String")) { + if (fieldName.equals("hash") || fieldName.equals("hashIsZero")) { + return lambdaName + " -> 0"; // Return a default value for hash and hashIsZero + } + } else if (field.getEnclosingElement().toString().equals("java.lang.Enum")) { + if (fieldName.equals("hash")) { + return lambdaName + " -> 0"; // Return a default value for hash + } + } else if (field.getEnclosingElement().toString().equals("java.util.Date")) { + if (fieldName.equals("fastTime")) { + return lambdaName + " -> " + lambdaName + ".getTime()"; // Use getTime() as a fallback for fastTime + } else if (fieldName.equals("cdate")) { + return lambdaName + " -> " + lambdaName + ".getTime()"; // Use getTime() as a fallback for cdate + } + } + // default to thrower messager.printMessage(Diagnostic.Kind.ERROR, "Class " + entityName + " is not a proper JavaBean because " + field.getSimpleName()