|
| 1 | +/* |
| 2 | + * Copyright 2021 the original author or authors. |
| 3 | + * |
| 4 | + * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | + * you may not use this file except in compliance with the License. |
| 6 | + * You may obtain a copy of the License at |
| 7 | + * |
| 8 | + * https://www.apache.org/licenses/LICENSE-2.0 |
| 9 | + * |
| 10 | + * Unless required by applicable law or agreed to in writing, software |
| 11 | + * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | + * See the License for the specific language governing permissions and |
| 14 | + * limitations under the License. |
| 15 | + */ |
| 16 | +package org.springframework.data.envers.repository.config; |
| 17 | + |
| 18 | +import java.lang.annotation.Documented; |
| 19 | +import java.lang.annotation.ElementType; |
| 20 | +import java.lang.annotation.Inherited; |
| 21 | +import java.lang.annotation.Retention; |
| 22 | +import java.lang.annotation.RetentionPolicy; |
| 23 | +import java.lang.annotation.Target; |
| 24 | + |
| 25 | +import jakarta.persistence.EntityManagerFactory; |
| 26 | + |
| 27 | +import org.springframework.beans.factory.FactoryBean; |
| 28 | +import org.springframework.context.annotation.ComponentScan.Filter; |
| 29 | +import org.springframework.context.annotation.Lazy; |
| 30 | +import org.springframework.core.annotation.AliasFor; |
| 31 | +import org.springframework.data.envers.repository.support.EnversRevisionRepositoryFactoryBean; |
| 32 | +import org.springframework.data.jpa.repository.config.EnableJpaRepositories; |
| 33 | +import org.springframework.data.jpa.repository.support.JpaRepositoryFactoryBean; |
| 34 | +import org.springframework.data.repository.config.BootstrapMode; |
| 35 | +import org.springframework.data.repository.config.DefaultRepositoryBaseClass; |
| 36 | +import org.springframework.data.repository.query.QueryLookupStrategy; |
| 37 | +import org.springframework.data.repository.query.QueryLookupStrategy.Key; |
| 38 | +import org.springframework.transaction.PlatformTransactionManager; |
| 39 | + |
| 40 | +/** |
| 41 | + * Annotation to enable Envers repositories. Will scan the package of the annotated configuration class for Spring Data |
| 42 | + * repositories by default. |
| 43 | + * <p> |
| 44 | + * This annotation is a meta-annotation for {@link EnableJpaRepositories @EnableJpaRepositories} overriding the default |
| 45 | + * {@link #repositoryFactoryBeanClass} to {@link EnversRevisionRepositoryFactoryBean}. |
| 46 | + * |
| 47 | + * @author Mark Paluch |
| 48 | + * @since 2.5 |
| 49 | + * @see EnableJpaRepositories |
| 50 | + * @see AliasFor |
| 51 | + */ |
| 52 | +@Target(ElementType.TYPE) |
| 53 | +@Retention(RetentionPolicy.RUNTIME) |
| 54 | +@Documented |
| 55 | +@Inherited |
| 56 | +@EnableJpaRepositories |
| 57 | +public @interface EnableEnversRepositories { |
| 58 | + |
| 59 | + /** |
| 60 | + * Alias for the {@link #basePackages()} attribute. Allows for more concise annotation declarations e.g.: |
| 61 | + * {@code @EnableJpaRepositories("org.my.pkg")} instead of |
| 62 | + * {@code @EnableEnversRepositories(basePackages="org.my.pkg")}. |
| 63 | + */ |
| 64 | + @AliasFor(annotation = EnableJpaRepositories.class) |
| 65 | + String[] value() default {}; |
| 66 | + |
| 67 | + /** |
| 68 | + * Base packages to scan for annotated components. {@link #value()} is an alias for (and mutually exclusive with) this |
| 69 | + * attribute. Use {@link #basePackageClasses()} for a type-safe alternative to String-based package names. |
| 70 | + */ |
| 71 | + @AliasFor(annotation = EnableJpaRepositories.class) |
| 72 | + String[] basePackages() default {}; |
| 73 | + |
| 74 | + /** |
| 75 | + * Type-safe alternative to {@link #basePackages()} for specifying the packages to scan for annotated components. The |
| 76 | + * package of each class specified will be scanned. Consider creating a special no-op marker class or interface in |
| 77 | + * each package that serves no purpose other than being referenced by this attribute. |
| 78 | + */ |
| 79 | + @AliasFor(annotation = EnableJpaRepositories.class) |
| 80 | + Class<?>[] basePackageClasses() default {}; |
| 81 | + |
| 82 | + /** |
| 83 | + * Specifies which types are eligible for component scanning. Further narrows the set of candidate components from |
| 84 | + * everything in {@link #basePackages()} to everything in the base packages that matches the given filter or filters. |
| 85 | + */ |
| 86 | + @AliasFor(annotation = EnableJpaRepositories.class) |
| 87 | + Filter[] includeFilters() default {}; |
| 88 | + |
| 89 | + /** |
| 90 | + * Specifies which types are not eligible for component scanning. |
| 91 | + */ |
| 92 | + @AliasFor(annotation = EnableJpaRepositories.class) |
| 93 | + Filter[] excludeFilters() default {}; |
| 94 | + |
| 95 | + /** |
| 96 | + * Returns the postfix to be used when looking up custom repository implementations. Defaults to {@literal Impl}. So |
| 97 | + * for a repository named {@code PersonRepository} the corresponding implementation class will be looked up scanning |
| 98 | + * for {@code PersonRepositoryImpl}. |
| 99 | + * |
| 100 | + * @return |
| 101 | + */ |
| 102 | + @AliasFor(annotation = EnableJpaRepositories.class) |
| 103 | + String repositoryImplementationPostfix() default "Impl"; |
| 104 | + |
| 105 | + /** |
| 106 | + * Configures the location of where to find the Spring Data named queries properties file. Will default to |
| 107 | + * {@code META-INF/jpa-named-queries.properties}. |
| 108 | + * |
| 109 | + * @return |
| 110 | + */ |
| 111 | + @AliasFor(annotation = EnableJpaRepositories.class) |
| 112 | + String namedQueriesLocation() default ""; |
| 113 | + |
| 114 | + /** |
| 115 | + * Returns the key of the {@link QueryLookupStrategy} to be used for lookup queries for query methods. Defaults to |
| 116 | + * {@link Key#CREATE_IF_NOT_FOUND}. |
| 117 | + * |
| 118 | + * @return |
| 119 | + */ |
| 120 | + @AliasFor(annotation = EnableJpaRepositories.class) |
| 121 | + Key queryLookupStrategy() default Key.CREATE_IF_NOT_FOUND; |
| 122 | + |
| 123 | + /** |
| 124 | + * Returns the {@link FactoryBean} class to be used for each repository instance. Defaults to |
| 125 | + * {@link JpaRepositoryFactoryBean}. |
| 126 | + * |
| 127 | + * @return |
| 128 | + */ |
| 129 | + @AliasFor(annotation = EnableJpaRepositories.class) |
| 130 | + Class<?> repositoryFactoryBeanClass() default EnversRevisionRepositoryFactoryBean.class; |
| 131 | + |
| 132 | + /** |
| 133 | + * Configure the repository base class to be used to create repository proxies for this particular configuration. |
| 134 | + * |
| 135 | + * @return |
| 136 | + */ |
| 137 | + @AliasFor(annotation = EnableJpaRepositories.class) |
| 138 | + Class<?> repositoryBaseClass() default DefaultRepositoryBaseClass.class; |
| 139 | + |
| 140 | + // JPA specific configuration |
| 141 | + |
| 142 | + /** |
| 143 | + * Configures the name of the {@link EntityManagerFactory} bean definition to be used to create repositories |
| 144 | + * discovered through this annotation. Defaults to {@code entityManagerFactory}. |
| 145 | + * |
| 146 | + * @return |
| 147 | + */ |
| 148 | + @AliasFor(annotation = EnableJpaRepositories.class) |
| 149 | + String entityManagerFactoryRef() default "entityManagerFactory"; |
| 150 | + |
| 151 | + /** |
| 152 | + * Configures the name of the {@link PlatformTransactionManager} bean definition to be used to create repositories |
| 153 | + * discovered through this annotation. Defaults to {@code transactionManager}. |
| 154 | + * |
| 155 | + * @return |
| 156 | + */ |
| 157 | + @AliasFor(annotation = EnableJpaRepositories.class) |
| 158 | + String transactionManagerRef() default "transactionManager"; |
| 159 | + |
| 160 | + /** |
| 161 | + * Configures whether nested repository-interfaces (e.g. defined as inner classes) should be discovered by the |
| 162 | + * repositories infrastructure. |
| 163 | + */ |
| 164 | + @AliasFor(annotation = EnableJpaRepositories.class) |
| 165 | + boolean considerNestedRepositories() default false; |
| 166 | + |
| 167 | + /** |
| 168 | + * Configures whether to enable default transactions for Spring Data JPA repositories. Defaults to {@literal true}. If |
| 169 | + * disabled, repositories must be used behind a facade that's configuring transactions (e.g. using Spring's annotation |
| 170 | + * driven transaction facilities) or repository methods have to be used to demarcate transactions. |
| 171 | + * |
| 172 | + * @return whether to enable default transactions, defaults to {@literal true}. |
| 173 | + */ |
| 174 | + @AliasFor(annotation = EnableJpaRepositories.class) |
| 175 | + boolean enableDefaultTransactions() default true; |
| 176 | + |
| 177 | + /** |
| 178 | + * Configures when the repositories are initialized in the bootstrap lifecycle. {@link BootstrapMode#DEFAULT} |
| 179 | + * (default) means eager initialization except all repository interfaces annotated with {@link Lazy}, |
| 180 | + * {@link BootstrapMode#LAZY} means lazy by default including injection of lazy-initialization proxies into client |
| 181 | + * beans so that those can be instantiated but will only trigger the initialization upon first repository usage (i.e a |
| 182 | + * method invocation on it). This means repositories can still be uninitialized when the application context has |
| 183 | + * completed its bootstrap. {@link BootstrapMode#DEFERRED} is fundamentally the same as {@link BootstrapMode#LAZY}, |
| 184 | + * but triggers repository initialization when the application context finishes its bootstrap. |
| 185 | + * |
| 186 | + * @return |
| 187 | + */ |
| 188 | + @AliasFor(annotation = EnableJpaRepositories.class) |
| 189 | + BootstrapMode bootstrapMode() default BootstrapMode.DEFAULT; |
| 190 | + |
| 191 | + /** |
| 192 | + * Configures what character is used to escape the wildcards {@literal _} and {@literal %} in derived queries with |
| 193 | + * {@literal contains}, {@literal startsWith} or {@literal endsWith} clauses. |
| 194 | + * |
| 195 | + * @return a single character used for escaping. |
| 196 | + */ |
| 197 | + @AliasFor(annotation = EnableJpaRepositories.class) |
| 198 | + char escapeCharacter() default '\\'; |
| 199 | +} |
0 commit comments