@@ -124,7 +124,7 @@ public final class Neo4jTemplate implements
124
124
125
125
private EventSupport eventSupport ;
126
126
127
- private ProjectionFactory projectionFactory ;
127
+ private ProjectionFactory projectionFactoryf ;
128
128
129
129
private Renderer renderer ;
130
130
@@ -146,6 +146,11 @@ public Neo4jTemplate(Neo4jClient neo4jClient, Neo4jMappingContext neo4jMappingCo
146
146
this .neo4jMappingContext = neo4jMappingContext ;
147
147
this .cypherGenerator = CypherGenerator .INSTANCE ;
148
148
this .eventSupport = EventSupport .useExistingCallbacks (neo4jMappingContext , entityCallbacks );
149
+ this .renderer = Renderer .getDefaultRenderer ();
150
+ }
151
+
152
+ ProjectionFactory getProjectionFactory () {
153
+ 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." );
149
154
}
150
155
151
156
@ Override
@@ -256,7 +261,7 @@ <T, R> List<R> doFind(@Nullable String cypherQuery, @Nullable Map<String, Object
256
261
257
262
if (resultType .isInterface ()) {
258
263
return intermediaResults .stream ()
259
- .map (instance -> projectionFactory .createProjection (resultType , instance ))
264
+ .map (instance -> getProjectionFactory () .createProjection (resultType , instance ))
260
265
.collect (Collectors .toList ());
261
266
}
262
267
@@ -342,23 +347,24 @@ public <T, R> R saveAs(T instance, Class<R> resultType) {
342
347
return resultType .cast (save (instance ));
343
348
}
344
349
345
- ProjectionInformation projectionInformation = projectionFactory .getProjectionInformation (resultType );
350
+ ProjectionFactory localProjectionFactory = getProjectionFactory ();
351
+ ProjectionInformation projectionInformation = localProjectionFactory .getProjectionInformation (resultType );
346
352
Collection <PropertyFilter .ProjectedPath > pps = PropertyFilterSupport .addPropertiesFrom (instance .getClass (), resultType ,
347
- projectionFactory , neo4jMappingContext );
353
+ localProjectionFactory , neo4jMappingContext );
348
354
349
355
T savedInstance = saveImpl (instance , pps , null );
350
356
if (!resultType .isInterface ()) {
351
357
@ SuppressWarnings ("unchecked" ) R result = (R ) new DtoInstantiatingConverter (resultType , neo4jMappingContext ).convertDirectly (savedInstance );
352
358
return result ;
353
359
}
354
360
if (projectionInformation .isClosed ()) {
355
- return projectionFactory .createProjection (resultType , savedInstance );
361
+ return localProjectionFactory .createProjection (resultType , savedInstance );
356
362
}
357
363
358
364
Neo4jPersistentEntity <?> entityMetaData = neo4jMappingContext .getRequiredPersistentEntity (savedInstance .getClass ());
359
365
Neo4jPersistentProperty idProperty = entityMetaData .getIdProperty ();
360
366
PersistentPropertyAccessor <T > propertyAccessor = entityMetaData .getPropertyAccessor (savedInstance );
361
- return projectionFactory .createProjection (resultType ,
367
+ return localProjectionFactory .createProjection (resultType ,
362
368
this .findById (propertyAccessor .getProperty (idProperty ), savedInstance .getClass ()).get ());
363
369
}
364
370
@@ -542,15 +548,16 @@ public <T, R> List<R> saveAllAs(Iterable<T> instances, Class<R> resultType) {
542
548
return saveElements ;
543
549
}
544
550
545
- ProjectionInformation projectionInformation = projectionFactory .getProjectionInformation (resultType );
551
+ ProjectionFactory localProjectionFactory = getProjectionFactory ();
552
+ ProjectionInformation projectionInformation = localProjectionFactory .getProjectionInformation (resultType );
546
553
547
554
Collection <PropertyFilter .ProjectedPath > pps = PropertyFilterSupport .addPropertiesFrom (commonElementType , resultType ,
548
- projectionFactory , neo4jMappingContext );
555
+ localProjectionFactory , neo4jMappingContext );
549
556
550
557
List <T > savedInstances = saveAllImpl (instances , pps , null );
551
558
552
559
if (projectionInformation .isClosed ()) {
553
- return savedInstances .stream ().map (instance -> projectionFactory .createProjection (resultType , instance ))
560
+ return savedInstances .stream ().map (instance -> localProjectionFactory .createProjection (resultType , instance ))
554
561
.collect (Collectors .toList ());
555
562
}
556
563
@@ -563,7 +570,7 @@ public <T, R> List<R> saveAllAs(Iterable<T> instances, Class<R> resultType) {
563
570
}).collect (Collectors .toList ());
564
571
565
572
return findAllById (ids , commonElementType )
566
- .stream ().map (instance -> projectionFactory .createProjection (resultType , instance ))
573
+ .stream ().map (instance -> localProjectionFactory .createProjection (resultType , instance ))
567
574
.collect (Collectors .toList ());
568
575
}
569
576
@@ -1000,7 +1007,7 @@ public void setBeanFactory(BeanFactory beanFactory) throws BeansException {
1000
1007
SpelAwareProxyProjectionFactory spelAwareProxyProjectionFactory = new SpelAwareProxyProjectionFactory ();
1001
1008
spelAwareProxyProjectionFactory .setBeanClassLoader (beanClassLoader );
1002
1009
spelAwareProxyProjectionFactory .setBeanFactory (beanFactory );
1003
- this .projectionFactory = spelAwareProxyProjectionFactory ;
1010
+ this .projectionFactoryf = spelAwareProxyProjectionFactory ;
1004
1011
1005
1012
Configuration cypherDslConfiguration = beanFactory
1006
1013
.getBeanProvider (Configuration .class )
@@ -1054,7 +1061,7 @@ <T, R> List<R> doSave(Iterable<R> instances, Class<T> domainType) {
1054
1061
Class <?> resultType = TemplateSupport .findCommonElementType (instances );
1055
1062
1056
1063
Collection <PropertyFilter .ProjectedPath > pps = PropertyFilterSupport .addPropertiesFrom (domainType , resultType ,
1057
- projectionFactory , neo4jMappingContext );
1064
+ getProjectionFactory () , neo4jMappingContext );
1058
1065
1059
1066
NestedRelationshipProcessingStateMachine stateMachine = new NestedRelationshipProcessingStateMachine (neo4jMappingContext );
1060
1067
List <R > results = new ArrayList <>();
0 commit comments