Search in sources :

Example 1 with LifecycleEncoder

use of dev.morphia.mapping.codec.pojo.LifecycleEncoder in project morphia by mongodb.

the class MorphiaCodecProvider method get.

@Nullable
@Override
@SuppressWarnings({ "unchecked", "rawtypes" })
public <T> Codec<T> get(Class<T> type, CodecRegistry registry) {
    MorphiaCodec<T> codec = (MorphiaCodec<T>) codecs.get(type);
    if (codec == null && (mapper.isMapped(type) || mapper.isMappable(type))) {
        EntityModel model = mapper.getEntityModel(type);
        codec = new MorphiaCodec<>(datastore, model, propertyCodecProviders, mapper.getDiscriminatorLookup(), registry);
        if (model.hasLifecycle(PostPersist.class) || model.hasLifecycle(PrePersist.class) || mapper.hasInterceptors()) {
            codec.setEncoder(new LifecycleEncoder(codec));
        }
        if (model.hasLifecycle(PreLoad.class) || model.hasLifecycle(PostLoad.class) || mapper.hasInterceptors()) {
            codec.setDecoder(new LifecycleDecoder(codec));
        }
        codecs.put(type, codec);
    }
    return codec;
}
Also used : LifecycleDecoder(dev.morphia.mapping.codec.pojo.LifecycleDecoder) EntityModel(dev.morphia.mapping.codec.pojo.EntityModel) MorphiaCodec(dev.morphia.mapping.codec.pojo.MorphiaCodec) LifecycleEncoder(dev.morphia.mapping.codec.pojo.LifecycleEncoder) Nullable(com.mongodb.lang.Nullable)

Aggregations

Nullable (com.mongodb.lang.Nullable)1 EntityModel (dev.morphia.mapping.codec.pojo.EntityModel)1 LifecycleDecoder (dev.morphia.mapping.codec.pojo.LifecycleDecoder)1 LifecycleEncoder (dev.morphia.mapping.codec.pojo.LifecycleEncoder)1 MorphiaCodec (dev.morphia.mapping.codec.pojo.MorphiaCodec)1