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 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
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected String
bsonToId(Object val)
String
bsonToKey(String key)
Serializable
bsonToSerializable(String key, Object val)
Class<?>
bsonToSerializableClass(String key, Class<?> klass)
State
bsonToState(org.bson.Document doc)
Serializable
bsonToValue(String key, Object value)
List<org.bson.Document>
diffToBson(State.StateDiff diff)
Constructs a list of MongoDB updates from the givenState.StateDiff
.org.bson.conversions.Bson
filterEq(String key, Object value)
<T> org.bson.conversions.Bson
filterIn(String key, Collection<T> values)
Serializable
getFromBson(org.bson.Document doc, String bsonKey, String key)
protected Object
idToBson(Object value)
String
keyToBson(String key)
<T> List<Object>
listToBson(String key, Collection<T> values)
void
putToBson(org.bson.Document doc, String key, Object value)
Object
serializableToBson(String key, Object value)
org.bson.Document
stateToBson(State state)
protected boolean
valueIsId(String key)
Object
valueToBson(String key, Object value)
-
-
-
Field Detail
-
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.
-
-
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 List<org.bson.Document> 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.
-
valueToBson
public Object valueToBson(String key, Object value)
-
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)
-
serializableToBson
public Object serializableToBson(String key, Object value)
-
bsonToSerializable
public Serializable bsonToSerializable(String key, Object val)
-
bsonToSerializableClass
public Class<?> bsonToSerializableClass(String key, Class<?> klass)
-
-