Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/repository cleanup #160

Merged
merged 2 commits into from
Mar 10, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -29,19 +29,18 @@
*/
public interface AerospikeRepository<T, ID> extends PagingAndSortingRepository<T, ID> {

<T> void createIndex(Class<T> domainType, String indexName, String binName, IndexType indexType);
<E> void createIndex(Class<E> domainType, String indexName, String binName, IndexType indexType);

<T> void deleteIndex(Class<T> domainType, String indexName);
<E> void deleteIndex(Class<E> domainType, String indexName);

/**
* Checks whether index by specified name exists in Aerospike.
* @param indexName
* @param indexName The Aerospike index name.
* @return true if exists
* @deprecated This operation is deprecated due to complications that are required for guaranteed index existence response.
* <p>If you need to conditionally create index \u2014 replace {@link #indexExists} with {@link #createIndex} and catch {@link IndexAlreadyExistsException}.
* <p>If you need to conditionally create index \u2014 replace this method (indexExists) with {@link #createIndex} and catch {@link IndexAlreadyExistsException}.
* <p>More information can be found at: <a href="https://github.com/aerospike/aerospike-client-java/pull/149">https://github.com/aerospike/aerospike-client-java/pull/149</a>
*/
@Deprecated
boolean indexExists(String indexName);

}
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import org.springframework.data.aerospike.repository.query.AerospikeQueryCreator;
import org.springframework.data.keyvalue.repository.config.KeyValueRepositoryConfigurationExtension;
import org.springframework.data.keyvalue.repository.config.QueryCreatorType;
import org.springframework.data.keyvalue.repository.query.SpelQueryCreator;
import org.springframework.data.repository.config.AnnotationRepositoryConfigurationSource;

import java.util.Map;
Expand All @@ -45,8 +46,8 @@ public void postProcess(BeanDefinitionBuilder builder, AnnotationRepositoryConfi
* Detects the query creator type to be used for the factory to set. Will lookup a {@link QueryCreatorType} annotation
* on the {@code @Enable}-annotation or use {@link SpelQueryCreator} if not found.
*
* @param config
* @return
* @param config The annotation repository configuration to get the query creator metadata from.
* @return Query creator class.
*/
private static Class<?> getQueryCreatorType(AnnotationRepositoryConfigurationSource config) {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,23 +15,17 @@
*/
package org.springframework.data.aerospike.repository.config;

import java.lang.annotation.Documented;
import java.lang.annotation.ElementType;
import java.lang.annotation.Inherited;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;

import org.springframework.beans.factory.FactoryBean;
import org.springframework.context.annotation.ComponentScan.Filter;
import org.springframework.context.annotation.Import;
import org.springframework.data.aerospike.repository.support.AerospikeRepositoryFactoryBean;
import org.springframework.data.aerospike.repository.support.SimpleAerospikeRepository;
import org.springframework.data.keyvalue.core.KeyValueOperations;
import org.springframework.data.keyvalue.repository.support.KeyValueRepositoryFactoryBean;
import org.springframework.data.repository.query.QueryLookupStrategy;
import org.springframework.data.repository.query.QueryLookupStrategy.Key;

import java.lang.annotation.*;

/**
* Annotation to activate Aerospike repositories. If no base package is configured through either {@link #value()},
* {@link #basePackages()} or {@link #basePackageClasses()} it will trigger scanning of the package of annotated class.
Expand All @@ -43,8 +37,6 @@
@Documented
@Inherited
@Import(AerospikeRepositoriesRegistrar.class)
//@QueryCreatorType(SpelQueryCreator.class)
//@QueryCreatorType(AerospikeQueryCreator.class)
public @interface EnableAerospikeRepositories {

/**
Expand Down Expand Up @@ -81,47 +73,35 @@
* Returns the postfix to be used when looking up custom repository implementations. Defaults to {@literal Impl}. So
* for a repository named {@code PersonRepository} the corresponding implementation class will be looked up scanning
* for {@code PersonRepositoryImpl}.
*
* @return
*/
String repositoryImplementationPostfix() default "Impl";

/**
* Configures the location of where to find the Spring Data named queries properties file.
*
* @return
*/
String namedQueriesLocation() default "";

/**
* Returns the key of the {@link QueryLookupStrategy} to be used for lookup queries for query methods. Defaults to
* {@link Key#CREATE_IF_NOT_FOUND}.
*
* @return
*/
Key queryLookupStrategy() default Key.CREATE_IF_NOT_FOUND;

/**
* Returns the {@link FactoryBean} class to be used for each repository instance.
* Defaults to {@link AerospikeRepositoryFactoryBean}.
*
* @return
*/
Class<?> repositoryFactoryBeanClass() default AerospikeRepositoryFactoryBean.class;

/**
* Configure the repository base class to be used to create repository proxies for this particular configuration.
* Defaults to {@link SimpleAerospikeRepository}.
*
* @return
* @since 1.8
*/
Class<?> repositoryBaseClass() default SimpleAerospikeRepository.class;

/**
* Configures the name of the {@link KeyValueOperations} bean to be used with the repositories detected.
*
* @return
*/
String keyValueTemplateRef() default "aerospikeTemplate";

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,47 +73,35 @@
* Returns the postfix to be used when looking up custom repository implementations. Defaults to {@literal Impl}. So
* for a repository named {@code PersonRepository} the corresponding implementation class will be looked up scanning
* for {@code PersonRepositoryImpl}.
*
* @return
*/
String repositoryImplementationPostfix() default "Impl";

/**
* Configures the location of where to find the Spring Data named queries properties file.
*
* @return
*/
String namedQueriesLocation() default "";

/**
* Returns the key of the {@link QueryLookupStrategy} to be used for lookup queries for query methods. Defaults to
* {@link Key#CREATE_IF_NOT_FOUND}.
*
* @return
*/
Key queryLookupStrategy() default Key.CREATE_IF_NOT_FOUND;

/**
* Returns the {@link FactoryBean} class to be used for each repository instance. Defaults to
* {@link ReactiveAerospikeRepositoryFactoryBean}.
*
* @return
*/
Class<?> repositoryFactoryBeanClass() default ReactiveAerospikeRepositoryFactoryBean.class;

/**
* Configure the repository base class to be used to create repository proxies for this particular configuration.
* Defaults to {@link SimpleReactiveAerospikeRepository}.
*
* @return
* @since 1.8
*/
Class<?> repositoryBaseClass() default SimpleReactiveAerospikeRepository.class;

/**
* Configures the name of the {@link KeyValueOperations} bean to be used with the repositories detected.
*
* @return
*/
String keyValueTemplateRef() default "reactiveAerospikeTemplate";

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,8 @@
import org.springframework.data.aerospike.query.Qualifier;

/**
*
* @author Michael Zhang
* @author Jeff Boone
*
*/
public class AerospikeCriteria extends Qualifier implements CriteriaDefinition {

Expand Down Expand Up @@ -64,5 +62,4 @@ public Qualifier getCriteriaObject() {
public String getKey() {
return this.getField();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,8 @@
import org.springframework.data.repository.query.ParameterAccessor;

/**
*
* @author Peter Milne
* @author Jean Mercier
*
*/
public interface AerospikeParameterAccessor extends ParameterAccessor {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,17 +26,17 @@
import java.util.stream.Stream;

/**
*
* @author Peter Milne
* @author Jean Mercier
*
*/
public class AerospikePartTreeQuery extends BaseAerospikePartTreeQuery {

private final AerospikeOperations aerospikeOperations;

public AerospikePartTreeQuery(QueryMethod queryMethod, QueryMethodEvaluationContextProvider evalContextProvider,
AerospikeOperations aerospikeOperations, Class<? extends AbstractQueryCreator<?, ?>> queryCreator) {
public AerospikePartTreeQuery(QueryMethod queryMethod,
QueryMethodEvaluationContextProvider evalContextProvider,
AerospikeOperations aerospikeOperations,
Class<? extends AbstractQueryCreator<?, ?>> queryCreator) {
super(queryMethod, evalContextProvider, queryCreator);
this.aerospikeOperations = aerospikeOperations;
}
Expand All @@ -51,10 +51,8 @@ public Object execute(Object[] parameters) {
Query query = prepareQuery(parameters, accessor);

if (queryMethod.isPageQuery() || queryMethod.isSliceQuery()) {

Stream<?> result = findByQuery(query);
long total = queryMethod.isSliceQuery() ? 0 : aerospikeOperations.count(query, queryMethod.getEntityInformation().getJavaType());

//TODO: should return SliceImpl for slice query
return new PageImpl(result.collect(Collectors.toList()), accessor.getPageable(), total);
} else if (queryMethod.isStreamQuery()) {
Expand All @@ -65,7 +63,6 @@ public Object execute(Object[] parameters) {
Stream<?> result = findByQuery(query);
return result.findFirst().orElse(null);
}

throw new UnsupportedOperationException("Query method " + queryMethod.getNamedQueryName() + " not supported.");
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ private AerospikeCriteria create(Part part, AerospikePersistentProperty property
throw new IllegalArgumentException("Unsupported keyword!");
}

//customization for collection/map query
// Customization for collection/map query
TypeInformation<?> propertyType = property.getTypeInformation();
if (propertyType.isCollectionLike()) {
if (op == FilterOperation.CONTAINING) {
Expand All @@ -132,9 +132,9 @@ private AerospikeCriteria create(Part part, AerospikePersistentProperty property
}
}

if(null == v2)
return new AerospikeCriteria(fieldName, op, ignoreCase==IgnoreCaseType.ALWAYS, Value.get(v1));

if (null == v2) {
return new AerospikeCriteria(fieldName, op, ignoreCase == IgnoreCaseType.ALWAYS, Value.get(v1));
}
return new AerospikeCriteria(fieldName, op, Value.get(v1), Value.get(v2));
}

Expand Down Expand Up @@ -176,7 +176,7 @@ protected Query complete(AerospikeCriteria criteria, Sort sort) {
}

@SuppressWarnings("unused")
private boolean isSimpleComparisionPossible(Part part) {
private boolean isSimpleComparisonPossible(Part part) {
switch (part.shouldIgnoreCase()) {
case WHEN_POSSIBLE:
return part.getProperty().getType() != String.class;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@ public abstract class BaseAerospikePartTreeQuery implements RepositoryQuery {
private final Class<? extends AbstractQueryCreator<?, ?>> queryCreator;
protected final QueryMethod queryMethod;


public BaseAerospikePartTreeQuery(QueryMethod queryMethod, QueryMethodEvaluationContextProvider evalContextProvider,
public BaseAerospikePartTreeQuery(QueryMethod queryMethod,
QueryMethodEvaluationContextProvider evalContextProvider,
Class<? extends AbstractQueryCreator<?, ?>> queryCreator) {
this.queryMethod = queryMethod;
this.evaluationContextProvider = evalContextProvider;
Expand Down Expand Up @@ -81,13 +81,11 @@ protected Query prepareQuery(Object[] parameters, ParametersParameterAccessor ac
return q;
}


public Query createQuery(ParametersParameterAccessor accessor) {
PartTree tree = new PartTree(queryMethod.getName(), queryMethod.getEntityInformation().getJavaType());

Constructor<? extends AbstractQueryCreator<?, ?>> constructor = ClassUtils
.getConstructorIfAvailable(queryCreator, PartTree.class, ParameterAccessor.class);
return (Query) BeanUtils.instantiateClass(constructor, tree, accessor).createQuery();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,8 @@
import java.util.List;

/**
*
* @author Peter Milne
* @author Jean Mercier
*
*/
public class Criteria implements CriteriaDefinition {

Expand Down Expand Up @@ -266,5 +264,4 @@ public Criteria geo_within(Object lng, Object lat, Object radius, String propert
this.criteria.put(Qualifier.FilterOperation.GEO_WITHIN.name(), qualifier);
return this;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,8 @@
import org.springframework.data.aerospike.query.Qualifier;

/**
*
* @author Peter Milne
* @author Jean Mercier
*
*/
public interface CriteriaDefinition {

Expand All @@ -38,7 +36,7 @@ public interface CriteriaDefinition {
*/
String getKey();

public enum AerospikeMapCriteria{
enum AerospikeMapCriteria{
KEY,
VALUE
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,8 @@
import org.springframework.data.keyvalue.core.query.KeyValueQuery;

/**
*
* @author Peter Milne
* @author Jean Mercier
*
*/
public class Query {

Expand Down Expand Up @@ -158,7 +156,7 @@ public Query with(Sort sort) {
if (order.isIgnoreCase()) {
throw new IllegalArgumentException(String.format(
"Given sort contained an Order for %s with ignore case! "
+ "Aerospike does not support sorting ignoreing case currently!",
+ "Aerospike does not support sorting ignoring case currently!",
order.getProperty()));
}
}
Expand All @@ -171,5 +169,4 @@ public Query with(Sort sort) {

return this;
}

}
Loading