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.
This commit is contained in:
@@ -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.</a> licensed under the Apache License, Version 2.0. <br />
|
||||
* Formatted and modified.
|
||||
*
|
||||
* @since 2.2
|
||||
* @author Jeff Yemin
|
||||
* @author Ross Lawley
|
||||
* @since 2.2
|
||||
*/
|
||||
class DateTimeFormatter {
|
||||
|
||||
|
||||
@@ -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.</a> licensed under the Apache License, Version 2.0. <br />
|
||||
* Formatted and modified.
|
||||
*
|
||||
* @since 2.2
|
||||
*
|
||||
* @author Jeff Yemin
|
||||
* @author Ross Lawley
|
||||
* @since 2.2
|
||||
*/
|
||||
class JsonBuffer {
|
||||
|
||||
|
||||
@@ -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.</a> licensed under the Apache License, Version 2.0. <br />
|
||||
* 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:
|
||||
*
|
||||
*
|
||||
* <pre>
|
||||
* /pattern/
|
||||
* /\(pattern\)/
|
||||
* /pattern/ims
|
||||
* </pre>
|
||||
*
|
||||
*
|
||||
* 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:
|
||||
*
|
||||
*
|
||||
* <pre>
|
||||
* 12
|
||||
* 123
|
||||
|
||||
@@ -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.</a> licensed under the Apache License, Version 2.0. <br />
|
||||
*
|
||||
* @since 2.2
|
||||
* @author Jeff Yemin
|
||||
* @author Ross Lawley
|
||||
* @since 2.2
|
||||
*/
|
||||
class JsonToken {
|
||||
|
||||
|
||||
@@ -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.</a> licensed under the Apache License, Version 2.0. <br />
|
||||
*
|
||||
* @since 2.2
|
||||
* @author Jeff Yemin
|
||||
* @author Ross Lawley
|
||||
* @since 2.2
|
||||
*/
|
||||
enum JsonTokenType {
|
||||
/**
|
||||
|
||||
@@ -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</a> licensed under the Apache License, Version 2.0. <br />
|
||||
*
|
||||
* @since 2.2
|
||||
* @author Jeff Yemin
|
||||
* @author Ross Lawley
|
||||
* @author Ralph Schaer
|
||||
* @author Christoph Strobl
|
||||
* @since 2.2
|
||||
*/
|
||||
public class ParameterBindingDocumentCodec implements CollectibleCodec<Document> {
|
||||
|
||||
@@ -78,7 +89,6 @@ public class ParameterBindingDocumentCodec implements CollectibleCodec<Document>
|
||||
* 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<Document>
|
||||
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<Document>
|
||||
return document;
|
||||
}
|
||||
|
||||
// Spring Data Customization END
|
||||
|
||||
@Override
|
||||
public Class<Document> getEncoderClass() {
|
||||
return Document.class;
|
||||
@@ -254,11 +267,12 @@ public class ParameterBindingDocumentCodec implements CollectibleCodec<Document>
|
||||
|
||||
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<Document>
|
||||
}
|
||||
}
|
||||
|
||||
// Spring Data Customization END
|
||||
|
||||
BsonType bsonType = reader.getCurrentBsonType();
|
||||
if (bsonType == BsonType.NULL) {
|
||||
reader.readNull();
|
||||
@@ -281,6 +297,7 @@ public class ParameterBindingDocumentCodec implements CollectibleCodec<Document>
|
||||
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<Document>
|
||||
}
|
||||
|
||||
return valueTransformer.transform(codecToUse.decode(reader, decoderContext));
|
||||
// Spring Data Customization END
|
||||
}
|
||||
|
||||
private List<Object> readList(final BsonReader reader, final DecoderContext decoderContext) {
|
||||
@@ -296,12 +314,14 @@ public class ParameterBindingDocumentCodec implements CollectibleCodec<Document>
|
||||
List<Object> 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;
|
||||
|
||||
@@ -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 <a href=
|
||||
* "https://github.com/mongodb/mongo-java-driver/blob/master/bson/src/main/org/bson/json/JsonReader.java">MongoDB Inc.
|
||||
* JsonReader</a> licensed under the Apache License, Version 2.0. <br />
|
||||
*
|
||||
*
|
||||
* @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
|
||||
}
|
||||
|
||||
@@ -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<byte[]> 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());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user