Package org.bson.codecs
Interface CollectibleCodec<T>
-
- Type Parameters:
T
- the document type
- All Known Implementing Classes:
BsonDocumentCodec
,DBObjectCodec
,DocumentCodec
public interface CollectibleCodec<T> extends Codec<T>
A Codec that generates complete BSON documents for storage in a MongoDB collection.- Since:
- 3.0
-
-
Method Summary
All Methods Instance Methods Abstract Methods Modifier and Type Method Description boolean
documentHasId(T document)
Returns true if the given document has an _id.T
generateIdIfAbsentFromDocument(T document)
Generates a value for the _id field on the given document, if the document does not have one.BsonValue
getDocumentId(T document)
Gets the _id of the given document if it contains one, otherwise throwsIllegalArgumentException
.-
Methods inherited from interface org.bson.codecs.Encoder
encode, getEncoderClass
-
-
-
-
Method Detail
-
generateIdIfAbsentFromDocument
T generateIdIfAbsentFromDocument(T document)
Generates a value for the _id field on the given document, if the document does not have one.- Parameters:
document
- the document for which to generate a value for the _id.- Returns:
- the document with the _id
-
documentHasId
boolean documentHasId(T document)
Returns true if the given document has an _id.- Parameters:
document
- the document in which to look for an _id- Returns:
- true if the document has an _id
-
getDocumentId
BsonValue getDocumentId(T document)
Gets the _id of the given document if it contains one, otherwise throwsIllegalArgumentException
. To avoid the latter case, calldocumentHasId
first to check.- Parameters:
document
- the document from which to get the _id- Returns:
- the _id of the document
- Throws:
java.lang.IllegalStateException
- if the document does not contain an _id
-
-