Java Code Examples for org.springframework.data.repository.query.QueryLookupStrategy#Key

The following examples show how to use org.springframework.data.repository.query.QueryLookupStrategy#Key . 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: ArangoRepositoryFactory.java    From spring-data with Apache License 2.0 6 votes vote down vote up
@Override
protected Optional<QueryLookupStrategy> getQueryLookupStrategy(
		final QueryLookupStrategy.Key key, final QueryMethodEvaluationContextProvider evaluationContextProvider) {

	QueryLookupStrategy strategy = null;
	switch (key) {
	case CREATE_IF_NOT_FOUND:
		strategy = new DefaultArangoQueryLookupStrategy(arangoOperations);
		break;
	case CREATE:
		break;
	case USE_DECLARED_QUERY:
		break;
	}
	return Optional.ofNullable(strategy);
}
 
Example 2
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 3
Source File: ReactiveCosmosRepositoryFactory.java    From spring-data-cosmosdb with MIT License 5 votes vote down vote up
@Override
protected Optional<QueryLookupStrategy> getQueryLookupStrategy(
    QueryLookupStrategy.Key key,
    QueryMethodEvaluationContextProvider evaluationContextProvider) {
    return Optional.of(new ReactiveCosmosQueryLookupStrategy(cosmosOperations,
        evaluationContextProvider));
}
 
Example 4
Source File: AggregateQuerySupportingRepositoryFactory.java    From mongodb-aggregate-query-support with Apache License 2.0 5 votes vote down vote up
@Override
public QueryLookupStrategy getQueryLookupStrategy(QueryLookupStrategy.Key key,
                                                  EvaluationContextProvider evaluationContextProvider) {

  QueryLookupStrategy parentQueryLookupStrategy = super.getQueryLookupStrategy(key, evaluationContextProvider);
  return new AggregateQueryLookupStrategy(parentQueryLookupStrategy);
}
 
Example 5
Source File: NonReactiveAggregateQuerySupportingRepositoryFactory.java    From mongodb-aggregate-query-support with Apache License 2.0 5 votes vote down vote up
@Override
public Optional<QueryLookupStrategy> getQueryLookupStrategy(@Nullable QueryLookupStrategy.Key key,
                                                            QueryMethodEvaluationContextProvider evaluationContextProvider) {

  Optional<QueryLookupStrategy> parentQueryLookupStrategy = super.getQueryLookupStrategy(key, evaluationContextProvider);
  Assert.isTrue(parentQueryLookupStrategy.isPresent(), "Expecting parent lookup strategy");
  return Optional.of(new AggregateQueryLookupStrategy(parentQueryLookupStrategy.get()));
}
 
Example 6
Source File: ReactiveAggregateQuerySupportingRepositoryFactory.java    From mongodb-aggregate-query-support with Apache License 2.0 5 votes vote down vote up
@Override
public Optional<QueryLookupStrategy> getQueryLookupStrategy(QueryLookupStrategy.Key key,
                                                            QueryMethodEvaluationContextProvider evaluationContextProvider) {

  Optional<QueryLookupStrategy> parentQueryLookupStrategy = super.getQueryLookupStrategy(key, evaluationContextProvider);
  Assert.isTrue(parentQueryLookupStrategy.isPresent(), "Expecting parent query lookup strategy to be present");
  return Optional.of(new AggregateQueryLookupStrategy(parentQueryLookupStrategy.get()));
}
 
Example 7
Source File: GenericJpaRepositoryFactory.java    From genericdao with Artistic License 2.0 5 votes vote down vote up
@Override
protected QueryLookupStrategy getQueryLookupStrategy(QueryLookupStrategy.Key key, EvaluationContextProvider evaluationContextProvider) {
	QueryLookupStrategy queryLookupStrategy = GenericQueryLookupStrategy.create(entityManager ,
			sqlSessionTemplate , key , extractor , evaluationContextProvider) ;

	return queryLookupStrategy  ;
}
 
Example 8
Source File: IgniteRepositoryFactory.java    From ignite with Apache License 2.0 5 votes vote down vote up
/** {@inheritDoc} */
@Override protected QueryLookupStrategy getQueryLookupStrategy(final QueryLookupStrategy.Key key,
    EvaluationContextProvider evaluationCtxProvider) {

    return new QueryLookupStrategy() {
        @Override public RepositoryQuery resolveQuery(final Method mtd, final RepositoryMetadata metadata,
            final ProjectionFactory factory, NamedQueries namedQueries) {

            final Query annotation = mtd.getAnnotation(Query.class);

            if (annotation != null) {
                String qryStr = annotation.value();

                if (key != Key.CREATE && StringUtils.hasText(qryStr))
                    return new IgniteRepositoryQuery(metadata,
                        new IgniteQuery(qryStr, isFieldQuery(qryStr), IgniteQueryGenerator.getOptions(mtd)),
                        mtd, factory, ignite.getOrCreateCache(repoToCache.get(metadata.getRepositoryInterface())));
            }

            if (key == QueryLookupStrategy.Key.USE_DECLARED_QUERY)
                throw new IllegalStateException("To use QueryLookupStrategy.Key.USE_DECLARED_QUERY, pass " +
                    "a query string via org.apache.ignite.springdata.repository.config.Query annotation.");

            return new IgniteRepositoryQuery(metadata, IgniteQueryGenerator.generateSql(mtd, metadata), mtd,
                factory, ignite.getOrCreateCache(repoToCache.get(metadata.getRepositoryInterface())));
        }
    };
}
 
Example 9
Source File: IgniteRepositoryFactory.java    From ignite with Apache License 2.0 5 votes vote down vote up
/** {@inheritDoc} */
@Override protected Optional<QueryLookupStrategy> getQueryLookupStrategy(final QueryLookupStrategy.Key key,
    EvaluationContextProvider evaluationContextProvider) {
    return Optional.of((mtd, metadata, factory, namedQueries) -> {
        final Query annotation = mtd.getAnnotation(Query.class);
        final Ignite ignite = repoToIgnite.get(metadata.getRepositoryInterface());

        if (annotation != null && (StringUtils.hasText(annotation.value()) || annotation.textQuery() || annotation
            .dynamicQuery())) {

            String qryStr = annotation.value();

            boolean annotatedIgniteQuery = !annotation.dynamicQuery() && (StringUtils.hasText(qryStr) || annotation
                .textQuery());

            IgniteQuery query = annotatedIgniteQuery ? new IgniteQuery(qryStr,
                !annotation.textQuery() && (isFieldQuery(qryStr) || annotation.forceFieldsQuery()),
                annotation.textQuery(), false, IgniteQueryGenerator.getOptions(mtd)) : null;

            if (key != QueryLookupStrategy.Key.CREATE) {
                return new IgniteRepositoryQuery(ignite, metadata, query, mtd, factory,
                    getRepositoryCache(metadata.getRepositoryInterface()),
                    annotatedIgniteQuery ? DynamicQueryConfig.fromQueryAnnotation(annotation) : null,
                    evaluationContextProvider);
            }
        }

        if (key == QueryLookupStrategy.Key.USE_DECLARED_QUERY) {
            throw new IllegalStateException("To use QueryLookupStrategy.Key.USE_DECLARED_QUERY, pass "
                + "a query string via org.apache.ignite.springdata20.repository"
                + ".config.Query annotation.");
        }

        return new IgniteRepositoryQuery(ignite, metadata, IgniteQueryGenerator.generateSql(mtd, metadata), mtd,
            factory, getRepositoryCache(metadata.getRepositoryInterface()),
            DynamicQueryConfig.fromQueryAnnotation(annotation), evaluationContextProvider);
    });
}
 
Example 10
Source File: IgniteRepositoryFactory.java    From ignite with Apache License 2.0 5 votes vote down vote up
/** {@inheritDoc} */
@Override protected Optional<QueryLookupStrategy> getQueryLookupStrategy(final QueryLookupStrategy.Key key,
    QueryMethodEvaluationContextProvider evaluationContextProvider) {
    return Optional.of((mtd, metadata, factory, namedQueries) -> {
        final Query annotation = mtd.getAnnotation(Query.class);
        final Ignite ignite = repoToIgnite.get(metadata.getRepositoryInterface());

        if (annotation != null && (StringUtils.hasText(annotation.value()) || annotation.textQuery() || annotation
            .dynamicQuery())) {

            String qryStr = annotation.value();

            boolean annotatedIgniteQuery = !annotation.dynamicQuery() && (StringUtils.hasText(qryStr) || annotation
                .textQuery());

            IgniteQuery query = annotatedIgniteQuery ? new IgniteQuery(qryStr,
                !annotation.textQuery() && (isFieldQuery(qryStr) || annotation.forceFieldsQuery()),
                annotation.textQuery(), false, IgniteQueryGenerator.getOptions(mtd)) : null;

            if (key != QueryLookupStrategy.Key.CREATE) {
                return new IgniteRepositoryQuery(ignite, metadata, query, mtd, factory,
                    getRepositoryCache(metadata.getRepositoryInterface()),
                    annotatedIgniteQuery ? DynamicQueryConfig.fromQueryAnnotation(annotation) : null,
                    evaluationContextProvider);
            }
        }

        if (key == QueryLookupStrategy.Key.USE_DECLARED_QUERY) {
            throw new IllegalStateException("To use QueryLookupStrategy.Key.USE_DECLARED_QUERY, pass "
                + "a query string via org.apache.ignite.springdata22.repository"
                + ".config.Query annotation.");
        }

        return new IgniteRepositoryQuery(ignite, metadata, IgniteQueryGenerator.generateSql(mtd, metadata), mtd,
            factory, getRepositoryCache(metadata.getRepositoryInterface()),
            DynamicQueryConfig.fromQueryAnnotation(annotation), evaluationContextProvider);
    });
}
 
Example 11
Source File: HazelcastRepositoryFactory.java    From spring-data-hazelcast with Apache License 2.0 5 votes vote down vote up
/**
 * <p>
 * Ensure the mechanism for query evaluation is Hazelcast specific, as the original
 * {@link KeyValueRepositoryFactory.KeyValueQueryLookupStrategy} does not function correctly for Hazelcast.
 * </P>
 */
@Override
protected Optional<QueryLookupStrategy> getQueryLookupStrategy(QueryLookupStrategy.Key key,
                                                        QueryMethodEvaluationContextProvider evaluationContextProvider) {
    return Optional.of(new HazelcastQueryLookupStrategy(key, evaluationContextProvider, keyValueOperations, queryCreator,
            hazelcastInstance));
}
 
Example 12
Source File: SimpleDbRepositoryFactory.java    From spring-data-simpledb with MIT License 4 votes vote down vote up
@Override
protected QueryLookupStrategy getQueryLookupStrategy(QueryLookupStrategy.Key key) {
	return SimpleDbQueryLookupStrategy.create(simpleDbOperations, key);
}
 
Example 13
Source File: SimpleDbQueryLookupStrategy.java    From spring-data-simpledb with MIT License 4 votes vote down vote up
public static QueryLookupStrategy create(SimpleDbOperations simpleDbOperations, QueryLookupStrategy.Key key) {
	// TODO check in Spring data core key switching and their semantics (look in spring-data-jpa)
	return new SimpleDbQueryLookupStrategy(simpleDbOperations);
}
 
Example 14
Source File: SimpleBaseRepositoryFactoryBean.java    From es with Apache License 2.0 4 votes vote down vote up
@Override
protected QueryLookupStrategy getQueryLookupStrategy(QueryLookupStrategy.Key key) {
    return super.getQueryLookupStrategy(key);
}
 
Example 15
Source File: CrateRepositoryFactory.java    From spring-data-crate with Apache License 2.0 4 votes vote down vote up
@Override
protected QueryLookupStrategy getQueryLookupStrategy(QueryLookupStrategy.Key key, EvaluationContextProvider evaluationContextProvider) {
    return new CrateQueryLookupStrategy();
}
 
Example 16
Source File: GenericJpaRepositoryFactory.java    From spring-data-jpa-extra with Apache License 2.0 4 votes vote down vote up
protected Optional<QueryLookupStrategy> getQueryLookupStrategy(@Nullable QueryLookupStrategy.Key key,
                                                               EvaluationContextProvider evaluationContextProvider) {
    return Optional.of(TemplateQueryLookupStrategy.create(entityManager, key, extractor, evaluationContextProvider));
}
 
Example 17
Source File: EbeanRepositoryFactory.java    From spring-data-ebean with Apache License 2.0 4 votes vote down vote up
@Override
protected Optional<QueryLookupStrategy> getQueryLookupStrategy(QueryLookupStrategy.Key key,
                                                               QueryMethodEvaluationContextProvider evaluationContextProvider) {
    return Optional.ofNullable(EbeanQueryLookupStrategy.create(ebeanServer, key, evaluationContextProvider));
}
 
Example 18
Source File: ReactiveFirestoreRepositoryFactory.java    From spring-cloud-gcp with Apache License 2.0 4 votes vote down vote up
@Override
protected Optional<QueryLookupStrategy> getQueryLookupStrategy(@Nullable QueryLookupStrategy.Key key,
		QueryMethodEvaluationContextProvider evaluationContextProvider) {
	return Optional.of(new FirestoreQueryLookupStrategy(this.firestoreTemplate));
}
 
Example 19
Source File: CosmosRepositoryFactory.java    From spring-data-cosmosdb with MIT License 4 votes vote down vote up
@Override
protected Optional<QueryLookupStrategy> getQueryLookupStrategy(
        QueryLookupStrategy.Key key, QueryMethodEvaluationContextProvider evaluationContextProvider) {
    return Optional.of(new CosmosDbQueryLookupStrategy(cosmosOperations, evaluationContextProvider));
}