Skip to content

Commit 80e52b9

Browse files
committed
Adapt to AOT Infrastructure changes in Commons.
Add Neo4jTypeFilters for general exclusion of Neo4j simple types. See spring-projects/spring-data-commons#3267
1 parent 83dc7b8 commit 80e52b9

File tree

4 files changed

+133
-14
lines changed

4 files changed

+133
-14
lines changed

src/main/java/org/springframework/data/neo4j/aot/Neo4jManagedTypesBeanRegistrationAotProcessor.java

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,11 @@
1313
* See the License for the specific language governing permissions and
1414
* limitations under the License.
1515
*/
16+
1617
package org.springframework.data.neo4j.aot;
1718

1819
import org.jspecify.annotations.Nullable;
1920

20-
import org.springframework.aot.generate.GenerationContext;
21-
import org.springframework.core.ResolvableType;
22-
import org.springframework.data.aot.AotContext;
2321
import org.springframework.data.aot.ManagedTypesBeanRegistrationAotProcessor;
2422
import org.springframework.util.ClassUtils;
2523

@@ -45,14 +43,4 @@ boolean isNeo4jManagedTypes(@Nullable Class<?> beanType) {
4543
return beanType != null && ClassUtils.isAssignable(Neo4jManagedTypes.class, beanType);
4644
}
4745

48-
@Override
49-
protected void contributeType(ResolvableType type, GenerationContext generationContext, AotContext aotContext) {
50-
51-
if (Neo4jAotPredicates.IS_SIMPLE_TYPE.test(type.toClass())) {
52-
return;
53-
}
54-
55-
super.contributeType(type, generationContext, aotContext);
56-
}
57-
5846
}
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
/*
2+
* Copyright 2011-2025 the original author or authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package org.springframework.data.neo4j.aot;
18+
19+
import java.util.function.Predicate;
20+
21+
import org.springframework.data.util.TypeCollector;
22+
import org.springframework.data.util.TypeUtils;
23+
24+
/**
25+
* {@link TypeCollector} predicates to exclude Neo4j simple types.
26+
*
27+
* @author Mark Paluch
28+
* @since 8.0
29+
*/
30+
class Neo4jTypeFilters implements TypeCollector.TypeCollectorFilters {
31+
32+
private static final Predicate<Class<?>> CLASS_FILTER = it -> TypeUtils.type(it)
33+
.isPartOf("org.springframework.data.neo4j.types", "org.neo4j.driver.types");
34+
35+
@Override
36+
public Predicate<Class<?>> classPredicate() {
37+
return Neo4jAotPredicates.IS_SIMPLE_TYPE.or(CLASS_FILTER).negate();
38+
}
39+
40+
}
Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
org.springframework.aot.hint.RuntimeHintsRegistrar=\
22
org.springframework.data.neo4j.aot.Neo4jRuntimeHints
33
org.springframework.beans.factory.aot.BeanRegistrationAotProcessor=\
4-
org.springframework.data.neo4j.aot.Neo4jManagedTypesBeanRegistrationAotProcessor
4+
org.springframework.data.neo4j.aot.Neo4jManagedTypesBeanRegistrationAotProcessor
5+
org.springframework.data.util.TypeCollector$TypeCollectorFilters=\
6+
org.springframework.data.neo4j.aot.Neo4jTypeFilters
Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
/*
2+
* Copyright 2011-2025 the original author or authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package org.springframework.data.neo4j.aot;
18+
19+
import java.math.BigDecimal;
20+
21+
import org.junit.jupiter.api.Test;
22+
import org.neo4j.driver.Value;
23+
24+
import org.springframework.data.neo4j.types.GeographicPoint2d;
25+
import org.springframework.data.util.TypeCollector;
26+
27+
import static org.assertj.core.api.Assertions.assertThat;
28+
29+
/**
30+
* Unit tests for {@link Neo4jTypeFilters}.
31+
*
32+
* @author Mark Paluch
33+
*/
34+
class Neo4jTypeFiltersUnitTests {
35+
36+
@Test
37+
void shouldExcludeNeo4jSimpleTypes() {
38+
assertThat(TypeCollector.inspect(MyEntity.class).list()).containsOnly(MyEntity.class, OtherEntity.class);
39+
}
40+
41+
public static class MyEntity {
42+
43+
private BigDecimal aNumber;
44+
45+
private GeographicPoint2d point;
46+
47+
private Value value;
48+
49+
private OtherEntity other;
50+
51+
public BigDecimal getaNumber() {
52+
return this.aNumber;
53+
}
54+
55+
public void setaNumber(BigDecimal aNumber) {
56+
this.aNumber = aNumber;
57+
}
58+
59+
public GeographicPoint2d getPoint() {
60+
return this.point;
61+
}
62+
63+
public void setPoint(GeographicPoint2d point) {
64+
this.point = point;
65+
}
66+
67+
public Value getValue() {
68+
return this.value;
69+
}
70+
71+
public void setValue(Value value) {
72+
this.value = value;
73+
}
74+
75+
public OtherEntity getOther() {
76+
return this.other;
77+
}
78+
79+
public void setOther(OtherEntity other) {
80+
this.other = other;
81+
}
82+
83+
}
84+
85+
public static class OtherEntity {
86+
87+
}
88+
89+
}

0 commit comments

Comments
 (0)