|
1 |
| -/* |
2 |
| - * Copyright 2018 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.mongodb.core.validation; |
17 |
| - |
18 |
| -import lombok.AccessLevel; |
19 |
| -import lombok.EqualsAndHashCode; |
20 |
| -import lombok.RequiredArgsConstructor; |
21 |
| - |
22 |
| -import org.bson.Document; |
23 |
| -import org.springframework.data.mongodb.core.query.Criteria; |
24 |
| -import org.springframework.data.mongodb.core.query.CriteriaDefinition; |
25 |
| -import org.springframework.data.mongodb.core.query.SerializationUtils; |
26 |
| -import org.springframework.util.Assert; |
27 |
| - |
28 |
| -/** |
29 |
| - * {@link Validator} implementation based on {@link CriteriaDefinition query expressions}. |
30 |
| - * |
31 |
| - * @author Andreas Zink |
32 |
| - * @author Christoph Strobl |
33 |
| - * @since 2.1 |
34 |
| - * @see Criteria |
35 |
| - * @see <a href="https://docs.mongodb.com/manual/core/schema-validation/#query-expressions">Schema Validation</a> |
36 |
| - */ |
37 |
| -@RequiredArgsConstructor(access = AccessLevel.PRIVATE) |
38 |
| -@EqualsAndHashCode |
39 |
| -public class CriteriaValidator implements Validator { |
40 |
| - |
41 |
| - private final CriteriaDefinition criteria; |
42 |
| - |
43 |
| - /** |
44 |
| - * Creates a new {@link Validator} object, which is basically setup of query operators, based on a |
45 |
| - * {@link CriteriaDefinition} instance. |
46 |
| - * |
47 |
| - * @param criteria the criteria to build the {@code validator} from. Must not be {@literal null}. |
48 |
| - * @return new instance of {@link CriteriaValidator}. |
49 |
| - * @throws IllegalArgumentException when criteria is {@literal null}. |
50 |
| - */ |
51 |
| - public static CriteriaValidator of(CriteriaDefinition criteria) { |
52 |
| - |
53 |
| - Assert.notNull(criteria, "Criteria must not be null!"); |
54 |
| - return new CriteriaValidator(criteria); |
55 |
| - } |
56 |
| - |
57 |
| - /* |
58 |
| - * (non-Javadoc) |
59 |
| - * @see org.springframework.data.mongodb.core.validation.Validator#toDocument() |
60 |
| - */ |
61 |
| - @Override |
62 |
| - public Document toDocument() { |
63 |
| - return criteria.getCriteriaObject(); |
64 |
| - } |
65 |
| - |
66 |
| - /* |
67 |
| - * (non-Javadoc) |
68 |
| - * @see java.lang.Object#toString() |
69 |
| - */ |
70 |
| - @Override |
71 |
| - public String toString() { |
72 |
| - return SerializationUtils.serializeToJsonSafely(toDocument()); |
73 |
| - } |
74 |
| - |
75 |
| -} |
| 1 | +/* |
| 2 | + * Copyright 2018 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.mongodb.core.validation; |
| 17 | + |
| 18 | +import lombok.AccessLevel; |
| 19 | +import lombok.EqualsAndHashCode; |
| 20 | +import lombok.RequiredArgsConstructor; |
| 21 | + |
| 22 | +import org.bson.Document; |
| 23 | +import org.springframework.data.mongodb.core.query.Criteria; |
| 24 | +import org.springframework.data.mongodb.core.query.CriteriaDefinition; |
| 25 | +import org.springframework.data.mongodb.core.query.SerializationUtils; |
| 26 | +import org.springframework.util.Assert; |
| 27 | + |
| 28 | +/** |
| 29 | + * {@link Validator} implementation based on {@link CriteriaDefinition query expressions}. |
| 30 | + * |
| 31 | + * @author Andreas Zink |
| 32 | + * @author Christoph Strobl |
| 33 | + * @since 2.1 |
| 34 | + * @see Criteria |
| 35 | + * @see <a href="https://docs.mongodb.com/manual/core/schema-validation/#query-expressions">Schema Validation</a> |
| 36 | + */ |
| 37 | +@RequiredArgsConstructor(access = AccessLevel.PRIVATE) |
| 38 | +@EqualsAndHashCode |
| 39 | +class CriteriaValidator implements Validator { |
| 40 | + |
| 41 | + private final CriteriaDefinition criteria; |
| 42 | + |
| 43 | + /** |
| 44 | + * Creates a new {@link Validator} object, which is basically setup of query operators, based on a |
| 45 | + * {@link CriteriaDefinition} instance. |
| 46 | + * |
| 47 | + * @param criteria the criteria to build the {@code validator} from. Must not be {@literal null}. |
| 48 | + * @return new instance of {@link CriteriaValidator}. |
| 49 | + * @throws IllegalArgumentException when criteria is {@literal null}. |
| 50 | + */ |
| 51 | + static CriteriaValidator of(CriteriaDefinition criteria) { |
| 52 | + |
| 53 | + Assert.notNull(criteria, "Criteria must not be null!"); |
| 54 | + |
| 55 | + return new CriteriaValidator(criteria); |
| 56 | + } |
| 57 | + |
| 58 | + /* |
| 59 | + * (non-Javadoc) |
| 60 | + * @see org.springframework.data.mongodb.core.validation.Validator#toDocument() |
| 61 | + */ |
| 62 | + @Override |
| 63 | + public Document toDocument() { |
| 64 | + return criteria.getCriteriaObject(); |
| 65 | + } |
| 66 | + |
| 67 | + /* |
| 68 | + * (non-Javadoc) |
| 69 | + * @see java.lang.Object#toString() |
| 70 | + */ |
| 71 | + @Override |
| 72 | + public String toString() { |
| 73 | + return SerializationUtils.serializeToJsonSafely(toDocument()); |
| 74 | + } |
| 75 | +} |
0 commit comments