@groovy.transform.CompileStatic class EnumType extends AbstractMappingAwareCustomTypeMarshaller<java.lang.Object, org.bson.Document, org.bson.Document>
A custom type for persisting Enum which have an id field in domain classes. For example: To save identity instead of string in database for field type.
class User { UserType type String name } enum UserType { A(1), B(2) final int id UserType(int id) { this.id = id } }
Constructor and description |
---|
EnumType
() |
Type Params | Return Type | Name and description |
---|---|---|
|
private static java.lang.Object |
enumValue(PersistentProperty property, java.lang.Object value, java.lang.Class enumType) |
|
private static java.lang.Class |
getCollectionType(PersistentProperty property) Get type of collection by looking at hasMany static field in
the domain class.
|
|
private static java.lang.Object |
getEnumValueForOrdinal(java.lang.Number value, java.lang.Class type) |
|
protected static java.lang.Object |
getId(java.lang.Enum value) |
|
private static boolean |
isEnumTypeCollection(PersistentProperty property) |
|
private static boolean |
isOrdinalTypeEnum(PersistentProperty property) |
|
private void |
putValueToProperPlace(PersistentProperty property, java.lang.String queryKey, PropertyCriterion criterion, org.bson.Document nativeQuery) For custom user types, GORM return an empty map where our custom value needs to be inserted. |
|
protected void |
queryInternal(PersistentProperty property, java.lang.String key, PropertyCriterion criterion, org.bson.Document nativeQuery) |
|
protected java.lang.Object |
readInternal(PersistentProperty property, java.lang.String key, org.bson.Document nativeSource) |
|
boolean |
supports(MappingContext context) |
|
boolean |
supports(Datastore datastore) |
|
protected java.lang.Object |
writeInternal(PersistentProperty property, java.lang.String key, java.lang.Object value, org.bson.Document nativeTarget) |
Get type of collection by looking at hasMany
static field in
the domain class.
@Example: Will return String class for list of String mapped by hasMany.
For custom user types, GORM return an empty map where our custom value needs to be inserted. For example: If our code is something like this:
User.withCriteria {
or {
eq("name", "admin")
eq("status", UserStatus.ACTIVE)
}
eq("foo", "bar")
}
Then the query we receive will be like:
[$and: [[$or: [["name": "admin"], [:]]], ["foo": "bar"]]
Now we have to place value of status to the blank field.
This method searches that empty place and put the value to the right place.