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.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 | */ |
30 | public class ElasticsearchRepositoryFactoryBean<T extends Repository<S, ID>, S, ID extends Serializable> extends |
31 | RepositoryFactoryBeanSupport<T, S, ID> { |
32 | |
33 | private ElasticsearchOperations operations; |
34 | |
35 | /** |
36 | * Configures the {@link ElasticsearchOperations} to be used to create Elasticsearch repositories. |
37 | * |
38 | * @param operations the operations to set |
39 | */ |
40 | public void setElasticsearchOperations(ElasticsearchOperations operations) { |
41 | Assert.notNull(operations); |
42 | this.operations = operations; |
43 | } |
44 | |
45 | /* |
46 | * (non-Javadoc) |
47 | * @see org.springframework.data.repository.core.support.RepositoryFactoryBeanSupport#afterPropertiesSet() |
48 | */ |
49 | @Override |
50 | public void afterPropertiesSet() { |
51 | super.afterPropertiesSet(); |
52 | Assert.notNull(operations, "ElasticsearchOperations must be configured!"); |
53 | } |
54 | |
55 | |
56 | @Override |
57 | protected RepositoryFactorySupport createRepositoryFactory() { |
58 | return new ElasticsearchRepositoryFactory(operations); |
59 | } |
60 | |
61 | } |