Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Revert "Handled dollar prefixed values for "createOrReplace" Mongo implementation" #213

Merged
merged 1 commit into from
Oct 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
},
{
"name": "Mars",
"color": "$Red",
"color": "Red",
"humans_live": "possibly in future",
"tags": {}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
},
{
"name": "Mars",
"color": "$Red",
"color": "Red",
"humans_live": "possibly in future",
"tags": {}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,8 @@
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.node.ArrayNode;
import com.fasterxml.jackson.databind.node.JsonNodeFactory;
import com.fasterxml.jackson.databind.node.ObjectNode;
import com.fasterxml.jackson.databind.node.TextNode;
import com.mongodb.BasicDBObject;
import com.mongodb.client.model.ReturnDocument;
import java.io.IOException;
Expand All @@ -37,7 +35,6 @@
public final class MongoUtils {
public static final String FIELD_SEPARATOR = ".";
public static final String PREFIX = "$";
private static final String UNICODE_FOR_FIELD_PREFIX = "\\u0024";
private static final String LITERAL = PREFIX + "literal";
private static final String UNSUPPORTED_OPERATION = "No MongoDB support available for: '%s'";
private static final ObjectMapper MAPPER = new ObjectMapper();
Expand All @@ -57,19 +54,15 @@ public static String encodeKey(final String key) {
return null;
}

return key.replace("\\", "\\\\")
.replace(PREFIX, UNICODE_FOR_FIELD_PREFIX)
.replace(FIELD_SEPARATOR, "\\u002e");
return key.replace("\\", "\\\\").replace(PREFIX, "\\u0024").replace(FIELD_SEPARATOR, "\\u002e");
}

public static String decodeKey(final String key) {
if (key == null) {
return null;
}

return key.replace("\\u002e", FIELD_SEPARATOR)
.replace(UNICODE_FOR_FIELD_PREFIX, PREFIX)
.replace("\\\\", "\\");
return key.replace("\\u002e", FIELD_SEPARATOR).replace("\\u0024", PREFIX).replace("\\\\", "\\");
}

public static String getLastField(final String fieldPath) {
Expand Down Expand Up @@ -106,10 +99,6 @@ public static JsonNode recursiveClone(
JsonNode src,
UnaryOperator<String> function,
final UnaryOperator<ObjectNode> emptyObjectConverter) {
if (src.isTextual()) {
return new TextNode(function.apply(src.asText()));
}

if (!src.isObject()) {
return src;
}
Expand All @@ -124,17 +113,6 @@ public static JsonNode recursiveClone(
if (value.isObject()) {
newValue = recursiveClone(value, function, emptyObjectConverter);
}
if (value.isArray()) {
newValue = new ArrayNode(JsonNodeFactory.instance);
for (int i = 0; i < value.size(); i++) {
final JsonNode elementValue =
recursiveClone(value.get(i), function, emptyObjectConverter);
((ArrayNode) newValue).add(elementValue);
}
}
if (newValue.isTextual()) {
newValue = new TextNode(function.apply(newValue.asText()));
}
tgt.set(newFieldName, newValue);
}
return tgt.isEmpty() ? emptyObjectConverter.apply(tgt) : tgt;
Expand Down
Loading