Class MongoDBConverter
- java.lang.Object
-
- org.nuxeo.ecm.core.storage.mongodb.MongoDBConverter
-
public class MongoDBConverter extends Object
Converts between MongoDB types (bson) and DBS types (diff, state, list, serializable).The MongoDB native "_id" can optionally be translated into a custom id in memory (usually "ecm:id"). Otherwise it is stripped from returned results.
- Since:
- 9.1
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
MongoDBConverter.ConditionsAndUpdates
class
MongoDBConverter.UpdateBuilder
Update list builder to prevent several updates of the same field.
-
Field Summary
Fields Modifier and Type Field Description protected static Pattern
HEX_RE
protected String
idKey
The key to use in memory to map the database native "_id".protected Set<String>
idValuesKeys
The keys whose values are ids and are stored as longs.protected Set<String>
trueOrNullBooleanKeys
The keys for booleans whose value is true or null (instead of false).
-
Constructor Summary
Constructors Constructor Description MongoDBConverter()
Constructor for a converter that does not map the MongoDB native "_id".MongoDBConverter(String idKey, Set<String> trueOrNullBooleanKeys, Set<String> idValuesKeys)
Constructor for a converter that also knows to optionally translate the native MongoDB "_id" into a custom id.
-
Method Summary
-
-
-
Field Detail
-
idKey
protected final String idKey
The key to use in memory to map the database native "_id".
-
trueOrNullBooleanKeys
protected final Set<String> trueOrNullBooleanKeys
The keys for booleans whose value is true or null (instead of false).
-
idValuesKeys
protected final Set<String> idValuesKeys
The keys whose values are ids and are stored as longs.
-
HEX_RE
protected static final Pattern HEX_RE
-
-
Constructor Detail
-
MongoDBConverter
public MongoDBConverter()
Constructor for a converter that does not map the MongoDB native "_id".- Since:
- 10.3
-
MongoDBConverter
public MongoDBConverter(String idKey, Set<String> trueOrNullBooleanKeys, Set<String> idValuesKeys)
Constructor for a converter that also knows to optionally translate the native MongoDB "_id" into a custom id.When
idValuesKeys
are provided, the ids are stored as longs.- Parameters:
idKey
- the key to use to map the native "_id" in memory, if notnull
trueOrNullBooleanKeys
- the keys corresponding to boolean values that are only true or null (instead of false)idValuesKeys
- the keys corresponding to values that are ids
-
-
Method Detail
-
diffToBson
public MongoDBConverter.ConditionsAndUpdates diffToBson(State.StateDiff diff)
Constructs a list of MongoDB updates from the givenState.StateDiff
.We need a list because some cases need two operations to avoid conflicts.
-
stateToBson
public org.bson.Document stateToBson(State state)
-
listToBson
public <T> List<Object> listToBson(String key, Collection<T> values)
-
filterIn
public <T> org.bson.conversions.Bson filterIn(String key, Collection<T> values)
-
getFromBson
public Serializable getFromBson(org.bson.Document doc, String bsonKey, String key)
-
bsonToState
public State bsonToState(org.bson.Document doc)
-
bsonToValue
public Serializable bsonToValue(String key, Object value)
-
valueIsId
protected boolean valueIsId(String key)
-
bsonToSerializable
public Serializable bsonToSerializable(String key, Object val)
-
-