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

The following examples show how to use org.springframework.data.repository.query.QueryLookupStrategy. These examples are extracted from open source projects. 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 Project: spring-data   Source File: ArangoRepositoryFactory.java    License: 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
/**
 * 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 3
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
/**
 * <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 5
/**
 * 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 6
Source Project: sdn-rx   Source File: ReactiveNeo4jRepositoryFactory.java    License: 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 7
@Override
protected Optional<QueryLookupStrategy> getQueryLookupStrategy(
    QueryLookupStrategy.Key key,
    QueryMethodEvaluationContextProvider evaluationContextProvider) {
    return Optional.of(new ReactiveCosmosQueryLookupStrategy(cosmosOperations,
        evaluationContextProvider));
}
 
Example 8
@Override
protected Optional<QueryLookupStrategy> getQueryLookupStrategy(@Nullable Key key,
		QueryMethodEvaluationContextProvider evaluationContextProvider) {

	return Optional.of(new DatastoreQueryLookupStrategy(this.datastoreMappingContext,
			this.datastoreOperations,
			delegateContextProvider(evaluationContextProvider)));
}
 
Example 9
Source Project: spring-cloud-gcp   Source File: SpannerRepositoryFactory.java    License: 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 10
@Override
public QueryLookupStrategy getQueryLookupStrategy(QueryLookupStrategy.Key key,
                                                  EvaluationContextProvider evaluationContextProvider) {

  QueryLookupStrategy parentQueryLookupStrategy = super.getQueryLookupStrategy(key, evaluationContextProvider);
  return new AggregateQueryLookupStrategy(parentQueryLookupStrategy);
}
 
Example 11
@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 12
@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 13
@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 14
@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 15
@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 16
@Override
protected Optional<QueryLookupStrategy> getQueryLookupStrategy(Key key,
		QueryMethodEvaluationContextProvider evaluationContextProvider) {

	return Optional.of(MybatisQueryLookupStrategy.create(sqlSessionTemplate, key,
			evaluationContextProvider));
}
 
Example 17
/**
 * @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 18
Source Project: genericdao   Source File: GenericJpaRepositoryFactory.java    License: 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 19
Source Project: ignite   Source File: IgniteRepositoryFactory.java    License: 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 20
Source Project: ignite   Source File: IgniteRepositoryFactory.java    License: 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 21
Source Project: ignite   Source File: IgniteRepositoryFactory.java    License: 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 22
/**
 * <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 23
Source Project: sdn-rx   Source File: Neo4jRepositoryFactory.java    License: Apache License 2.0 4 votes vote down vote up
@Override
protected Optional<QueryLookupStrategy> getQueryLookupStrategy(Key key,
		QueryMethodEvaluationContextProvider evaluationContextProvider) {

	return Optional.of(new Neo4jQueryLookupStrategy(neo4jOperations, mappingContext, evaluationContextProvider));
}
 
Example 24
Source Project: dubbox   Source File: SolrRepositoryFactory.java    License: Apache License 2.0 4 votes vote down vote up
@Override
protected QueryLookupStrategy getQueryLookupStrategy(Key key) {
	return new SolrQueryLookupStrategy();
}
 
Example 25
Source Project: spring-data-cosmosdb   Source File: CosmosRepositoryFactory.java    License: 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));
}
 
Example 26
@Test
public void getQueryLookupStrategyTest() {
	Optional<QueryLookupStrategy> qls = this.spannerRepositoryFactory
			.getQueryLookupStrategy(null, mock(QueryMethodEvaluationContextProvider.class));
	assertThat(qls.get()).isInstanceOf(SpannerQueryLookupStrategy.class);
}
 
Example 27
@Override
protected Optional<QueryLookupStrategy> getQueryLookupStrategy(@Nullable QueryLookupStrategy.Key key,
		QueryMethodEvaluationContextProvider evaluationContextProvider) {
	return Optional.of(new FirestoreQueryLookupStrategy(this.firestoreTemplate));
}
 
Example 28
Source Project: spring-data-ebean   Source File: EbeanRepositoryFactory.java    License: 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 29
protected Optional<QueryLookupStrategy> getQueryLookupStrategy(@Nullable QueryLookupStrategy.Key key,
                                                               EvaluationContextProvider evaluationContextProvider) {
    return Optional.of(TemplateQueryLookupStrategy.create(entityManager, key, extractor, evaluationContextProvider));
}
 
Example 30
public static QueryLookupStrategy create(EntityManager entityManager, Key key, QueryExtractor extractor,
                                         EvaluationContextProvider evaluationContextProvider) {
    return new TemplateQueryLookupStrategy(entityManager, key, extractor, evaluationContextProvider);
}