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 [MappingElasticsearchEntityInformation.java]

nameclass, %method, %block, %line, %
MappingElasticsearchEntityInformation.java100% (1/1)71%  (5/7)55%  (46/84)65%  (10.4/16)

COVERAGE BREAKDOWN BY CLASS AND METHOD

nameclass, %method, %block, %line, %
     
class MappingElasticsearchEntityInformation100% (1/1)71%  (5/7)55%  (46/84)65%  (10.4/16)
getIdAttribute (): String 0%   (0/1)0%   (0/23)0%   (0/2)
getIdType (): Class 0%   (0/1)0%   (0/2)0%   (0/1)
getId (Object): Serializable 100% (1/1)63%  (12/19)50%  (2/4)
getIndexName (): String 100% (1/1)70%  (7/10)70%  (0.7/1)
getType (): String 100% (1/1)70%  (7/10)70%  (0.7/1)
MappingElasticsearchEntityInformation (ElasticsearchPersistentEntity): void 100% (1/1)100% (6/6)100% (2/2)
MappingElasticsearchEntityInformation (ElasticsearchPersistentEntity, String,... 100% (1/1)100% (14/14)100% (5/5)

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.mapping.ElasticsearchPersistentEntity;
19import org.springframework.data.elasticsearch.core.mapping.ElasticsearchPersistentProperty;
20import org.springframework.data.mapping.model.BeanWrapper;
21import org.springframework.data.repository.core.support.AbstractEntityInformation;
22import org.springframework.util.Assert;
23 
24import java.io.Serializable;
25 
26/**
27 * Elasticsearch specific implementation of {@link org.springframework.data.repository.core.support.AbstractEntityInformation}
28 *
29 * @param <T>
30 * @param <ID>
31 */
32public class MappingElasticsearchEntityInformation<T, ID extends Serializable> extends AbstractEntityInformation<T, ID>
33        implements ElasticsearchEntityInformation<T, ID> {
34 
35    private final ElasticsearchPersistentEntity<T> entityMetadata;
36    private final String indexName;
37    private final String type;
38 
39    public MappingElasticsearchEntityInformation(ElasticsearchPersistentEntity<T> entity) {
40        this(entity, null, null);
41    }
42 
43    public MappingElasticsearchEntityInformation(ElasticsearchPersistentEntity<T> entity, String indexName, String type) {
44        super(entity.getType());
45        this.entityMetadata = entity;
46        this.indexName = indexName;
47        this.type = type;
48    }
49 
50    @SuppressWarnings("unchecked")
51    @Override
52    public ID getId(T entity) {
53        ElasticsearchPersistentProperty id = entityMetadata.getIdProperty();
54        try {
55            return (ID) BeanWrapper.create(entity, null).getProperty(id);
56        } catch (Exception e) {
57            throw new IllegalStateException("ID could not be resolved", e);
58        }
59    }
60 
61    @SuppressWarnings("unchecked")
62    @Override
63    public Class<ID> getIdType() {
64        return (Class<ID>) String.class;
65    }
66 
67    @Override
68    public String getIdAttribute() {
69        Assert.notNull(entityMetadata.getIdProperty(),"Unable to identify 'id' property in class " + entityMetadata.getType().getSimpleName() +". Make sure the 'id' property is annotated with @Id or named as 'id' or 'documentId' ");
70        return entityMetadata.getIdProperty().getFieldName();
71    }
72 
73    @Override
74    public String getIndexName() {
75        return indexName != null?  indexName : entityMetadata.getIndexName();
76    }
77 
78    @Override
79    public String getType() {
80        return type != null? type : entityMetadata.getIndexType();
81    }
82}

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