Skip to content

Commit cabfe7c

Browse files
committed
WIP: Add @EnableFalkorDBRepositories annotation and repository infrastructure…
1 parent dae2701 commit cabfe7c

File tree

6 files changed

+545
-0
lines changed

6 files changed

+545
-0
lines changed
Lines changed: 134 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,134 @@
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+
}
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
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.Annotation;
25+
26+
import org.springframework.data.repository.config.RepositoryBeanDefinitionRegistrarSupport;
27+
import org.springframework.data.repository.config.RepositoryConfigurationExtension;
28+
29+
/**
30+
* {@link org.springframework.context.annotation.ImportBeanDefinitionRegistrar} to enable
31+
* {@link EnableFalkorDBRepositories} annotation.
32+
*
33+
* @author Shahar Biron
34+
* @since 1.0
35+
*/
36+
public class FalkorDBRepositoriesRegistrar extends RepositoryBeanDefinitionRegistrarSupport {
37+
38+
@Override
39+
protected Class<? extends Annotation> getAnnotation() {
40+
return EnableFalkorDBRepositories.class;
41+
}
42+
43+
@Override
44+
protected RepositoryConfigurationExtension getExtension() {
45+
return new FalkorDBRepositoryConfigurationExtension();
46+
}
47+
48+
}
Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
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.Annotation;
25+
import java.util.Collection;
26+
import java.util.Collections;
27+
28+
import org.springframework.beans.factory.support.BeanDefinitionBuilder;
29+
import org.springframework.data.falkordb.core.mapping.FalkorDBMappingContext;
30+
import org.springframework.data.falkordb.repository.FalkorDBRepository;
31+
import org.springframework.data.falkordb.repository.support.FalkorDBRepositoryFactoryBean;
32+
import org.springframework.data.repository.config.RepositoryConfigurationExtensionSupport;
33+
import org.springframework.data.repository.config.RepositoryConfigurationSource;
34+
import org.springframework.data.repository.core.RepositoryMetadata;
35+
36+
/**
37+
* {@link org.springframework.data.repository.config.RepositoryConfigurationExtension} for
38+
* FalkorDB.
39+
*
40+
* @author Shahar Biron
41+
* @since 1.0
42+
*/
43+
public class FalkorDBRepositoryConfigurationExtension extends RepositoryConfigurationExtensionSupport {
44+
45+
private static final String FALKORDB_TEMPLATE_REF = "falkorDB-template-ref";
46+
47+
@Override
48+
public String getModuleName() {
49+
return "FalkorDB";
50+
}
51+
52+
@Override
53+
public String getRepositoryFactoryBeanClassName() {
54+
return FalkorDBRepositoryFactoryBean.class.getName();
55+
}
56+
57+
@Override
58+
protected String getModulePrefix() {
59+
return "falkordb";
60+
}
61+
62+
@Override
63+
protected Collection<Class<? extends Annotation>> getIdentifyingAnnotations() {
64+
return Collections.singleton(org.springframework.data.falkordb.core.schema.Node.class);
65+
}
66+
67+
@Override
68+
protected Collection<Class<?>> getIdentifyingTypes() {
69+
return Collections.singleton(FalkorDBRepository.class);
70+
}
71+
72+
@Override
73+
public void postProcess(BeanDefinitionBuilder builder, RepositoryConfigurationSource source) {
74+
75+
source.getAttribute(FALKORDB_TEMPLATE_REF).ifPresent(s -> builder.addPropertyReference("falkorDBTemplate", s));
76+
}
77+
78+
@Override
79+
protected boolean useRepositoryConfiguration(RepositoryMetadata metadata) {
80+
return metadata.isReactiveRepository() == false;
81+
}
82+
83+
@Override
84+
protected String getDefaultNamedQueryLocation() {
85+
return "META-INF/falkordb-named-queries.properties";
86+
}
87+
88+
@Override
89+
protected Class<?> getDefaultMappingContextClass() {
90+
return FalkorDBMappingContext.class;
91+
}
92+
93+
}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
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+
23+
/**
24+
* Configuration infrastructure for Spring Data FalkorDB repositories.
25+
*/
26+
package org.springframework.data.falkordb.repository.config;

0 commit comments

Comments
 (0)