@@ -123,7 +123,7 @@ public final class Neo4jTemplate implements
123
123
124
124
private EventSupport eventSupport ;
125
125
126
- private ProjectionFactory projectionFactory ;
126
+ private ProjectionFactory projectionFactoryf ;
127
127
128
128
private Renderer renderer ;
129
129
@@ -169,6 +169,11 @@ public Neo4jTemplate(Neo4jClient neo4jClient, Neo4jMappingContext neo4jMappingCo
169
169
this .neo4jMappingContext = neo4jMappingContext ;
170
170
this .cypherGenerator = CypherGenerator .INSTANCE ;
171
171
this .eventSupport = EventSupport .useExistingCallbacks (neo4jMappingContext , entityCallbacks );
172
+ this .renderer = Renderer .getDefaultRenderer ();
173
+ }
174
+
175
+ ProjectionFactory getProjectionFactory () {
176
+ return Objects .requireNonNull (this .projectionFactoryf , "Projection support for the Neo4j template is only available when the template is a proper and fully initialized Spring bean." );
172
177
}
173
178
174
179
@ Override
@@ -283,7 +288,7 @@ <T, R> List<R> doFind(@Nullable String cypherQuery, @Nullable Map<String, Object
283
288
284
289
if (resultType .isInterface ()) {
285
290
return intermediaResults .stream ()
286
- .map (instance -> projectionFactory .createProjection (resultType , instance ))
291
+ .map (instance -> getProjectionFactory () .createProjection (resultType , instance ))
287
292
.collect (Collectors .toList ());
288
293
}
289
294
@@ -370,23 +375,24 @@ public <T, R> R saveAs(T instance, Class<R> resultType) {
370
375
return resultType .cast (save (instance ));
371
376
}
372
377
373
- ProjectionInformation projectionInformation = projectionFactory .getProjectionInformation (resultType );
378
+ ProjectionFactory localProjectionFactory = getProjectionFactory ();
379
+ ProjectionInformation projectionInformation = localProjectionFactory .getProjectionInformation (resultType );
374
380
Collection <PropertyFilter .ProjectedPath > pps = PropertyFilterSupport .addPropertiesFrom (instance .getClass (), resultType ,
375
- projectionFactory , neo4jMappingContext );
381
+ localProjectionFactory , neo4jMappingContext );
376
382
377
383
T savedInstance = saveImpl (instance , pps , null );
378
384
if (!resultType .isInterface ()) {
379
385
@ SuppressWarnings ("unchecked" ) R result = (R ) new DtoInstantiatingConverter (resultType , neo4jMappingContext ).convertDirectly (savedInstance );
380
386
return result ;
381
387
}
382
388
if (projectionInformation .isClosed ()) {
383
- return projectionFactory .createProjection (resultType , savedInstance );
389
+ return localProjectionFactory .createProjection (resultType , savedInstance );
384
390
}
385
391
386
392
Neo4jPersistentEntity <?> entityMetaData = neo4jMappingContext .getRequiredPersistentEntity (savedInstance .getClass ());
387
393
Neo4jPersistentProperty idProperty = entityMetaData .getIdProperty ();
388
394
PersistentPropertyAccessor <T > propertyAccessor = entityMetaData .getPropertyAccessor (savedInstance );
389
- return projectionFactory .createProjection (resultType ,
395
+ return localProjectionFactory .createProjection (resultType ,
390
396
this .findById (propertyAccessor .getProperty (idProperty ), savedInstance .getClass ()).get ());
391
397
}
392
398
@@ -570,15 +576,16 @@ public <T, R> List<R> saveAllAs(Iterable<T> instances, Class<R> resultType) {
570
576
return saveElements ;
571
577
}
572
578
573
- ProjectionInformation projectionInformation = projectionFactory .getProjectionInformation (resultType );
579
+ ProjectionFactory localProjectionFactory = getProjectionFactory ();
580
+ ProjectionInformation projectionInformation = localProjectionFactory .getProjectionInformation (resultType );
574
581
575
582
Collection <PropertyFilter .ProjectedPath > pps = PropertyFilterSupport .addPropertiesFrom (commonElementType , resultType ,
576
- projectionFactory , neo4jMappingContext );
583
+ localProjectionFactory , neo4jMappingContext );
577
584
578
585
List <T > savedInstances = saveAllImpl (instances , pps , null );
579
586
580
587
if (projectionInformation .isClosed ()) {
581
- return savedInstances .stream ().map (instance -> projectionFactory .createProjection (resultType , instance ))
588
+ return savedInstances .stream ().map (instance -> localProjectionFactory .createProjection (resultType , instance ))
582
589
.collect (Collectors .toList ());
583
590
}
584
591
@@ -591,7 +598,7 @@ public <T, R> List<R> saveAllAs(Iterable<T> instances, Class<R> resultType) {
591
598
}).collect (Collectors .toList ());
592
599
593
600
return findAllById (ids , commonElementType )
594
- .stream ().map (instance -> projectionFactory .createProjection (resultType , instance ))
601
+ .stream ().map (instance -> localProjectionFactory .createProjection (resultType , instance ))
595
602
.collect (Collectors .toList ());
596
603
}
597
604
@@ -1024,7 +1031,7 @@ public void setBeanFactory(BeanFactory beanFactory) throws BeansException {
1024
1031
SpelAwareProxyProjectionFactory spelAwareProxyProjectionFactory = new SpelAwareProxyProjectionFactory ();
1025
1032
spelAwareProxyProjectionFactory .setBeanClassLoader (beanClassLoader );
1026
1033
spelAwareProxyProjectionFactory .setBeanFactory (beanFactory );
1027
- this .projectionFactory = spelAwareProxyProjectionFactory ;
1034
+ this .projectionFactoryf = spelAwareProxyProjectionFactory ;
1028
1035
1029
1036
Configuration cypherDslConfiguration = beanFactory
1030
1037
.getBeanProvider (Configuration .class )
@@ -1078,7 +1085,7 @@ <T, R> List<R> doSave(Iterable<R> instances, Class<T> domainType) {
1078
1085
Class <?> resultType = TemplateSupport .findCommonElementType (instances );
1079
1086
1080
1087
Collection <PropertyFilter .ProjectedPath > pps = PropertyFilterSupport .addPropertiesFrom (domainType , resultType ,
1081
- projectionFactory , neo4jMappingContext );
1088
+ getProjectionFactory () , neo4jMappingContext );
1082
1089
1083
1090
NestedRelationshipProcessingStateMachine stateMachine = new NestedRelationshipProcessingStateMachine (neo4jMappingContext );
1084
1091
List <R > results = new ArrayList <>();
0 commit comments