EMMA Coverage Report (generated Mon Jan 28 16:15:17 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 2012 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 */
40public class ElasticsearchRepositoryFactory extends RepositoryFactorySupport {
41 
42    private final ElasticsearchOperations elasticsearchOperations;
43    private final ElasticsearchEntityInformationCreator entityInformationCreator;
44 
45    public ElasticsearchRepositoryFactory(ElasticsearchOperations elasticsearchOperations) {
46        Assert.notNull(elasticsearchOperations);
47        this.elasticsearchOperations = elasticsearchOperations;
48        this.entityInformationCreator = new ElasticsearchEntityInformationCreatorImpl(elasticsearchOperations.getElasticsearchConverter()
49                .getMappingContext());
50    }
51 
52    @Override
53    public <T, ID extends Serializable> ElasticsearchEntityInformation<T, ID> getEntityInformation(Class<T> domainClass) {
54        return entityInformationCreator.getEntityInformation(domainClass);
55    }
56 
57    @Override
58    @SuppressWarnings({ "rawtypes", "unchecked" })
59    protected Object getTargetRepository(RepositoryMetadata metadata) {
60        SimpleElasticsearchRepository repository = new SimpleElasticsearchRepository(getEntityInformation(metadata.getDomainType()), elasticsearchOperations);
61        repository.setEntityClass(metadata.getDomainType());
62        return repository;
63    }
64 
65    @Override
66    protected Class<?> getRepositoryBaseClass(RepositoryMetadata metadata) {
67        if (isQueryDslRepository(metadata.getRepositoryInterface())) {
68            throw new IllegalArgumentException("QueryDsl Support has not been implemented yet.");
69        }
70        return SimpleElasticsearchRepository.class;
71    }
72 
73    private static boolean isQueryDslRepository(Class<?> repositoryInterface) {
74        return QUERY_DSL_PRESENT && QueryDslPredicateExecutor.class.isAssignableFrom(repositoryInterface);
75    }
76 
77    @Override
78    protected QueryLookupStrategy getQueryLookupStrategy(QueryLookupStrategy.Key key) {
79        return new ElasticsearchQueryLookupStrategy();
80    }
81 
82    private class ElasticsearchQueryLookupStrategy implements QueryLookupStrategy {
83 
84        @Override
85        public RepositoryQuery resolveQuery(Method method, RepositoryMetadata metadata, NamedQueries namedQueries) {
86 
87            ElasticsearchQueryMethod queryMethod = new ElasticsearchQueryMethod(method, metadata, entityInformationCreator);
88            String namedQueryName = queryMethod.getNamedQueryName();
89 
90            if (namedQueries.hasQuery(namedQueryName)) {
91                String namedQuery = namedQueries.getQuery(namedQueryName);
92                return new ElasticsearchStringQuery(queryMethod, elasticsearchOperations, namedQuery);
93            }
94            else if (queryMethod.hasAnnotatedQuery()) {
95                return new ElasticsearchStringQuery(queryMethod, elasticsearchOperations, queryMethod.getAnnotatedQuery());
96            }
97            return new ElasticsearchPartQuery(queryMethod, elasticsearchOperations);
98        }
99    }
100 
101}

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