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.ElasticsearchOperations; |
19 | import org.springframework.data.repository.Repository; |
20 | import org.springframework.data.repository.core.support.RepositoryFactoryBeanSupport; |
21 | import org.springframework.data.repository.core.support.RepositoryFactorySupport; |
22 | import org.springframework.util.Assert; |
23 | |
24 | import java.io.Serializable; |
25 | |
26 | /** |
27 | * Spring {@link org.springframework.beans.factory.FactoryBean} implementation to ease container based configuration for XML namespace and JavaConfig. |
28 | * |
29 | * @author Rizwan Idrees |
30 | * @author Mohsin Husen |
31 | */ |
32 | public class ElasticsearchRepositoryFactoryBean<T extends Repository<S, ID>, S, ID extends Serializable> extends |
33 | RepositoryFactoryBeanSupport<T, S, ID> { |
34 | |
35 | private ElasticsearchOperations operations; |
36 | |
37 | /** |
38 | * Configures the {@link ElasticsearchOperations} to be used to create Elasticsearch repositories. |
39 | * |
40 | * @param operations the operations to set |
41 | */ |
42 | public void setElasticsearchOperations(ElasticsearchOperations operations) { |
43 | Assert.notNull(operations); |
44 | this.operations = operations; |
45 | } |
46 | |
47 | /* |
48 | * (non-Javadoc) |
49 | * @see org.springframework.data.repository.core.support.RepositoryFactoryBeanSupport#afterPropertiesSet() |
50 | */ |
51 | @Override |
52 | public void afterPropertiesSet() { |
53 | super.afterPropertiesSet(); |
54 | Assert.notNull(operations, "ElasticsearchOperations must be configured!"); |
55 | } |
56 | |
57 | |
58 | @Override |
59 | protected RepositoryFactorySupport createRepositoryFactory() { |
60 | return new ElasticsearchRepositoryFactory(operations); |
61 | } |
62 | |
63 | } |