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 | */ |
16 | package org.springframework.data.elasticsearch.repository.support; |
17 | |
18 | import org.springframework.data.elasticsearch.core.mapping.ElasticsearchPersistentEntity; |
19 | import org.springframework.data.elasticsearch.core.mapping.ElasticsearchPersistentProperty; |
20 | import org.springframework.data.mapping.context.MappingContext; |
21 | import org.springframework.util.Assert; |
22 | |
23 | import java.io.Serializable; |
24 | |
25 | /** |
26 | * ElasticsearchEntityInformationCreatorImpl |
27 | * |
28 | * @author Rizwan Idrees |
29 | * @author Mohsin Husen |
30 | */ |
31 | public class ElasticsearchEntityInformationCreatorImpl implements ElasticsearchEntityInformationCreator { |
32 | |
33 | private final MappingContext<? extends ElasticsearchPersistentEntity<?>, ElasticsearchPersistentProperty> mappingContext; |
34 | |
35 | public ElasticsearchEntityInformationCreatorImpl( |
36 | MappingContext<? extends ElasticsearchPersistentEntity<?>, ElasticsearchPersistentProperty> mappingContext) { |
37 | Assert.notNull(mappingContext); |
38 | this.mappingContext = mappingContext; |
39 | } |
40 | |
41 | @Override |
42 | @SuppressWarnings("unchecked") |
43 | public <T, ID extends Serializable> ElasticsearchEntityInformation<T, ID> getEntityInformation(Class<T> domainClass) { |
44 | ElasticsearchPersistentEntity<T> persistentEntity = (ElasticsearchPersistentEntity<T>) mappingContext |
45 | .getPersistentEntity(domainClass); |
46 | return new MappingElasticsearchEntityInformation<T, ID>(persistentEntity); |
47 | } |
48 | |
49 | } |