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 | */ |
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 | public class ElasticsearchEntityInformationCreatorImpl implements ElasticsearchEntityInformationCreator { |
26 | |
27 | private final MappingContext<? extends ElasticsearchPersistentEntity<?>, ElasticsearchPersistentProperty> mappingContext; |
28 | |
29 | public ElasticsearchEntityInformationCreatorImpl( |
30 | MappingContext<? extends ElasticsearchPersistentEntity<?>, ElasticsearchPersistentProperty> mappingContext) { |
31 | Assert.notNull(mappingContext); |
32 | this.mappingContext = mappingContext; |
33 | } |
34 | |
35 | @Override |
36 | @SuppressWarnings("unchecked") |
37 | public <T, ID extends Serializable> ElasticsearchEntityInformation<T, ID> getEntityInformation(Class<T> domainClass) { |
38 | ElasticsearchPersistentEntity<T> persistentEntity = (ElasticsearchPersistentEntity<T>) mappingContext |
39 | .getPersistentEntity(domainClass); |
40 | return new MappingElasticsearchEntityInformation<T, ID>(persistentEntity); |
41 | } |
42 | |
43 | } |