org.springframework.data.repository.query.QueryLookupStrategy Java Examples

The following examples show how to use org.springframework.data.repository.query.QueryLookupStrategy. 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: MybatisQueryLookupStrategy.java    From spring-data-mybatis with Apache License 2.0 6 votes vote down vote up
public static QueryLookupStrategy create(SqlSessionTemplate sqlSessionTemplate,
		Key key, QueryMethodEvaluationContextProvider evaluationContextProvider) {

	Assert.notNull(sqlSessionTemplate, "SqlSessionTemplate must not be null!");
	Assert.notNull(evaluationContextProvider,
			"EvaluationContextProvider must not be null!");

	switch (key != null ? key : Key.CREATE_IF_NOT_FOUND) {
	case CREATE:
		return new CreateQueryLookupStrategy(sqlSessionTemplate);
	case USE_DECLARED_QUERY:
		return new DeclaredQueryLookupStrategy(sqlSessionTemplate,
				evaluationContextProvider);
	case CREATE_IF_NOT_FOUND:
		return new CreateIfNotFoundQueryLookupStrategy(sqlSessionTemplate,
				new CreateQueryLookupStrategy(sqlSessionTemplate),
				new DeclaredQueryLookupStrategy(sqlSessionTemplate,
						evaluationContextProvider));
	default:
		throw new IllegalArgumentException(
				String.format("Unsupported query lookup strategy %s!", key));
	}
}
 
Example #4
Source File: DynamoDBQueryLookupStrategy.java    From spring-data-dynamodb with Apache License 2.0 6 votes vote down vote up
/**
 * Creates a {@link QueryLookupStrategy} for the given
 * {@link DynamoDBMapper} and {@link Key}.
 *
 * @param dynamoDBOperations
 * @param key
 * @return
 */
public static QueryLookupStrategy create(DynamoDBOperations dynamoDBOperations, Key key) {

	if (key == null) {
		return new CreateQueryLookupStrategy(dynamoDBOperations);
	}

	switch (key) {
	case CREATE:
		return new CreateQueryLookupStrategy(dynamoDBOperations);
	case USE_DECLARED_QUERY:
		throw new IllegalArgumentException(String.format("Unsupported query lookup strategy %s!", key));
	case CREATE_IF_NOT_FOUND:
		return new CreateIfNotFoundQueryLookupStrategy(dynamoDBOperations);
	default:
		throw new IllegalArgumentException(String.format("Unsupported query lookup strategy %s!", key));
	}
}
 
Example #5
Source File: EbeanQueryLookupStrategy.java    From spring-data-ebean with Apache License 2.0 6 votes vote down vote up
/**
 * Creates a {@link QueryLookupStrategy} for the given {@link EbeanServer} and {@link Key}.
 *
 * @param ebeanServer               must not be {@literal null}.
 * @param key                       may be {@literal null}.
 * @param evaluationContextProvider must not be {@literal null}.
 * @return
 */
public static QueryLookupStrategy create(EbeanServer ebeanServer, Key key,
                                         QueryMethodEvaluationContextProvider evaluationContextProvider) {

    Assert.notNull(ebeanServer, "EbeanServer must not be null!");
    Assert.notNull(evaluationContextProvider, "EvaluationContextProvider must not be null!");

    switch (key != null ? key : Key.CREATE_IF_NOT_FOUND) {
        case CREATE:
            return new CreateQueryLookupStrategy(ebeanServer);
        case USE_DECLARED_QUERY:
            return new DeclaredQueryLookupStrategy(ebeanServer, evaluationContextProvider);
        case CREATE_IF_NOT_FOUND:
            return new CreateIfNotFoundQueryLookupStrategy(ebeanServer, new CreateQueryLookupStrategy(ebeanServer),
                    new DeclaredQueryLookupStrategy(ebeanServer, evaluationContextProvider));
        default:
            throw new IllegalArgumentException(String.format("Unsupported query lookup strategy %s!", key));
    }
}
 
Example #6
Source File: AggregateQueryProvider2Test.java    From mongodb-aggregate-query-support with Apache License 2.0 5 votes vote down vote up
@Test(dataProvider = "queryMethods", expectedExceptions = {JsonParseException.class})
public void testCreateAggregateQuery(String methodName) throws Exception {
  NonReactiveAggregateQuerySupportingRepositoryFactory factory =
      new NonReactiveAggregateQuerySupportingRepositoryFactory(mongoOperations, queryExecutor);
  Optional<QueryLookupStrategy> lookupStrategy = factory.getQueryLookupStrategy(CREATE_IF_NOT_FOUND, evaluationContextProvider);
  assertTrue(lookupStrategy.isPresent(), "Expecting non null lookupStrategy");
  Method method = TestAggregateRepository22.class.getMethod(methodName);
  RepositoryMetadata repositoryMetadata = new DefaultRepositoryMetadata(TestAggregateRepository22.class);
  ProjectionFactory projectionFactory = new SpelAwareProxyProjectionFactory();
  RepositoryQuery query = lookupStrategy.get().resolveQuery(method, repositoryMetadata, projectionFactory, null);
  assertNotNull(query);
  Object object = query.execute(new Object[0]);
  assertNull(object);
}
 
Example #7
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 #8
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 #9
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 #10
Source File: ReactiveNeo4jRepositoryFactory.java    From sdn-rx with Apache License 2.0 5 votes vote down vote up
@Override
protected Optional<QueryLookupStrategy> getQueryLookupStrategy(Key key,
	QueryMethodEvaluationContextProvider evaluationContextProvider) {

	return Optional
		.of(new ReactiveNeo4jQueryLookupStrategy(neo4jOperations, mappingContext, evaluationContextProvider));
}
 
Example #11
Source File: ReactiveAggregateQueryProviderTest.java    From mongodb-aggregate-query-support with Apache License 2.0 5 votes vote down vote up
@Test(dataProvider = "queryMethods", expectedExceptions = {JsonParseException.class})
public void testCreateAggregateQuery(String methodName) throws Exception {
  ReactiveAggregateQuerySupportingRepositoryFactory factory = new ReactiveAggregateQuerySupportingRepositoryFactory(mongoOperations,
                                                                                                                    queryExecutor);
  Optional<QueryLookupStrategy> lookupStrategy = factory.getQueryLookupStrategy(CREATE_IF_NOT_FOUND, evaluationContextProvider);

  Assert.isTrue(lookupStrategy.isPresent(), "Lookup strategy must not be null");
  Method method = ReactiveTestAggregateRepository22.class.getMethod(methodName);
  RepositoryMetadata repositoryMetadata = new DefaultRepositoryMetadata(ReactiveTestAggregateRepository22.class);
  ProjectionFactory projectionFactory = new SpelAwareProxyProjectionFactory();
  RepositoryQuery query = lookupStrategy.get().resolveQuery(method, repositoryMetadata, projectionFactory, null);
  assertNotNull(query);
  Object object = query.execute(new Object[0]);
  assertNull(object);
}
 
Example #12
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 #13
Source File: MybatisRepositoryFactory.java    From spring-data-mybatis with Apache License 2.0 5 votes vote down vote up
@Override
protected Optional<QueryLookupStrategy> getQueryLookupStrategy(Key key,
		QueryMethodEvaluationContextProvider evaluationContextProvider) {

	return Optional.of(MybatisQueryLookupStrategy.create(sqlSessionTemplate, key,
			evaluationContextProvider));
}
 
Example #14
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 #15
Source File: AclJpaRepositoryFactoryBean.java    From strategy-spring-security-acl with Apache License 2.0 5 votes vote down vote up
/**
 * @since Spring data JPA 1.10.0
 */
public RepositoryQuery resolveQuery(Method method, RepositoryMetadata metadata,
      ProjectionFactory factory, NamedQueries namedQueries) {
  QueryLookupStrategy queryLookupStrategy =
      Factory.super.getQueryLookupStrategy(key, evaluationContextProvider);

  RepositoryQuery query = queryLookupStrategy.resolveQuery(method, metadata, factory, namedQueries);
  return wrapQuery(method, metadata, query);
}
 
Example #16
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 #17
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 #18
Source File: AggregateQueryProvider2Test.java    From mongodb-aggregate-query-support with Apache License 2.0 5 votes vote down vote up
@Test(dataProvider = "queryMethods", expectedExceptions = {JsonParseException.class})
public void testCreateAggregateQuery(String methodName) throws Exception {
  AggregateQuerySupportingRepositoryFactory factory = new AggregateQuerySupportingRepositoryFactory(mongoOperations,
                                                                                                    queryExecutor);
  QueryLookupStrategy lookupStrategy = factory.getQueryLookupStrategy(CREATE_IF_NOT_FOUND, evaluationContextProvider);

  Method method = TestAggregateRepository22.class.getMethod(methodName);
  RepositoryMetadata repositoryMetadata = new DefaultRepositoryMetadata(TestAggregateRepository22.class);
  ProjectionFactory projectionFactory = new SpelAwareProxyProjectionFactory();
  RepositoryQuery query = lookupStrategy.resolveQuery(method, repositoryMetadata, projectionFactory, null);
  assertNotNull(query);
  Object object = query.execute(new Object[0]);
  assertNull(object);
}
 
Example #19
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 #20
Source File: SpannerRepositoryFactory.java    From spring-cloud-gcp with Apache License 2.0 5 votes vote down vote up
@Override
protected Optional<QueryLookupStrategy> getQueryLookupStrategy(@Nullable Key key,
		QueryMethodEvaluationContextProvider evaluationContextProvider) {

	return Optional.of(new SpannerQueryLookupStrategy(this.spannerMappingContext,
			this.spannerTemplate,
			delegateContextProvider(evaluationContextProvider), EXPRESSION_PARSER));
}
 
Example #21
Source File: DatastoreRepositoryFactory.java    From spring-cloud-gcp with Apache License 2.0 5 votes vote down vote up
@Override
protected Optional<QueryLookupStrategy> getQueryLookupStrategy(@Nullable Key key,
		QueryMethodEvaluationContextProvider evaluationContextProvider) {

	return Optional.of(new DatastoreQueryLookupStrategy(this.datastoreMappingContext,
			this.datastoreOperations,
			delegateContextProvider(evaluationContextProvider)));
}
 
Example #22
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 #23
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 #24
Source File: ReactiveAggregateQuerySupportingRepositoryFactory.java    From mongodb-aggregate-query-support with Apache License 2.0 4 votes vote down vote up
AggregateQueryLookupStrategy(QueryLookupStrategy parentQueryLookupStrategy) {
  this.parentQueryLookupStrategy = parentQueryLookupStrategy;
}
 
Example #25
Source File: KeyValueRepositoryFactory.java    From spring-data-keyvalue with Apache License 2.0 4 votes vote down vote up
@Override
protected Optional<QueryLookupStrategy> getQueryLookupStrategy(@Nullable Key key,
		QueryMethodEvaluationContextProvider evaluationContextProvider) {
	return Optional.of(new KeyValueQueryLookupStrategy(key, evaluationContextProvider, this.keyValueOperations,
			this.queryCreator, this.repositoryQueryType));
}
 
Example #26
Source File: DynamoDBRepositoryFactory.java    From spring-data-dynamodb with Apache License 2.0 4 votes vote down vote up
@Override
protected QueryLookupStrategy getQueryLookupStrategy(Key key) {
	return DynamoDBQueryLookupStrategy.create(dynamoDBOperations, key);
}
 
Example #27
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 #28
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 #29
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 #30
Source File: GenericQueryLookupStrategy.java    From genericdao with Artistic License 2.0 4 votes vote down vote up
public static QueryLookupStrategy create(EntityManager entityManager, SqlSessionTemplate sqlSessionTemplate  ,
                                         Key key, QueryExtractor extractor, EvaluationContextProvider evaluationContextProvider) {
    return new GenericQueryLookupStrategy(entityManager , sqlSessionTemplate ,
            key , extractor , evaluationContextProvider);
}