Package io.debezium.connector.mongodb
Class FieldSelector.Path
- java.lang.Object
-
- io.debezium.connector.mongodb.FieldSelector.Path
-
- Direct Known Subclasses:
FieldSelector.RemovePath,FieldSelector.RenamePath
- Enclosing class:
- FieldSelector
@ThreadSafe private abstract static class FieldSelector.Path extends Object
Represents a field that should be excluded from or renamed in MongoDB documents.
-
-
Field Summary
Fields Modifier and Type Field Description (package private) Stringfield(package private) String[]fieldNodes(package private) PatternnamespacePattern
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description private <T> List<T>add(List<T> list, T element)(package private) StringcheckFieldExists(org.bson.Document doc, String field)private String[]excludeNumericItems(String[] items)Excludes numeric items from the given array.(package private) abstract FieldSelector.FieldNameAndValuegenerateNewFieldName(String[] fieldNodes, Object value)Generates a new field name for the given value.booleanmatches(String namespace)Whether this path applies to the given collection namespace or not.voidmodify(org.bson.Document doc, org.bson.Document setDoc, org.bson.Document unsetDoc)Applies the transformation represented by this path, i.e.(package private) abstract voidmodifyField(org.bson.Document doc, String field)Modifies the field in the document used for read, insert and full update operations.private voidmodifyFields(Object value, String[] fieldNodes, int length)private voidmodifyFields(org.bson.Document doc, String[] nodes, int beginIndex)Modifies fields in the document by the given path nodes start with the begin index.private voidmodifyFieldsWithDotNotation(org.bson.Document doc)Modifies fields that use the dot notation, like'a.b'or'a.0.b'.(package private) abstract voidmodifyFieldWithDotNotation(org.bson.Document doc, String field)Immediately modifies the field that uses the dot notation like'a.b'in the document used for set and unset update operations.private booleanstartsWith(String[] begin, String[] source)Returnstrueif the source array starts with the specified array.StringtoString()
-
-
-
Method Detail
-
matches
public boolean matches(String namespace)
Whether this path applies to the given collection namespace or not.- Parameters:
namespace- namespace to match- Returns:
trueif this path applies to the given collection namespace
-
modify
public void modify(org.bson.Document doc, org.bson.Document setDoc, org.bson.Document unsetDoc)Applies the transformation represented by this path, i.e. removes or renames the represented field.- Parameters:
doc- the original document; nevernullsetDoc- the value of$setfield; may benullunsetDoc- the value of$unsetfield; may benull
-
modifyFields
private void modifyFields(org.bson.Document doc, String[] nodes, int beginIndex)Modifies fields in the document by the given path nodes start with the begin index.Note that the path doesn't support modification of fields inside arrays of arrays.
- Parameters:
doc- the document to modify fieldsnodes- the path nodesbeginIndex- the begin index
-
modifyFieldsWithDotNotation
private void modifyFieldsWithDotNotation(org.bson.Document doc)
Modifies fields that use the dot notation, like'a.b'or'a.0.b'.First, we try to modify field that exactly matches the current path. Then, if the field isn't found, we try to find fields that start with the current path or fields that are part of the current path.
- Parameters:
doc- the document to modify fields
-
excludeNumericItems
private String[] excludeNumericItems(String[] items)
Excludes numeric items from the given array.If the array has consecutive numeric items, like
'a.0.0.b', then the numeric items aren't excluded. It is necessary because the modification of fields inside arrays of arrays isn't supported.- Parameters:
items- the array to exclude numeric items- Returns:
- filtered items
-
startsWith
private boolean startsWith(String[] begin, String[] source)
Returnstrueif the source array starts with the specified array.- Parameters:
begin- the array from which the source array beginssource- the source array to check- Returns:
trueif the source array starts with the specified array
-
modifyField
abstract void modifyField(org.bson.Document doc, String field)Modifies the field in the document used for read, insert and full update operations.- Parameters:
doc- the document to modify fieldfield- the modified field
-
modifyFieldWithDotNotation
abstract void modifyFieldWithDotNotation(org.bson.Document doc, String field)Immediately modifies the field that uses the dot notation like'a.b'in the document used for set and unset update operations.- Parameters:
doc- the document to modify fieldfield- the modified field
-
generateNewFieldName
abstract FieldSelector.FieldNameAndValue generateNewFieldName(String[] fieldNodes, Object value)
Generates a new field name for the given value.- Parameters:
fieldNodes- the field nodesvalue- the field value- Returns:
- a new field name for the given value
-
-