From b8f1062ac2c140fa3c6c808e9843bd962063ff95 Mon Sep 17 00:00:00 2001 From: Mark Paluch Date: Mon, 18 Feb 2019 13:31:36 +0100 Subject: [PATCH] DATAMONGO-2199 - Polishing. Align copyright years with forked code. Add customization markers to identify code blocks that were altered (in comparison to the original code) for future fork updates. Original pull request: #643. --- .../mongodb/util/json/DateTimeFormatter.java | 4 +-- .../data/mongodb/util/json/JsonBuffer.java | 6 ++-- .../data/mongodb/util/json/JsonScanner.java | 12 ++++---- .../data/mongodb/util/json/JsonToken.java | 4 +-- .../data/mongodb/util/json/JsonTokenType.java | 4 +-- .../json/ParameterBindingDocumentCodec.java | 30 +++++++++++++++---- .../util/json/ParameterBindingJsonReader.java | 29 ++++++++++++++++-- .../ParameterBindingJsonReaderUnitTests.java | 22 ++------------ 8 files changed, 69 insertions(+), 42 deletions(-) diff --git a/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/util/json/DateTimeFormatter.java b/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/util/json/DateTimeFormatter.java index d9c16c1c1..ff1cbd6db 100644 --- a/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/util/json/DateTimeFormatter.java +++ b/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/util/json/DateTimeFormatter.java @@ -1,5 +1,5 @@ /* - * Copyright 2019 the original author or authors. + * Copyright 2008-2019 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -34,9 +34,9 @@ import java.util.TimeZone; * Inc. licensed under the Apache License, Version 2.0.
* Formatted and modified. * - * @since 2.2 * @author Jeff Yemin * @author Ross Lawley + * @since 2.2 */ class DateTimeFormatter { diff --git a/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/util/json/JsonBuffer.java b/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/util/json/JsonBuffer.java index 185a90d4c..de7eef287 100644 --- a/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/util/json/JsonBuffer.java +++ b/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/util/json/JsonBuffer.java @@ -1,5 +1,5 @@ /* - * Copyright 2019 the original author or authors. + * Copyright 2008-2019 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -22,10 +22,10 @@ import org.bson.json.JsonParseException; * "https://github.com/mongodb/mongo-java-driver/blob/master/bson/src/main/org/bson/json/JsonBuffer.java">MongoDB * Inc. licensed under the Apache License, Version 2.0.
* Formatted and modified. - * - * @since 2.2 + * * @author Jeff Yemin * @author Ross Lawley + * @since 2.2 */ class JsonBuffer { diff --git a/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/util/json/JsonScanner.java b/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/util/json/JsonScanner.java index f38a2a8ca..6534f4a10 100644 --- a/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/util/json/JsonScanner.java +++ b/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/util/json/JsonScanner.java @@ -1,5 +1,5 @@ /* - * Copyright 2019 the original author or authors. + * Copyright 2008-2019 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -24,13 +24,13 @@ import org.bson.json.JsonParseException; * "https://github.com/mongodb/mongo-java-driver/blob/master/bson/src/main/org/bson/json/JsonScanner.java">MongoDB * Inc. licensed under the Apache License, Version 2.0.
* Formatted and modified to allow reading Spring Data specific placeholder values. - * - * @since 2.2 + * * @author Jeff Yemin * @author Trisha Gee * @author Robert Guo * @author Ross Lawley * @author Christoph Strobl + * @since 2.2 */ class JsonScanner { @@ -122,13 +122,13 @@ class JsonScanner { /** * Reads {@code RegularExpressionToken} from source. The following variants of lexemes are possible: - * + * *
 	 *  /pattern/
 	 *  /\(pattern\)/
 	 *  /pattern/ims
 	 * 
- * + * * Options can include 'i','m','x','s' * * @return The regular expression token. @@ -295,7 +295,7 @@ class JsonScanner { /** * Reads number token from source. The following variants of lexemes are possible: - * + * *
 	 *  12
 	 *  123
diff --git a/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/util/json/JsonToken.java b/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/util/json/JsonToken.java
index 2b13ebde4..8f3195151 100644
--- a/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/util/json/JsonToken.java
+++ b/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/util/json/JsonToken.java
@@ -1,5 +1,5 @@
 /*
- * Copyright 2019 the original author or authors.
+ * Copyright 2008-2019 the original author or authors.
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -26,9 +26,9 @@ import org.bson.types.Decimal128;
  * "https://github.com/mongodb/mongo-java-driver/blob/master/bson/src/main/org/bson/json/JsonToken.java">MongoDB
  * Inc. licensed under the Apache License, Version 2.0. 
* - * @since 2.2 * @author Jeff Yemin * @author Ross Lawley + * @since 2.2 */ class JsonToken { diff --git a/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/util/json/JsonTokenType.java b/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/util/json/JsonTokenType.java index bda090c92..0bc2a9891 100644 --- a/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/util/json/JsonTokenType.java +++ b/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/util/json/JsonTokenType.java @@ -1,5 +1,5 @@ /* - * Copyright 2019 the original author or authors. + * Copyright 2008-2019 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -20,9 +20,9 @@ package org.springframework.data.mongodb.util.json; * "https://github.com/mongodb/mongo-java-driver/blob/master/bson/src/main/org/bson/json/JsonTokenType.java">MongoDB * Inc. licensed under the Apache License, Version 2.0.
* - * @since 2.2 * @author Jeff Yemin * @author Ross Lawley + * @since 2.2 */ enum JsonTokenType { /** diff --git a/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/util/json/ParameterBindingDocumentCodec.java b/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/util/json/ParameterBindingDocumentCodec.java index 740cd6add..f0d7d311a 100644 --- a/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/util/json/ParameterBindingDocumentCodec.java +++ b/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/util/json/ParameterBindingDocumentCodec.java @@ -1,5 +1,5 @@ /* - * Copyright 2019 the original author or authors. + * Copyright 2008-2019 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -35,8 +35,19 @@ import org.bson.BsonValue; import org.bson.BsonWriter; import org.bson.Document; import org.bson.Transformer; -import org.bson.codecs.*; +import org.bson.codecs.BsonTypeClassMap; +import org.bson.codecs.BsonTypeCodecMap; +import org.bson.codecs.BsonValueCodecProvider; +import org.bson.codecs.Codec; +import org.bson.codecs.CollectibleCodec; +import org.bson.codecs.DecoderContext; +import org.bson.codecs.DocumentCodecProvider; +import org.bson.codecs.EncoderContext; +import org.bson.codecs.IdGenerator; +import org.bson.codecs.ObjectIdGenerator; +import org.bson.codecs.ValueCodecProvider; import org.bson.codecs.configuration.CodecRegistry; + import org.springframework.data.spel.EvaluationContextProvider; import org.springframework.expression.spel.standard.SpelExpressionParser; import org.springframework.lang.Nullable; @@ -49,11 +60,11 @@ import org.springframework.util.StringUtils; * "https://github.com/mongodb/mongo-java-driver/blob/master/bson/src/main/org/bson/codecs/DocumentCodec.java">MongoDB * Inc. DocumentCodec licensed under the Apache License, Version 2.0.
* - * @since 2.2 * @author Jeff Yemin * @author Ross Lawley * @author Ralph Schaer * @author Christoph Strobl + * @since 2.2 */ public class ParameterBindingDocumentCodec implements CollectibleCodec { @@ -78,7 +89,6 @@ public class ParameterBindingDocumentCodec implements CollectibleCodec * Construct a new instance with the given registry. * * @param registry the registry - * @since 3.5 */ public ParameterBindingDocumentCodec(final CodecRegistry registry) { this(registry, DEFAULT_BSON_TYPE_CLASS_MAP); @@ -156,6 +166,7 @@ public class ParameterBindingDocumentCodec implements CollectibleCodec writeMap(writer, document, encoderContext); } + // Spring Data Customization START public Document decode(@Nullable String json, Object[] values) { return decode(json, new ParameterBindingContext((index) -> values[index], new SpelExpressionParser(), @@ -197,6 +208,8 @@ public class ParameterBindingDocumentCodec implements CollectibleCodec return document; } + // Spring Data Customization END + @Override public Class getEncoderClass() { return Document.class; @@ -254,11 +267,12 @@ public class ParameterBindingDocumentCodec implements CollectibleCodec private Object readValue(final BsonReader reader, final DecoderContext decoderContext) { + // Spring Data Customization START if (reader instanceof ParameterBindingJsonReader) { ParameterBindingJsonReader bindingReader = (ParameterBindingJsonReader) reader; - // check if the reader has actually found something to replaceand did so. + // check if the reader has actually found something to replace and did so. // resets the reader state to move on after the actual value // returns the replacement value if (bindingReader.currentValue != null) { @@ -270,6 +284,8 @@ public class ParameterBindingDocumentCodec implements CollectibleCodec } } + // Spring Data Customization END + BsonType bsonType = reader.getCurrentBsonType(); if (bsonType == BsonType.NULL) { reader.readNull(); @@ -281,6 +297,7 @@ public class ParameterBindingDocumentCodec implements CollectibleCodec return registry.get(UUID.class).decode(reader, decoderContext); } + // Spring Data Customization START // By default the registry uses DocumentCodec for parsing. // We need to reroute that to our very own implementation or we'll end up only mapping half the placeholders. Codec codecToUse = bsonTypeCodecMap.get(bsonType); @@ -289,6 +306,7 @@ public class ParameterBindingDocumentCodec implements CollectibleCodec } return valueTransformer.transform(codecToUse.decode(reader, decoderContext)); + // Spring Data Customization END } private List readList(final BsonReader reader, final DecoderContext decoderContext) { @@ -296,12 +314,14 @@ public class ParameterBindingDocumentCodec implements CollectibleCodec List list = new ArrayList<>(); while (reader.readBsonType() != BsonType.END_OF_DOCUMENT) { + // Spring Data Customization START Object listValue = readValue(reader, decoderContext); if (listValue instanceof Collection) { list.addAll((Collection) listValue); break; } list.add(listValue); + // Spring Data Customization END } reader.readEndArray(); return list; diff --git a/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/util/json/ParameterBindingJsonReader.java b/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/util/json/ParameterBindingJsonReader.java index 4eb2f08d5..fc385729a 100644 --- a/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/util/json/ParameterBindingJsonReader.java +++ b/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/util/json/ParameterBindingJsonReader.java @@ -1,5 +1,5 @@ /* - * Copyright 2019 the original author or authors. + * Copyright 2008-2019 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -36,6 +36,7 @@ import org.bson.types.Decimal128; import org.bson.types.MaxKey; import org.bson.types.MinKey; import org.bson.types.ObjectId; + import org.springframework.data.spel.EvaluationContextProvider; import org.springframework.expression.EvaluationContext; import org.springframework.expression.spel.standard.SpelExpressionParser; @@ -47,7 +48,7 @@ import org.springframework.util.NumberUtils; * Reads a JSON and evaluates placehoders and SpEL expressions. Modified version of MongoDB Inc. * JsonReader licensed under the Apache License, Version 2.0.
- * + * * @author Jeff Yemin * @author Ross Lawley * @author Thrisha Gee @@ -55,6 +56,7 @@ import org.springframework.util.NumberUtils; * @author Florian Buecklers * @author Brendon Puntin * @author Christoph Strobl + * @since 2.2 */ public class ParameterBindingJsonReader extends AbstractBsonReader { @@ -78,6 +80,8 @@ public class ParameterBindingJsonReader extends AbstractBsonReader { this(json, new Object[] {}); } + // Spring Data Customization START + /** * Constructs a new instance with the given JSON string. * @@ -116,6 +120,8 @@ public class ParameterBindingJsonReader extends AbstractBsonReader { } } + // Spring Data Customization END + @Override protected BsonBinary doReadBinaryData() { return (BsonBinary) currentValue; @@ -156,7 +162,12 @@ public class ParameterBindingJsonReader extends AbstractBsonReader { switch (nameToken.getType()) { case STRING: case UNQUOTED_STRING: + + // Spring Data Customization START + setCurrentName(bindableValueFor(nameToken).getValue().toString()); + + // Spring Data Customization END break; case END_OBJECT: setState(State.END_OF_DOCUMENT); @@ -177,6 +188,8 @@ public class ParameterBindingJsonReader extends AbstractBsonReader { return BsonType.END_OF_DOCUMENT; } + // Spring Data Customization START + boolean noValueFound = false; BindableValue bindableValue = null; @@ -297,6 +310,9 @@ public class ParameterBindingJsonReader extends AbstractBsonReader { noValueFound = true; break; } + + // Spring Data Customization END + if (noValueFound) { throw new JsonParseException("JSON reader was expecting a value but found '%s'.", token.getValue()); } @@ -324,6 +340,8 @@ public class ParameterBindingJsonReader extends AbstractBsonReader { return getCurrentBsonType(); } + // Spring Data Customization START + @Override public void setState(State newState) { super.setState(newState); @@ -434,6 +452,7 @@ public class ParameterBindingJsonReader extends AbstractBsonReader { return bindingContext.evaluateExpression(expressionString); } + // Spring Data Customization END // CHECKSTYLE:ON @Override @@ -1311,7 +1330,9 @@ public class ParameterBindingJsonReader extends AbstractBsonReader { throw new JsonParseException("JSON reader expected a string but found '%s'.", patternToken.getValue()); } + // Spring Data Customization START return bindableValueFor(patternToken).getValue().toString(); + // Spring Data Customization END } private String visitSymbolExtendedJson() { @@ -1576,6 +1597,8 @@ public class ParameterBindingJsonReader extends AbstractBsonReader { return out; } + // Spring Data Customization START + @Data static class BindableValue { @@ -1583,4 +1606,6 @@ public class ParameterBindingJsonReader extends AbstractBsonReader { Object value; int index; } + + // Spring Data Customization END } diff --git a/spring-data-mongodb/src/test/java/org/springframework/data/mongodb/util/json/ParameterBindingJsonReaderUnitTests.java b/spring-data-mongodb/src/test/java/org/springframework/data/mongodb/util/json/ParameterBindingJsonReaderUnitTests.java index 8f5061b83..912986eab 100644 --- a/spring-data-mongodb/src/test/java/org/springframework/data/mongodb/util/json/ParameterBindingJsonReaderUnitTests.java +++ b/spring-data-mongodb/src/test/java/org/springframework/data/mongodb/util/json/ParameterBindingJsonReaderUnitTests.java @@ -1,19 +1,3 @@ -/* - * Copyright 2019. the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - /* * Copyright 2019 the original author or authors. * @@ -44,7 +28,6 @@ import org.junit.Test; /** * @author Christoph Strobl - * @since 2019/02 */ public class ParameterBindingJsonReaderUnitTests { @@ -138,7 +121,7 @@ public class ParameterBindingJsonReaderUnitTests { byte[] value = "Kohlin".getBytes(StandardCharsets.UTF_8); List args = Collections.singletonList(value); - Document target = parse("{ 'lastname' : { $in : ?0 } }",args); + Document target = parse("{ 'lastname' : { $in : ?0 } }", args); assertThat(target).isEqualTo(new Document("lastname", new Document("$in", args))); } @@ -178,8 +161,7 @@ public class ParameterBindingJsonReaderUnitTests { private static Document parse(String json, Object... args) { ParameterBindingJsonReader reader = new ParameterBindingJsonReader(json, args); - return new ParameterBindingDocumentCodec().decode(reader, - DecoderContext.builder().build()); + return new ParameterBindingDocumentCodec().decode(reader, DecoderContext.builder().build()); } }