1 /*
2 * Copyright 2019-2020 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 * https://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.mapping.model;
17
18 import lombok.RequiredArgsConstructor;
19
20 import org.springframework.data.mapping.PersistentEntity;
21 import org.springframework.data.mapping.PersistentPropertyAccessor;
22
23 /**
24 * Delegating {@link PersistentPropertyAccessorFactory} decorating the {@link PersistentPropertyAccessor}s created with
25 * an {@link InstantiationAwarePropertyAccessor} to allow the handling of purely immutable types.
26 *
27 * @author Oliver Drotbohm
28 * @author Mark Paluch
29 * @since 2.3
30 */
31 @RequiredArgsConstructor
32 public class InstantiationAwarePropertyAccessorFactory implements PersistentPropertyAccessorFactory {
33
34 private final PersistentPropertyAccessorFactory delegate;
35 private final EntityInstantiators instantiators;
36
37 /*
38 * (non-Javadoc)
39 * @see org.springframework.data.mapping.model.PersistentPropertyAccessorFactory#getPropertyAccessor(org.springframework.data.mapping.PersistentEntity, java.lang.Object)
40 */
41 @Override
42 public <T> PersistentPropertyAccessor<T> getPropertyAccessor(PersistentEntity<?, ?> entity, T bean) {
43 return new InstantiationAwarePropertyAccessor<>(bean, it -> delegate.getPropertyAccessor(entity, it),
44 instantiators);
45 }
46
47 /*
48 * (non-Javadoc)
49 * @see org.springframework.data.mapping.model.PersistentPropertyAccessorFactory#isSupported(org.springframework.data.mapping.PersistentEntity)
50 */
51 @Override
52 public boolean isSupported(PersistentEntity<?, ?> entity) {
53 return delegate.isSupported(entity);
54 }
55 }
56