EMMA Coverage Report (generated Tue Mar 05 16:36:55 GMT 2013)
[all classes][org.springframework.data.elasticsearch.repository.support]

COVERAGE SUMMARY FOR SOURCE FILE [ElasticsearchRepositoryFactory.java]

nameclass, %method, %block, %line, %
ElasticsearchRepositoryFactory.java67%  (2/3)100% (11/11)82%  (106/130)85%  (20.4/24)

COVERAGE BREAKDOWN BY CLASS AND METHOD

nameclass, %method, %block, %line, %
     
class ElasticsearchRepositoryFactory$ElasticsearchQueryLookupStrategy100% (1/1)100% (3/3)78%  (47/60)78%  (7/9)
resolveQuery (Method, RepositoryMetadata, NamedQueries): RepositoryQuery 100% (1/1)74%  (37/50)75%  (6/8)
ElasticsearchRepositoryFactory$ElasticsearchQueryLookupStrategy (Elasticsearc... 100% (1/1)100% (6/6)100% (1/1)
ElasticsearchRepositoryFactory$ElasticsearchQueryLookupStrategy (Elasticsearc... 100% (1/1)100% (4/4)100% (1/1)
     
class ElasticsearchRepositoryFactory100% (1/1)100% (8/8)84%  (59/70)89%  (13.4/15)
isQueryDslRepository (Class): boolean 100% (1/1)40%  (4/10)40%  (0.4/1)
getRepositoryBaseClass (RepositoryMetadata): Class 100% (1/1)55%  (6/11)67%  (2/3)
ElasticsearchRepositoryFactory (ElasticsearchOperations): void 100% (1/1)100% (16/16)100% (5/5)
access$100 (ElasticsearchRepositoryFactory): ElasticsearchEntityInformationCr... 100% (1/1)100% (3/3)100% (1/1)
access$200 (ElasticsearchRepositoryFactory): ElasticsearchOperations 100% (1/1)100% (3/3)100% (1/1)
getEntityInformation (Class): ElasticsearchEntityInformation 100% (1/1)100% (5/5)100% (1/1)
getQueryLookupStrategy (QueryLookupStrategy$Key): QueryLookupStrategy 100% (1/1)100% (6/6)100% (1/1)
getTargetRepository (RepositoryMetadata): Object 100% (1/1)100% (16/16)100% (3/3)
     
class ElasticsearchRepositoryFactory$10%   (0/1)100% (0/0)100% (0/0)100% (0/0)

1/*
2 * Copyright 2013 the original author or authors.
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16package org.springframework.data.elasticsearch.repository.support;
17 
18import org.springframework.data.elasticsearch.core.ElasticsearchOperations;
19import org.springframework.data.elasticsearch.repository.ElasticsearchRepository;
20import org.springframework.data.elasticsearch.repository.query.ElasticsearchPartQuery;
21import org.springframework.data.elasticsearch.repository.query.ElasticsearchQueryMethod;
22import org.springframework.data.elasticsearch.repository.query.ElasticsearchStringQuery;
23import org.springframework.data.querydsl.QueryDslPredicateExecutor;
24import org.springframework.data.repository.core.NamedQueries;
25import org.springframework.data.repository.core.RepositoryMetadata;
26import org.springframework.data.repository.core.support.RepositoryFactorySupport;
27import org.springframework.data.repository.query.QueryLookupStrategy;
28import org.springframework.data.repository.query.RepositoryQuery;
29import org.springframework.util.Assert;
30 
31import java.io.Serializable;
32import java.lang.reflect.Method;
33 
34import static org.springframework.data.querydsl.QueryDslUtils.QUERY_DSL_PRESENT;
35 
36/**
37 * Factory to create {@link ElasticsearchRepository}
38 *
39 * @author Rizwan Idrees
40 * @author Mohsin Husen
41 */
42public class ElasticsearchRepositoryFactory extends RepositoryFactorySupport {
43 
44    private final ElasticsearchOperations elasticsearchOperations;
45    private final ElasticsearchEntityInformationCreator entityInformationCreator;
46 
47    public ElasticsearchRepositoryFactory(ElasticsearchOperations elasticsearchOperations) {
48        Assert.notNull(elasticsearchOperations);
49        this.elasticsearchOperations = elasticsearchOperations;
50        this.entityInformationCreator = new ElasticsearchEntityInformationCreatorImpl(elasticsearchOperations.getElasticsearchConverter()
51                .getMappingContext());
52    }
53 
54    @Override
55    public <T, ID extends Serializable> ElasticsearchEntityInformation<T, ID> getEntityInformation(Class<T> domainClass) {
56        return entityInformationCreator.getEntityInformation(domainClass);
57    }
58 
59    @Override
60    @SuppressWarnings({ "rawtypes", "unchecked" })
61    protected Object getTargetRepository(RepositoryMetadata metadata) {
62        SimpleElasticsearchRepository repository = new SimpleElasticsearchRepository(getEntityInformation(metadata.getDomainType()), elasticsearchOperations);
63        repository.setEntityClass(metadata.getDomainType());
64        return repository;
65    }
66 
67    @Override
68    protected Class<?> getRepositoryBaseClass(RepositoryMetadata metadata) {
69        if (isQueryDslRepository(metadata.getRepositoryInterface())) {
70            throw new IllegalArgumentException("QueryDsl Support has not been implemented yet.");
71        }
72        return SimpleElasticsearchRepository.class;
73    }
74 
75    private static boolean isQueryDslRepository(Class<?> repositoryInterface) {
76        return QUERY_DSL_PRESENT && QueryDslPredicateExecutor.class.isAssignableFrom(repositoryInterface);
77    }
78 
79    @Override
80    protected QueryLookupStrategy getQueryLookupStrategy(QueryLookupStrategy.Key key) {
81        return new ElasticsearchQueryLookupStrategy();
82    }
83 
84    private class ElasticsearchQueryLookupStrategy implements QueryLookupStrategy {
85 
86        @Override
87        public RepositoryQuery resolveQuery(Method method, RepositoryMetadata metadata, NamedQueries namedQueries) {
88 
89            ElasticsearchQueryMethod queryMethod = new ElasticsearchQueryMethod(method, metadata, entityInformationCreator);
90            String namedQueryName = queryMethod.getNamedQueryName();
91 
92            if (namedQueries.hasQuery(namedQueryName)) {
93                String namedQuery = namedQueries.getQuery(namedQueryName);
94                return new ElasticsearchStringQuery(queryMethod, elasticsearchOperations, namedQuery);
95            }
96            else if (queryMethod.hasAnnotatedQuery()) {
97                return new ElasticsearchStringQuery(queryMethod, elasticsearchOperations, queryMethod.getAnnotatedQuery());
98            }
99            return new ElasticsearchPartQuery(queryMethod, elasticsearchOperations);
100        }
101    }
102 
103}

[all classes][org.springframework.data.elasticsearch.repository.support]
EMMA 2.0.5312 (C) Vladimir Roubtsov