Skip to content

Commit

Permalink
3.3.2: improved ReflectionUtils performance
Browse files Browse the repository at this point in the history
  • Loading branch information
biagio committed Jan 9, 2025
1 parent a71647b commit 80cec9f
Show file tree
Hide file tree
Showing 6 changed files with 50 additions and 10 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -121,13 +121,13 @@ curl -X POST -H "Content-type: application/json" -d '{
<dependency>
<groupId>app.tozzi</groupId>
<artifactId>jpa-search-helper</artifactId>
<version>3.3.1</version>
<version>3.3.2</version>
</dependency>
```

#### Gradle
```
implementation 'app.tozzi:jpa-search-helper:3.3.1
implementation 'app.tozzi:jpa-search-helper:3.3.2
```

## Queries - Usage
Expand Down
4 changes: 2 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ plugins {
}

group = 'app.tozzi'
version = '3.3.1'
version = '3.3.2'

compileJava {
sourceCompatibility = JavaVersion.VERSION_17
Expand Down Expand Up @@ -65,7 +65,7 @@ publishing {
maven(MavenPublication) {
group = 'app.tozzi'
artifactId = 'jpa-search-helper'
version = "3.3.1"
version = "3.3.2"
from components.java
pom {
name = 'JPA Search Helper'
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/app/tozzi/util/ReflectionUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
import app.tozzi.annotation.Searchable;
import app.tozzi.exception.JPASearchException;
import jakarta.persistence.*;
import org.apache.commons.lang3.reflect.FieldUtils;
import org.apache.commons.lang3.tuple.Pair;
import org.springframework.beans.BeanUtils;

import java.lang.annotation.Annotation;
import java.lang.reflect.Field;
Expand Down Expand Up @@ -73,7 +73,7 @@ public static Map<String, Pair<Projectable, Field>> getAllProjectableFields(Clas

private static <A extends Annotation, N extends Annotation> void getFields(final StringBuilder root, Class<?> beanClass, Class<A> annotationClass, Class<N> nestedAnnotationClass, Map<String, Pair<A, Field>> res, boolean evaluateNested) {

Stream.of(BeanUtils.getPropertyDescriptors(beanClass)).flatMap(pd -> Stream.of(pd.getReadMethod().getDeclaringClass().getDeclaredFields()))
Stream.of(FieldUtils.getAllFields(beanClass))
.forEach(f -> {

if (f.isAnnotationPresent(annotationClass)) {
Expand Down
15 changes: 15 additions & 0 deletions src/test/java/app/tozzi/model/ModelA.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package app.tozzi.model;

import app.tozzi.annotation.Searchable;
import lombok.Data;

@Data
public class ModelA {

@Searchable
private String modelAID;

@Searchable
private String modelAField;

}
17 changes: 17 additions & 0 deletions src/test/java/app/tozzi/model/ModelB.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package app.tozzi.model;

import app.tozzi.annotation.Searchable;
import lombok.Data;
import lombok.EqualsAndHashCode;

@Data
@EqualsAndHashCode(callSuper = true)
public class ModelB extends ModelA {

@Searchable
private String modelBID;

@Searchable
private String modelBField;

}
16 changes: 12 additions & 4 deletions src/test/java/app/tozzi/util/ReflectionUtilsTest.java
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
package app.tozzi.util;

import app.tozzi.model.JPASearchOperatorFilter;
import app.tozzi.model.JPASearchType;
import app.tozzi.model.MyModel;
import app.tozzi.model.RecursiveModel;
import app.tozzi.model.*;
import org.junit.jupiter.api.Test;

import java.math.BigDecimal;
Expand Down Expand Up @@ -73,4 +70,15 @@ public void recursiveModelTest() {
assertTrue(map.containsKey("predecessor.name"));
assertEquals(30, map.size());
}

@Test
public void inheritanceTest() {
var map = ReflectionUtils.getAllSearchableFields(ModelB.class);
assertNotNull(map);
assertTrue(map.containsKey("modelBID"));
assertTrue(map.containsKey("modelBField"));
assertTrue(map.containsKey("modelAID"));
assertTrue(map.containsKey("modelAField"));
assertEquals(4, map.size());
}
}

0 comments on commit 80cec9f

Please sign in to comment.