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 |
coerceIdToDeclaredType(java.lang.Object value, org.grails.datastore.mapping.model.PersistentEntity entity)Inverse of coerceIdToStoredType: convert a value just read from BSON back to the entity's declared identifier type, so that association properties hold the type the domain class declares ( String) regardless of how _id is stored on disk
(ObjectId). |
|
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) |
Inverse of coerceIdToStoredType: convert a value just read from BSON back to
the entity's declared identifier type, so that association properties hold the type the
domain class declares (String) regardless of how _id is stored on disk
(ObjectId).
Returns the original value when it is null, already an instance of
the declared type, the entity declares no identity, or the converter throws.
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()).