Package org.springframework.data.repository.query

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


      this.repositoryInformation = repositoryInformation;
      this.customImplementation = customImplementation;
      this.target = target;

      QueryLookupStrategy lookupStrategy = getQueryLookupStrategy(queryLookupStrategyKey,
          RepositoryFactorySupport.this.evaluationContextProvider);
      lookupStrategy = lookupStrategy == null ? getQueryLookupStrategy(queryLookupStrategyKey) : lookupStrategy;
      Iterable<Method> queryMethods = repositoryInformation.getQueryMethods();

      if (lookupStrategy == null) {

        if (queryMethods.iterator().hasNext()) {
          throw new IllegalStateException("You have defined query method in the repository but "
              + "you don't have any query lookup strategy defined. The "
              + "infrastructure apparently does not support query methods!");
        }

        return;
      }

      for (Method method : queryMethods) {
        RepositoryQuery query = lookupStrategy.resolveQuery(method, repositoryInformation, namedQueries);
        invokeListeners(query);
        queries.put(method, query);
      }
    }
View Full Code Here


   * @see DATAJPA-226
   */
  @Test
  public void invalidAnnotatedQueryCausesException() throws Exception {

    QueryLookupStrategy strategy = JpaQueryLookupStrategy.create(em, Key.CREATE_IF_NOT_FOUND, extractor,
        DefaultEvaluationContextProvider.INSTANCE);
    Method method = UserRepository.class.getMethod("findByFoo", String.class);
    RepositoryMetadata metadata = new DefaultRepositoryMetadata(UserRepository.class);

    Throwable reference = new RuntimeException();
    when(em.createQuery(anyString())).thenThrow(reference);

    try {
      strategy.resolveQuery(method, metadata, namedQueries);
    } catch (Exception e) {
      assertThat(e, is(instanceOf(IllegalArgumentException.class)));
      assertThat(e.getCause(), is(reference));
    }
  }
View Full Code Here

   * @see DATAJPA-554
   */
  @Test
  public void sholdThrowMorePreciseExceptionIfTryingToUsePaginationInNativeQueries() throws Exception {

    QueryLookupStrategy strategy = JpaQueryLookupStrategy.create(em, Key.CREATE_IF_NOT_FOUND, extractor,
        DefaultEvaluationContextProvider.INSTANCE);
    Method method = UserRepository.class.getMethod("findByInvalidNativeQuery", String.class, Pageable.class);
    RepositoryMetadata metadata = new DefaultRepositoryMetadata(UserRepository.class);

    exception.expect(InvalidJpaQueryMethodException.class);
    exception.expectMessage("Cannot use native queries with dynamic sorting and/or pagination in method");
    exception.expectMessage(method.toString());

    strategy.resolveQuery(method, metadata, namedQueries);
  }
View Full Code Here

   * @see springframework.data.repository.core.support.RepositoryFactorySupport
   *   #getQueryLookupStrategy(org.springframework.data.repository.query.QueryLookupStrategy.Key)
   */
  @Override
  protected QueryLookupStrategy getQueryLookupStrategy(Key key) {
    return new QueryLookupStrategy() {
      @Override
      public RepositoryQuery resolveQuery(Method method, RepositoryMetadata metadata, NamedQueries namedQueries) {
        GemfireQueryMethod queryMethod = new GemfireQueryMethod(method, metadata, context);
        GemfireTemplate template = getTemplate(metadata);

View Full Code Here

TOP

Related Classes of org.springframework.data.repository.query.QueryLookupStrategy

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.