|
| 1 | +/* |
| 2 | + * Copyright (c) [2011-2017] "Pivotal Software, Inc." / "Neo Technology" / "Graph Aware Ltd." |
| 3 | + * |
| 4 | + * This product is licensed to you under the Apache License, Version 2.0 (the "License"). |
| 5 | + * You may not use this product except in compliance with the License. |
| 6 | + * |
| 7 | + * This product may include a number of subcomponents with |
| 8 | + * separate copyright notices and license terms. Your use of the source |
| 9 | + * code for these subcomponents is subject to the terms and |
| 10 | + * conditions of the subcomponent's license, as noted in the LICENSE file. |
| 11 | + * |
| 12 | + */ |
| 13 | + |
| 14 | +package org.springframework.data.neo4j.bookmark; |
| 15 | + |
| 16 | +import org.springframework.beans.factory.config.BeanDefinition; |
| 17 | +import org.springframework.context.annotation.Bean; |
| 18 | +import org.springframework.context.annotation.Configuration; |
| 19 | +import org.springframework.context.annotation.Role; |
| 20 | + |
| 21 | +/** |
| 22 | + * Configuration used by @{@link org.springframework.data.neo4j.annotation.EnableBookmarkManagement} |
| 23 | + * <p> |
| 24 | + * Note on bookmark management implementation: |
| 25 | + * The implementation closely follows implementation of @EnableTransactionManagement or @EnableCaching, with simplified |
| 26 | + * pointcut. |
| 27 | + * <p> |
| 28 | + * The bookmark interceptor will set BookmarkInfo thread local when a methods is annotated with @UseBookmark. |
| 29 | + * It is executed before transactional advice (see setOrder(0) ). |
| 30 | + * Neo4j transaction manager then uses {@link BookmarkManager} bean to retrieve currently stored bookmarks and begins |
| 31 | + * new transaction using these bookmarks. |
| 32 | + * After commit new bookmark is stored in the BookmarkManager, replacing the bookmarks used to begin the transaction. |
| 33 | + * The user needs to provide the BookmarkManager bean. |
| 34 | + * |
| 35 | + * @author Frantisek Hartman |
| 36 | + */ |
| 37 | +@Configuration |
| 38 | +public class BookmarkManagementConfiguration { |
| 39 | + |
| 40 | + @Bean |
| 41 | + @Role(BeanDefinition.ROLE_INFRASTRUCTURE) |
| 42 | + public BeanFactoryBookmarkOperationAdvisor bookmarkAdvisor() { |
| 43 | + BeanFactoryBookmarkOperationAdvisor advisor = new BeanFactoryBookmarkOperationAdvisor(); |
| 44 | + advisor.setAdvice(bookmarkInterceptor()); |
| 45 | + advisor.setOrder(0); |
| 46 | + return advisor; |
| 47 | + } |
| 48 | + |
| 49 | + |
| 50 | + @Bean |
| 51 | + @Role(BeanDefinition.ROLE_INFRASTRUCTURE) |
| 52 | + public BookmarkInterceptor bookmarkInterceptor() { |
| 53 | + return new BookmarkInterceptor(); |
| 54 | + } |
| 55 | + |
| 56 | +} |
0 commit comments