org.springframework.data.keyvalue.core.KeyValueOperations Java Examples

The following examples show how to use org.springframework.data.keyvalue.core.KeyValueOperations. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: KeyValueRepositoryFactory.java    From spring-data-keyvalue with Apache License 2.0 6 votes vote down vote up
/**
 * @param key
 * @param evaluationContextProvider
 * @param keyValueOperations
 * @param queryCreator
 * @since 1.1
 */
public KeyValueQueryLookupStrategy(@Nullable Key key,
		QueryMethodEvaluationContextProvider evaluationContextProvider, KeyValueOperations keyValueOperations,
		Class<? extends AbstractQueryCreator<?, ?>> queryCreator,
		Class<? extends RepositoryQuery> repositoryQueryType) {

	Assert.notNull(evaluationContextProvider, "EvaluationContextProvider must not be null!");
	Assert.notNull(keyValueOperations, "KeyValueOperations must not be null!");
	Assert.notNull(queryCreator, "Query creator type must not be null!");
	Assert.notNull(repositoryQueryType, "RepositoryQueryType type must not be null!");

	this.evaluationContextProvider = evaluationContextProvider;
	this.keyValueOperations = keyValueOperations;
	this.queryCreator = queryCreator;
	this.repositoryQueryType = repositoryQueryType;
}
 
Example #2
Source File: KeyValueRepositoryFactory.java    From spring-data-keyvalue with Apache License 2.0 6 votes vote down vote up
@Override
@SuppressWarnings("unchecked")
public RepositoryQuery resolveQuery(Method method, RepositoryMetadata metadata, ProjectionFactory factory,
		NamedQueries namedQueries) {

	QueryMethod queryMethod = new QueryMethod(method, metadata, factory);

	Constructor<? extends KeyValuePartTreeQuery> constructor = (Constructor<? extends KeyValuePartTreeQuery>) ClassUtils
			.getConstructorIfAvailable(this.repositoryQueryType, QueryMethod.class,
					QueryMethodEvaluationContextProvider.class, KeyValueOperations.class, Class.class);

	Assert.state(constructor != null,
			String.format(
					"Constructor %s(QueryMethod, EvaluationContextProvider, KeyValueOperations, Class) not available!",
					ClassUtils.getShortName(this.repositoryQueryType)));

	return BeanUtils.instantiateClass(constructor, queryMethod, evaluationContextProvider, this.keyValueOperations,
			this.queryCreator);
}
 
Example #3
Source File: HazelcastQueryLookupStrategy.java    From spring-data-hazelcast with Apache License 2.0 6 votes vote down vote up
/**
 * <p>
 * Required constructor, capturing arguments for use in {@link #resolveQuery}.
 * </P>
 * <p>
 * Assertions copied from {@link KayValueRepositoryFactory.KeyValueQUeryLookupStrategy} which this class essentially
 * duplicates.
 * </P>
 *
 * @param key                       Not used
 * @param evaluationContextProvider For evaluation of query expressions
 * @param keyValueOperations        Bean to use for Key/Value operations on Hazelcast repos
 * @param queryCreator              Likely to be {@link HazelcastQueryCreator}
 * @param hazelcastInstance         Instance of Hazelcast
 */
public HazelcastQueryLookupStrategy(QueryLookupStrategy.Key key,
                                    QueryMethodEvaluationContextProvider evaluationContextProvider,
                                    KeyValueOperations keyValueOperations,
                                    Class<? extends AbstractQueryCreator<?, ?>> queryCreator,
                                    HazelcastInstance hazelcastInstance) {

    Assert.notNull(evaluationContextProvider, "EvaluationContextProvider must not be null!");
    Assert.notNull(keyValueOperations, "KeyValueOperations must not be null!");
    Assert.notNull(queryCreator, "Query creator type must not be null!");
    Assert.notNull(hazelcastInstance, "HazelcastInstance must not be null!");

    this.evaluationContextProvider = evaluationContextProvider;
    this.keyValueOperations = keyValueOperations;
    this.queryCreator = queryCreator;
    this.hazelcastInstance = hazelcastInstance;
}
 
Example #4
Source File: SimpleKeyValueRepository.java    From spring-data-keyvalue with Apache License 2.0 5 votes vote down vote up
/**
 * Creates a new {@link SimpleKeyValueRepository} for the given {@link EntityInformation} and
 * {@link KeyValueOperations}.
 *
 * @param metadata must not be {@literal null}.
 * @param operations must not be {@literal null}.
 */
public SimpleKeyValueRepository(EntityInformation<T, ID> metadata, KeyValueOperations operations) {

	Assert.notNull(metadata, "EntityInformation must not be null!");
	Assert.notNull(operations, "KeyValueOperations must not be null!");

	this.entityInformation = metadata;
	this.operations = operations;
}
 
Example #5
Source File: QuerydslKeyValueRepository.java    From spring-data-keyvalue with Apache License 2.0 5 votes vote down vote up
/**
 * Creates a new {@link QuerydslKeyValueRepository} for the given {@link EntityInformation},
 * {@link KeyValueOperations} and {@link EntityPathResolver}.
 *
 * @param entityInformation must not be {@literal null}.
 * @param operations must not be {@literal null}.
 * @param resolver must not be {@literal null}.
 */
public QuerydslKeyValueRepository(EntityInformation<T, ID> entityInformation, KeyValueOperations operations,
		EntityPathResolver resolver) {

	super(entityInformation, operations);

	Assert.notNull(resolver, "EntityPathResolver must not be null!");

	EntityPath<T> path = resolver.createPath(entityInformation.getJavaType());
	this.builder = new PathBuilder<>(path.getType(), path.getMetadata());
}
 
Example #6
Source File: KeyValuePartTreeQuery.java    From spring-data-keyvalue with Apache License 2.0 5 votes vote down vote up
/**
 * Creates a new {@link KeyValuePartTreeQuery} for the given {@link QueryMethod}, {@link EvaluationContextProvider},
 * {@link KeyValueOperations} using the given {@link QueryCreatorFactory} producing the {@link AbstractQueryCreator}
 * in charge of altering the query.
 *
 * @param queryMethod must not be {@literal null}.
 * @param evaluationContextProvider must not be {@literal null}.
 * @param keyValueOperations must not be {@literal null}.
 * @param queryCreatorFactory must not be {@literal null}.
 * @since 2.0
 */
public KeyValuePartTreeQuery(QueryMethod queryMethod, QueryMethodEvaluationContextProvider evaluationContextProvider,
		KeyValueOperations keyValueOperations, QueryCreatorFactory queryCreatorFactory) {

	Assert.notNull(queryMethod, "Query method must not be null!");
	Assert.notNull(evaluationContextProvider, "EvaluationContextprovider must not be null!");
	Assert.notNull(keyValueOperations, "KeyValueOperations must not be null!");
	Assert.notNull(queryCreatorFactory, "QueryCreatorFactory type must not be null!");

	this.queryMethod = queryMethod;
	this.keyValueOperations = keyValueOperations;
	this.evaluationContextProvider = evaluationContextProvider;
	this.queryCreatorFactory = queryCreatorFactory;
}
 
Example #7
Source File: KeyValueRepositoryFactory.java    From spring-data-keyvalue with Apache License 2.0 5 votes vote down vote up
/**
 * Creates a new {@link KeyValueRepositoryFactory} for the given {@link KeyValueOperations} and
 * {@link AbstractQueryCreator}-type.
 *
 * @param keyValueOperations must not be {@literal null}.
 * @param queryCreator must not be {@literal null}.
 * @param repositoryQueryType must not be {@literal null}.
 * @since 1.1
 */
public KeyValueRepositoryFactory(KeyValueOperations keyValueOperations,
		Class<? extends AbstractQueryCreator<?, ?>> queryCreator, Class<? extends RepositoryQuery> repositoryQueryType) {

	Assert.notNull(keyValueOperations, "KeyValueOperations must not be null!");
	Assert.notNull(queryCreator, "Query creator type must not be null!");
	Assert.notNull(repositoryQueryType, "RepositoryQueryType type must not be null!");

	this.queryCreator = queryCreator;
	this.keyValueOperations = keyValueOperations;
	this.context = keyValueOperations.getMappingContext();
	this.repositoryQueryType = repositoryQueryType;
}
 
Example #8
Source File: MyTitleRepositoryFactoryBean.java    From spring-data-hazelcast with Apache License 2.0 5 votes vote down vote up
@Override
protected MyTitleRepositoryFactory createRepositoryFactory(KeyValueOperations operations,
                                                           Class<? extends AbstractQueryCreator<?, ?>> queryCreator,
                                                           Class<? extends RepositoryQuery> repositoryQueryType) {

    return new MyTitleRepositoryFactory(operations, queryCreator, hazelcastInstance);
}
 
Example #9
Source File: HazelcastRepositoryFactory.java    From spring-data-hazelcast with Apache License 2.0 5 votes vote down vote up
public HazelcastRepositoryFactory(KeyValueOperations keyValueOperations,
                                  Class<? extends AbstractQueryCreator<?, ?>> queryCreator,
                                  HazelcastInstance hazelcastInstance) {

    super(keyValueOperations, queryCreator);

    this.keyValueOperations = keyValueOperations;
    this.queryCreator = queryCreator;
    this.hazelcastInstance = hazelcastInstance;
}
 
Example #10
Source File: AbstractRepositoryUnitTests.java    From spring-data-keyvalue with Apache License 2.0 5 votes vote down vote up
@Before
public void setup() {

	KeyValueOperations operations = new KeyValueTemplate(new MapKeyValueAdapter());
	KeyValueRepositoryFactory keyValueRepositoryFactory = createKeyValueRepositoryFactory(operations);

	this.repository = getRepository(keyValueRepositoryFactory);
}
 
Example #11
Source File: VaultRepositoryFactoryBean.java    From spring-vault with Apache License 2.0 5 votes vote down vote up
@Override
protected VaultRepositoryFactory createRepositoryFactory(KeyValueOperations operations,
		Class<? extends AbstractQueryCreator<?, ?>> queryCreator,
		Class<? extends RepositoryQuery> repositoryQueryType) {

	return new VaultRepositoryFactory(operations, queryCreator, repositoryQueryType);
}
 
Example #12
Source File: VaultRepositoryFactory.java    From spring-vault with Apache License 2.0 5 votes vote down vote up
public VaultRepositoryFactory(KeyValueOperations keyValueOperations,
		Class<? extends AbstractQueryCreator<?, ?>> queryCreator,
		Class<? extends RepositoryQuery> repositoryQueryType) {
	super(keyValueOperations, queryCreator, repositoryQueryType);

	this.operations = keyValueOperations;
}
 
Example #13
Source File: KeyValueRepositoryFactoryBeanUnitTests.java    From spring-data-keyvalue with Apache License 2.0 5 votes vote down vote up
@Test // DATAKV-123
@SuppressWarnings("unchecked")
public void createsRepositoryFactory() {

	Class<? extends AbstractQueryCreator<?, ?>> creatorType = (Class<? extends AbstractQueryCreator<?, ?>>) mock(
			AbstractQueryCreator.class).getClass();
	Class<? extends RepositoryQuery> queryType = mock(KeyValuePartTreeQuery.class).getClass();

	factoryBean.setQueryCreator(creatorType);
	factoryBean.setKeyValueOperations(mock(KeyValueOperations.class));
	factoryBean.setQueryType(queryType);

	assertThat(factoryBean.createRepositoryFactory()).isNotNull();
}
 
Example #14
Source File: MapRepositoryRegistrarWithTemplateDefinitionIntegrationTests.java    From spring-data-keyvalue with Apache License 2.0 4 votes vote down vote up
@Bean
public KeyValueOperations keyValueTemplate() {
	return new KeyValueTemplate(new MapKeyValueAdapter());
}
 
Example #15
Source File: CachingQuerySimpleKeyValueRepositoryUnitTests.java    From spring-data-keyvalue with Apache License 2.0 4 votes vote down vote up
@Override
protected KeyValueRepositoryFactory createKeyValueRepositoryFactory(KeyValueOperations operations) {
	return new KeyValueRepositoryFactory(operations, SpelQueryCreator.class, CachingKeyValuePartTreeQuery.class);
}
 
Example #16
Source File: AbstractRepositoryUnitTests.java    From spring-data-keyvalue with Apache License 2.0 4 votes vote down vote up
protected KeyValueRepositoryFactory createKeyValueRepositoryFactory(KeyValueOperations operations) {
	return new KeyValueRepositoryFactory(operations);
}
 
Example #17
Source File: KeyValueRepositoryFactoryBeanUnitTests.java    From spring-data-keyvalue with Apache License 2.0 4 votes vote down vote up
@Test // DATAKV-123
public void rejectsInstanceWithoutQueryCreator() {

	factoryBean.setKeyValueOperations(mock(KeyValueOperations.class));
	assertThatIllegalArgumentException().isThrownBy(() -> factoryBean.afterPropertiesSet());
}
 
Example #18
Source File: Configurations.java    From tutorials with MIT License 4 votes vote down vote up
@Bean("keyValueTemplate")
public KeyValueOperations keyValueTemplate() {
    return new KeyValueTemplate(keyValueAdapter());

}
 
Example #19
Source File: CachingKeyValuePartTreeQuery.java    From spring-data-keyvalue with Apache License 2.0 4 votes vote down vote up
public CachingKeyValuePartTreeQuery(QueryMethod queryMethod,
		QueryMethodEvaluationContextProvider evaluationContextProvider, KeyValueOperations keyValueOperations,
		Class<? extends AbstractQueryCreator<?, ?>> queryCreator) {
	super(queryMethod, evaluationContextProvider, keyValueOperations, queryCreator);
}
 
Example #20
Source File: MyTitleRepositoryFactory.java    From spring-data-hazelcast with Apache License 2.0 4 votes vote down vote up
public MyTitleRepositoryFactory(KeyValueOperations keyValueOperations,
                                Class<? extends AbstractQueryCreator<?, ?>> queryCreator,
                                HazelcastInstance hazelcastInstance) {
    super(keyValueOperations, queryCreator, hazelcastInstance);
    this.keyValueOperations = keyValueOperations;
}
 
Example #21
Source File: MyTitleRepositoryImpl.java    From spring-data-hazelcast with Apache License 2.0 4 votes vote down vote up
public MyTitleRepositoryImpl(EntityInformation<T, ID> metadata, KeyValueOperations keyValueOperations) {
    super(metadata, keyValueOperations);
}
 
Example #22
Source File: SimpleHazelcastRepository.java    From spring-data-hazelcast with Apache License 2.0 4 votes vote down vote up
public SimpleHazelcastRepository(EntityInformation<T, ID> metadata, KeyValueOperations operations) {
    super(metadata, operations);
}
 
Example #23
Source File: HazelcastRepositoryFactory.java    From spring-data-hazelcast with Apache License 2.0 4 votes vote down vote up
public HazelcastRepositoryFactory(KeyValueOperations keyValueOperations, HazelcastInstance hazelcastInstance) {
    this(keyValueOperations, DEFAULT_QUERY_CREATOR, hazelcastInstance);
}
 
Example #24
Source File: VaultRepositoryFactory.java    From spring-vault with Apache License 2.0 4 votes vote down vote up
public VaultRepositoryFactory(KeyValueOperations keyValueOperations,
		Class<? extends AbstractQueryCreator<?, ?>> queryCreator) {
	this(keyValueOperations, queryCreator, KeyValuePartTreeQuery.class);
}
 
Example #25
Source File: VaultRepositoryFactory.java    From spring-vault with Apache License 2.0 4 votes vote down vote up
public VaultRepositoryFactory(KeyValueOperations keyValueOperations) {
	this(keyValueOperations, VaultQueryCreator.class);
}
 
Example #26
Source File: KeyValuePartTreeQuery.java    From spring-data-keyvalue with Apache License 2.0 3 votes vote down vote up
/**
 * Creates a new {@link KeyValuePartTreeQuery} for the given {@link QueryMethod}, {@link EvaluationContextProvider},
 * {@link KeyValueOperations} and query creator type.
 *
 * @param queryMethod must not be {@literal null}.
 * @param evaluationContextProvider must not be {@literal null}.
 * @param keyValueOperations must not be {@literal null}.
 * @param queryCreator must not be {@literal null}.
 */
public KeyValuePartTreeQuery(QueryMethod queryMethod, QueryMethodEvaluationContextProvider evaluationContextProvider,
		KeyValueOperations keyValueOperations, Class<? extends AbstractQueryCreator<?, ?>> queryCreator) {

	this(queryMethod, evaluationContextProvider, keyValueOperations,
			new ConstructorCachingQueryCreatorFactory(queryCreator));
}
 
Example #27
Source File: KeyValueRepositoryFactoryBean.java    From spring-data-keyvalue with Apache License 2.0 3 votes vote down vote up
/**
 * Configures the {@link KeyValueOperations} to be used for the repositories.
 *
 * @param operations must not be {@literal null}.
 */
public void setKeyValueOperations(KeyValueOperations operations) {

	Assert.notNull(operations, "KeyValueOperations must not be null!");

	this.operations = operations;
}
 
Example #28
Source File: HazelcastRepositoryFactoryBean.java    From spring-data-hazelcast with Apache License 2.0 3 votes vote down vote up
/**
 * <p>
 * Return a {@link HazelcastRepositoryFactory}.
 * </P>
 * <p>
 * {@code super} would return {@link KeyValueRepositoryFactory} which in turn builds {@link KeyValueRepository}
 * instances, and these have a private method that implement querying in a manner that does not fit with Hazelcast.
 * More details are in {@link HazelcastRepositoryFactory}.
 * </P>
 *
 * @param KeyValueOperations
 * @param Query                Creator
 * @param RepositoryQueryType, not used
 * @return A {@link HazelcastRepositoryFactory} that creates {@link HazelcastRepository} instances.
 */
@Override
protected KeyValueRepositoryFactory createRepositoryFactory(KeyValueOperations operations,
                                                            Class<? extends AbstractQueryCreator<?, ?>> queryCreator,
                                                            Class<? extends RepositoryQuery> repositoryQueryType) {
    Assert.state(hazelcastInstance != null, "HazelcastInstance must be set");

    return new HazelcastRepositoryFactory(operations, queryCreator, hazelcastInstance);
}
 
Example #29
Source File: HazelcastPartTreeQuery.java    From spring-data-hazelcast with Apache License 2.0 3 votes vote down vote up
/**
 * <p>
 * Create a {@link RepositoryQuery} implementation for each query method defined in a {@link HazelcastRepository}.
 * </P>
 *
 * @param queryMethod                Method defined in {@code HazelcastRepository}
 * @param evaluationContextProvider  Not used
 * @param keyValueOperations         Interface to Hazelcast
 * @param queryCreator               Not used
 */
public HazelcastPartTreeQuery(QueryMethod queryMethod, QueryMethodEvaluationContextProvider evaluationContextProvider,
                              KeyValueOperations keyValueOperations,
                              Class<? extends AbstractQueryCreator<?, ?>> queryCreator) {
    super(queryMethod, evaluationContextProvider, keyValueOperations, queryCreator);
    this.queryMethod = queryMethod;
    this.keyValueOperations = keyValueOperations;

    this.isRearrangeKnown = false;
}
 
Example #30
Source File: VaultPartTreeQuery.java    From spring-vault with Apache License 2.0 3 votes vote down vote up
/**
 * Creates a new {@link VaultPartTreeQuery} for the given {@link QueryMethod},
 * {@link EvaluationContextProvider}, {@link KeyValueOperations} and query creator
 * type.
 * @param queryMethod must not be {@literal null}.
 * @param evaluationContextProvider must not be {@literal null}.
 * @param keyValueOperations must not be {@literal null}.
 * @param queryCreator must not be {@literal null}.
 */
@SuppressWarnings("unchecked")
public VaultPartTreeQuery(QueryMethod queryMethod, QueryMethodEvaluationContextProvider evaluationContextProvider,
		KeyValueOperations keyValueOperations, Class<? extends AbstractQueryCreator<?, ?>> queryCreator) {

	super(queryMethod, evaluationContextProvider, keyValueOperations,
			new VaultQueryCreatorFactory((MappingContext) keyValueOperations.getMappingContext()));
}