Skip to content

Commit 579ca77

Browse files
committed
Attach repository interface name to each repository init event.
Make spring.data.repository.postprocessors conditional to reduce the number of events. Append full fragment diagnostics.
1 parent 31eeb74 commit 579ca77

File tree

2 files changed

+53
-21
lines changed

2 files changed

+53
-21
lines changed

src/main/java/org/springframework/data/repository/core/support/RepositoryFactorySupport.java

Lines changed: 53 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -277,28 +277,52 @@ public <T> T getRepository(Class<T> repositoryInterface, RepositoryFragments fra
277277

278278
ApplicationStartup applicationStartup = getStartup();
279279

280-
StartupStep repositoryInit = applicationStartup.start("spring.data.repository.init");
281-
repositoryInit.tag("repository", () -> repositoryInterface.getName());
280+
StartupStep repositoryInit = onEvent(applicationStartup, "spring.data.repository.init", repositoryInterface);
282281

283-
StartupStep repositoryMetadataStep = applicationStartup.start("spring.data.repository.metadata");
282+
repositoryBaseClass.ifPresent(it -> repositoryInit.tag("baseClass", it.getName()));
283+
284+
StartupStep repositoryMetadataStep = onEvent(applicationStartup, "spring.data.repository.metadata",
285+
repositoryInterface);
284286
RepositoryMetadata metadata = getRepositoryMetadata(repositoryInterface);
285287
repositoryMetadataStep.end();
286288

287-
StartupStep repositoryCompositionStep = applicationStartup.start("spring.data.repository.composition");
288-
repositoryCompositionStep.tag("fragment.count", () -> String.valueOf(fragments.size()));
289+
StartupStep repositoryCompositionStep = onEvent(applicationStartup, "spring.data.repository.composition",
290+
repositoryInterface);
291+
repositoryCompositionStep.tag("fragment.count", String.valueOf(fragments.size()));
289292

290293
RepositoryComposition composition = getRepositoryComposition(metadata, fragments);
291294
RepositoryInformation information = getRepositoryInformation(metadata, composition);
295+
296+
repositoryCompositionStep.tag("fragments", () -> {
297+
298+
StringBuilder fragmentsTag = new StringBuilder();
299+
300+
for (RepositoryFragment<?> fragment : composition.getFragments()) {
301+
302+
if (fragmentsTag.length() > 0) {
303+
fragmentsTag.append(";");
304+
}
305+
306+
fragmentsTag.append(fragment.getSignatureContributor().getName());
307+
fragmentsTag.append(fragment.getImplementation().map(it -> ":" + it.getClass().getName()).orElse(""));
308+
}
309+
310+
return fragmentsTag.toString();
311+
});
312+
292313
repositoryCompositionStep.end();
293314

294315
validate(information, composition);
295316

296-
StartupStep repositoryTargetStep = applicationStartup.start("spring.data.repository.target");
317+
StartupStep repositoryTargetStep = onEvent(applicationStartup, "spring.data.repository.target",
318+
repositoryInterface);
297319
Object target = getTargetRepository(information);
320+
321+
repositoryTargetStep.tag("target", target.getClass().getName());
298322
repositoryTargetStep.end();
299323

300324
// Create proxy
301-
StartupStep repositoryProxyStep = applicationStartup.start("spring.data.repository.proxy");
325+
StartupStep repositoryProxyStep = onEvent(applicationStartup, "spring.data.repository.proxy", repositoryInterface);
302326
ProxyFactory result = new ProxyFactory();
303327
result.setTarget(target);
304328
result.setInterfaces(repositoryInterface, Repository.class, TransactionalProxy.class);
@@ -309,30 +333,33 @@ public <T> T getRepository(Class<T> repositoryInterface, RepositoryFragments fra
309333

310334
result.addAdvisor(ExposeInvocationInterceptor.ADVISOR);
311335

312-
StartupStep repositoryPostprocessorsStep = applicationStartup.start("spring.data.repository.postprocessors");
313-
postProcessors.forEach(processor -> {
314-
315-
StartupStep singlePostProcessor = applicationStartup.start("spring.data.repository.postprocessor");
316-
singlePostProcessor.tag("type", processor.getClass().getName());
317-
processor.postProcess(result, information);
318-
singlePostProcessor.end();
319-
});
320-
repositoryPostprocessorsStep.end();
336+
if (!postProcessors.isEmpty()) {
337+
StartupStep repositoryPostprocessorsStep = onEvent(applicationStartup, "spring.data.repository.postprocessors",
338+
repositoryInterface);
339+
postProcessors.forEach(processor -> {
340+
341+
StartupStep singlePostProcessor = onEvent(applicationStartup, "spring.data.repository.postprocessor",
342+
repositoryInterface);
343+
singlePostProcessor.tag("type", processor.getClass().getName());
344+
processor.postProcess(result, information);
345+
singlePostProcessor.end();
346+
});
347+
repositoryPostprocessorsStep.end();
348+
}
321349

322350
if (DefaultMethodInvokingMethodInterceptor.hasDefaultMethods(repositoryInterface)) {
323351
result.addAdvice(new DefaultMethodInvokingMethodInterceptor());
324352
}
325353

326-
StartupStep queryExecutorsStep = applicationStartup.start("spring.data.repository.queryexecutors");
327354
ProjectionFactory projectionFactory = getProjectionFactory(classLoader, beanFactory);
328355
Optional<QueryLookupStrategy> queryLookupStrategy = getQueryLookupStrategy(queryLookupStrategyKey,
329356
evaluationContextProvider);
330357
result.addAdvice(new QueryExecutorMethodInterceptor(information, projectionFactory, queryLookupStrategy,
331358
namedQueries, queryPostProcessors, methodInvocationListeners));
332-
queryExecutorsStep.end();
333359

334-
composition = composition.append(RepositoryFragment.implemented(target));
335-
result.addAdvice(new ImplementationMethodExecutionInterceptor(information, composition, methodInvocationListeners));
360+
RepositoryComposition compositionToUse = composition.append(RepositoryFragment.implemented(target));
361+
result.addAdvice(
362+
new ImplementationMethodExecutionInterceptor(information, compositionToUse, methodInvocationListeners));
336363

337364
T repository = (T) result.getProxy(classLoader);
338365
repositoryProxyStep.end();
@@ -359,6 +386,12 @@ ApplicationStartup getStartup() {
359386
}
360387
}
361388

389+
private StartupStep onEvent(ApplicationStartup applicationStartup, String name, Class<?> repositoryInterface) {
390+
391+
StartupStep step = applicationStartup.start(name);
392+
return step.tag("repository", repositoryInterface.getName());
393+
}
394+
362395
/**
363396
* Returns the {@link ProjectionFactory} to be used with the repository instances created.
364397
*

src/test/java/org/springframework/data/repository/core/support/RepositoryFactorySupportUnitTests.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -420,7 +420,6 @@ void callsApplicationStartupOnRepositoryInitialization() {
420420
orderedInvocation.verify(startup).start("spring.data.repository.composition");
421421
orderedInvocation.verify(startup).start("spring.data.repository.target");
422422
orderedInvocation.verify(startup).start("spring.data.repository.proxy");
423-
orderedInvocation.verify(startup).start("spring.data.repository.postprocessors");
424423
}
425424

426425
private ConvertingRepository prepareConvertingRepository(final Object expectedValue) {

0 commit comments

Comments
 (0)