You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Update documentation.
Additional logging for repository bootstrap procedure.
Limit usage of Optional in RepositoryFragment.
Original Pull Request: #3145
Copy file name to clipboardExpand all lines: src/main/antora/modules/ROOT/pages/repositories/custom-implementations.adoc
+39-17
Original file line number
Diff line number
Diff line change
@@ -250,7 +250,7 @@ Imagine you'd like to provide some custom search functionality usable across mul
250
250
First all you need is the fragment interface.
251
251
Note the generic `<T>` parameter to align the fragment with the repository domain type.
252
252
253
-
====
253
+
.Fragment Interface
254
254
[source,java]
255
255
----
256
256
package com.acme.search;
@@ -260,12 +260,11 @@ public interface SearchExtension<T> {
260
260
List<T> search(String text, Limit limit);
261
261
}
262
262
----
263
-
====
264
263
265
264
Let's assume the actual full-text search is available via a `SearchService` that is registered as a `Bean` within the context so you can consume it in our `SearchExtension` implementation.
266
265
All you need to run the search is the collection (or index) name and an object mapper that converts the search results into actual domain objects as sketched out below.
267
266
268
-
====
267
+
.Fragment implementation
269
268
[source,java]
270
269
----
271
270
package com.acme.search;
@@ -297,27 +296,44 @@ class DefaultSearchExtension<T> implements SearchExtension<T> {
297
296
}
298
297
}
299
298
----
300
-
====
301
299
302
300
In the example above `RepositoryMethodContext.currentMethod()` is used to retrieve metadata for the actual method invocation.
303
301
`RepositoryMethodContext` exposes information attached to the repository such as the domain type.
304
302
In this case we use the repository domain type to identify the name of the index to be searched.
305
303
306
-
Now that you've got both, the fragment declaration and implementation you can register it in the `META-INF/spring.factories` file, package things up if needed, and you're almost good to go.
304
+
Exposing invocation metadata is costly, hence it is disabled by default.
305
+
To access `RepositoryMethodContext.currentMethod()` you need to advise the repository factory responsible for creating the actual repository to expose method metadata.
307
306
308
-
.Registering a fragment implementation through `META-INF/spring.factories`
307
+
.Expose Repository Metadata
308
+
[tabs]
309
+
======
310
+
Marker Interface::
311
+
+
309
312
====
310
-
[source,properties]
313
+
Adding the `RepositoryMetadataAccess` marker interface to the fragments implementation will trigger the infrastructure and enable metadata exposure for those repositories using the fragment.
class DefaultSearchExtension<T> implements SearchExtension<T>, RepositoryMetadataAccess {
325
+
326
+
// ...
327
+
}
313
328
----
314
329
====
315
330
316
-
Exposing invocation metadata is costly, hence it is disabled by default.
317
-
To access `RepositoryMethodContext.currentMethod()` you need to advise the repository factory responsible for creating the actual repository to expose method metadata by setting the `exposeMetadata` flag.
318
-
331
+
Bean Post Processor::
332
+
+
319
333
====
320
-
[source,java]
334
+
The `exposeMetadata` flag can be set directly on the repository factory bean via a `BeanPostProcessor`.
The above example outlines how to enable metadata exposure by setting the `exposeMetadata` flag using a `BeanPostProcessor`.
349
364
Please do not just copy/paste the above but consider your actual use case which may require a more fine-grained approach as the above will simply enable the flag on every repository.
350
-
You may want to have a look at our https://github.com/spring-projects/spring-data-examples/tree/main/bom[spring-data-examples] project to draw inspiration.
351
365
====
366
+
======
352
367
353
-
Now you are ready to make use of your extension; Simply add the interface to your repository:
368
+
Having both, the fragment declaration and implementation in place you can register the extension in the `META-INF/spring.factories` file and package things up if needed.
354
369
355
-
====
370
+
.Register the fragment in `META-INF/spring.factories`
0 commit comments