|
| 1 | +/* |
| 2 | + * Copyright (c) 2023-2024 FalkorDB Ltd. |
| 3 | + * |
| 4 | + * Permission is hereby granted, free of charge, to any person obtaining a copy |
| 5 | + * of this software and associated documentation files (the "Software"), to deal |
| 6 | + * in the Software without restriction, including without limitation the rights |
| 7 | + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
| 8 | + * copies of the Software, and to permit persons to whom the Software is |
| 9 | + * furnished to do so, subject to the following conditions: |
| 10 | + * |
| 11 | + * The above copyright notice and this permission notice shall be included in all |
| 12 | + * copies or substantial portions of the Software. |
| 13 | + * |
| 14 | + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| 15 | + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 16 | + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
| 17 | + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
| 18 | + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
| 19 | + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE |
| 20 | + * SOFTWARE. |
| 21 | + */ |
| 22 | +package org.springframework.data.falkordb.repository.config; |
| 23 | + |
| 24 | +import java.lang.annotation.Documented; |
| 25 | +import java.lang.annotation.ElementType; |
| 26 | +import java.lang.annotation.Inherited; |
| 27 | +import java.lang.annotation.Retention; |
| 28 | +import java.lang.annotation.RetentionPolicy; |
| 29 | +import java.lang.annotation.Target; |
| 30 | + |
| 31 | +import org.springframework.context.annotation.ComponentScan.Filter; |
| 32 | +import org.springframework.context.annotation.Import; |
| 33 | +import org.springframework.data.repository.config.DefaultRepositoryBaseClass; |
| 34 | +import org.springframework.data.repository.query.QueryLookupStrategy; |
| 35 | + |
| 36 | +/** |
| 37 | + * Annotation to enable FalkorDB repositories. Will scan the package of the annotated |
| 38 | + * configuration class for Spring Data repositories by default. |
| 39 | + * |
| 40 | + * @author Shahar Biron |
| 41 | + * @since 1.0 |
| 42 | + */ |
| 43 | +@Target(ElementType.TYPE) |
| 44 | +@Retention(RetentionPolicy.RUNTIME) |
| 45 | +@Documented |
| 46 | +@Inherited |
| 47 | +@Import(FalkorDBRepositoriesRegistrar.class) |
| 48 | +public @interface EnableFalkorDBRepositories { |
| 49 | + |
| 50 | + /** |
| 51 | + * Alias for the {@link #basePackages()} attribute. Allows for more concise annotation |
| 52 | + * declarations e.g.: {@code @EnableFalkorDBRepositories("org.my.pkg")} instead of |
| 53 | + * {@code @EnableFalkorDBRepositories(basePackages="org.my.pkg")}. |
| 54 | + * @return base packages to scan for repositories |
| 55 | + */ |
| 56 | + String[] value() default {}; |
| 57 | + |
| 58 | + /** |
| 59 | + * Base packages to scan for annotated components. {@link #value()} is an alias for |
| 60 | + * (and mutually exclusive with) this attribute. Use {@link #basePackageClasses()} for |
| 61 | + * a type-safe alternative to String-based package names. |
| 62 | + * @return base packages to scan |
| 63 | + */ |
| 64 | + String[] basePackages() default {}; |
| 65 | + |
| 66 | + /** |
| 67 | + * Type-safe alternative to {@link #basePackages()} for specifying the packages to |
| 68 | + * scan for annotated components. The package of each class specified will be scanned. |
| 69 | + * Consider creating a special no-op marker class or interface in each package that |
| 70 | + * serves no purpose other than being referenced by this attribute. |
| 71 | + * @return base package classes |
| 72 | + */ |
| 73 | + Class<?>[] basePackageClasses() default {}; |
| 74 | + |
| 75 | + /** |
| 76 | + * Specifies which types are eligible for component scanning. Further narrows the set |
| 77 | + * of candidate components from everything in {@link #basePackages()} to everything in |
| 78 | + * the base packages that matches the given filter or filters. |
| 79 | + * @return include filters |
| 80 | + */ |
| 81 | + Filter[] includeFilters() default {}; |
| 82 | + |
| 83 | + /** |
| 84 | + * Specifies which types are not eligible for component scanning. |
| 85 | + * @return exclude filters |
| 86 | + */ |
| 87 | + Filter[] excludeFilters() default {}; |
| 88 | + |
| 89 | + /** |
| 90 | + * Returns the postfix to be used when looking up custom repository implementations. |
| 91 | + * Defaults to {@literal Impl}. So for a repository named {@code PersonRepository} the |
| 92 | + * corresponding implementation class will be looked up scanning for |
| 93 | + * {@code PersonRepositoryImpl}. |
| 94 | + * @return repository implementation postfix |
| 95 | + */ |
| 96 | + String repositoryImplementationPostfix() default "Impl"; |
| 97 | + |
| 98 | + /** |
| 99 | + * Configures the location of where to find the Spring Data named queries properties |
| 100 | + * file. Will default to {@code META-INF/falkordb-named-queries.properties}. |
| 101 | + * @return named queries location |
| 102 | + */ |
| 103 | + String namedQueriesLocation() default ""; |
| 104 | + |
| 105 | + /** |
| 106 | + * Returns the key of the {@link QueryLookupStrategy} to be used for lookup queries |
| 107 | + * for query methods. Defaults to {@link QueryLookupStrategy.Key#CREATE_IF_NOT_FOUND}. |
| 108 | + * @return query lookup strategy key |
| 109 | + */ |
| 110 | + QueryLookupStrategy.Key queryLookupStrategy() default QueryLookupStrategy.Key.CREATE_IF_NOT_FOUND; |
| 111 | + |
| 112 | + /** |
| 113 | + * Configure the repository base class to be used to create repository proxies for |
| 114 | + * this particular configuration. |
| 115 | + * @return repository base class |
| 116 | + */ |
| 117 | + Class<?> repositoryBaseClass() default DefaultRepositoryBaseClass.class; |
| 118 | + |
| 119 | + /** |
| 120 | + * Configures the name of the |
| 121 | + * {@link org.springframework.data.falkordb.core.FalkorDBTemplate} bean to be used |
| 122 | + * with the repositories detected. |
| 123 | + * @return FalkorDB template bean name |
| 124 | + */ |
| 125 | + String falkorDBTemplateRef() default "falkorDBTemplate"; |
| 126 | + |
| 127 | + /** |
| 128 | + * Configures whether nested repository-interfaces (e.g. defined as inner classes) |
| 129 | + * should be discovered by the repositories infrastructure. |
| 130 | + * @return whether to consider nested repositories |
| 131 | + */ |
| 132 | + boolean considerNestedRepositories() default false; |
| 133 | + |
| 134 | +} |
0 commit comments