public final class MongoIdCoercion extends java.lang.Object
Centralizes coercion of an identifier value to the storedAs type declared
on a org.grails.datastore.mapping.model.PersistentEntity's id mapping.
Used at every boundary where in-memory ids cross into BSON: point lookups
(MongoCodecEntityPersister#retrieveEntity), batch lookups
(MongoCodecEntityPersister#retrieveAllEntities), update/delete filters
(MongoCodecSession), and query handlers (MongoQuery's
IdEquals and In). Keeping the rules in one place prevents the
four call sites from diverging — the null-return fallback for converter
rejection (e.g. non-hex String → ObjectId) is the kind of subtlety that breaks
silently when duplicated.
| Type Params | Return Type | Name and description |
|---|---|---|
|
public static java.lang.Object |
coerceIdToStoredType(java.lang.Object key, org.grails.datastore.mapping.model.PersistentEntity entity)Coerce key to the entity's storedAs type so query/update/delete
filters target BSON values that match what the encoder actually wrote on disk. |
|
public static java.lang.Class<?> |
resolveStoredAs(org.grails.datastore.mapping.model.PersistentEntity entity)Read the storedAs class from the entity's id mapping, or null
if the mapping doesn't declare one (or the mapping implementation predates
org.grails.datastore.mapping.model.IdentityMapping#getStoredAs()). |
| Methods inherited from class | Name |
|---|---|
class java.lang.Object |
java.lang.Object#equals(java.lang.Object), java.lang.Object#getClass(), java.lang.Object#hashCode(), java.lang.Object#notify(), java.lang.Object#notifyAll(), java.lang.Object#toString(), java.lang.Object#wait(), java.lang.Object#wait(long), java.lang.Object#wait(long, int) |
Coerce key to the entity's storedAs type so query/update/delete
filters target BSON values that match what the encoder actually wrote on disk.
Returns the original key when:
key is null, or already an instance of the storedAs type,storedAs,null (e.g. a non-hex
natural-key String against storedAs: ObjectId) — kept symmetric with
IdentityEncoder's non-hex fallback so filters target the BSON String
the encoder wrote rather than {_id: null}, Read the storedAs class from the entity's id mapping, or null
if the mapping doesn't declare one (or the mapping implementation predates
org.grails.datastore.mapping.model.IdentityMapping#getStoredAs()).