@@ -364,23 +364,42 @@ protected Optional<E> addPersistentEntity(TypeInformation<?> typeInformation) {
364
364
read .unlock ();
365
365
}
366
366
367
- Class <?> type = typeInformation .getType ();
368
- E entity = null ;
367
+ E entity ;
369
368
370
369
try {
371
370
372
371
write .lock ();
372
+ entity = doAddPersistentEntity (typeInformation );
373
373
374
- entity = createPersistentEntity (typeInformation );
374
+ } catch (BeansException e ) {
375
+ throw new MappingException (e .getMessage (), e );
376
+ } finally {
377
+ write .unlock ();
378
+ }
379
+
380
+ // Inform listeners
381
+ if (applicationEventPublisher != null ) {
382
+ applicationEventPublisher .publishEvent (new MappingContextEvent <>(this , entity ));
383
+ }
384
+
385
+ return Optional .of (entity );
386
+ }
387
+
388
+ private E doAddPersistentEntity (TypeInformation <?> typeInformation ) {
375
389
390
+ try {
391
+
392
+ Class <?> type = typeInformation .getType ();
393
+
394
+ E entity = createPersistentEntity (typeInformation );
376
395
entity .setEvaluationContextProvider (evaluationContextProvider );
377
396
378
397
// Eagerly cache the entity as we might have to find it during recursive lookups.
379
398
persistentEntities .put (typeInformation , Optional .of (entity ));
380
399
381
400
PropertyDescriptor [] pds = BeanUtils .getPropertyDescriptors (type );
382
401
383
- final Map <String , PropertyDescriptor > descriptors = new HashMap <>();
402
+ Map <String , PropertyDescriptor > descriptors = new HashMap <>();
384
403
for (PropertyDescriptor descriptor : pds ) {
385
404
descriptors .put (descriptor .getName (), descriptor );
386
405
}
@@ -395,21 +414,11 @@ protected Optional<E> addPersistentEntity(TypeInformation<?> typeInformation) {
395
414
entity .setPersistentPropertyAccessorFactory (persistentPropertyAccessorFactory );
396
415
}
397
416
398
- } catch (BeansException e ) {
399
- throw new MappingException (e .getMessage (), e );
417
+ return entity ;
400
418
} catch (RuntimeException e ) {
401
419
persistentEntities .remove (typeInformation );
402
420
throw e ;
403
- } finally {
404
- write .unlock ();
405
421
}
406
-
407
- // Inform listeners
408
- if (applicationEventPublisher != null && entity != null ) {
409
- applicationEventPublisher .publishEvent (new MappingContextEvent <>(this , entity ));
410
- }
411
-
412
- return Optional .of (entity );
413
422
}
414
423
415
424
/*
0 commit comments