1 /*
2 * Copyright 2017-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.jpa.projection;
17
18 import java.beans.PropertyDescriptor;
19 import java.util.Collection;
20 import java.util.Map;
21
22 import org.springframework.data.projection.ProjectionInformation;
23 import org.springframework.data.projection.SpelAwareProxyProjectionFactory;
24
25 /**
26 * A {@link org.springframework.data.projection.ProjectionFactory} considering projections containing collections or
27 * maps to be open.
28 *
29 * @author Jens Schauder
30 * @author Oliver Gierke
31 */
32 public class CollectionAwareProjectionFactory extends SpelAwareProxyProjectionFactory {
33
34 /*
35 * (non-Javadoc)
36 * @see org.springframework.data.projection.SpelAwareProxyProjectionFactory#createProjectionInformation(java.lang.Class)
37 */
38 @Override
39 protected ProjectionInformation createProjectionInformation(Class<?> projectionType) {
40 return new CollectionAwareProjectionInformation(projectionType);
41 }
42
43 private static class CollectionAwareProjectionInformation extends SpelAwareProjectionInformation {
44
45 CollectionAwareProjectionInformation(Class<?> projectionType) {
46 super(projectionType);
47 }
48
49 /*
50 * (non-Javadoc)
51 * @see org.springframework.data.projection.SpelAwareProxyProjectionFactory.SpelAwareProjectionInformation#isInputProperty(java.beans.PropertyDescriptor)
52 */
53 @Override
54 protected boolean isInputProperty(PropertyDescriptor descriptor) {
55
56 if (!super.isInputProperty(descriptor)) {
57 return false;
58 }
59
60 return !(Collection.class.isAssignableFrom(descriptor.getPropertyType()) //
61 || Map.class.isAssignableFrom(descriptor.getPropertyType()));
62 }
63 }
64 }
65