Search in sources :

Example 1 with PropertyModelBuilder

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

the class ConfigureProperties method processProperties.

@SuppressWarnings("rawtypes")
void processProperties(EntityModelBuilder modelBuilder, MapperOptions options) {
    Iterator<PropertyModelBuilder> iterator = modelBuilder.propertyModels().iterator();
    while (iterator.hasNext()) {
        final PropertyModelBuilder builder = iterator.next();
        final int modifiers = builder.modifiers();
        if (isStatic(modifiers) || isTransient(builder)) {
            iterator.remove();
        } else {
            Property property = builder.getAnnotation(Property.class);
            if (property != null && !property.concreteClass().equals(Object.class)) {
                TypeData typeData = builder.typeData().withType(property.concreteClass());
                builder.typeData(typeData);
            }
            AlsoLoad alsoLoad = builder.getAnnotation(AlsoLoad.class);
            if (alsoLoad != null) {
                for (String name : alsoLoad.value()) {
                    builder.alternateName(name);
                }
            }
            if (builder.getAnnotation(Id.class) != null) {
                modelBuilder.idPropertyName(builder.name());
            }
            if (builder.getAnnotation(Version.class) != null) {
                modelBuilder.versionPropertyName(builder.name());
            }
            buildProperty(options, builder);
        }
    }
}
Also used : PropertyModelBuilder(dev.morphia.mapping.codec.pojo.PropertyModelBuilder) Version(dev.morphia.annotations.Version) AlsoLoad(dev.morphia.annotations.AlsoLoad) TypeData(dev.morphia.mapping.codec.pojo.TypeData) Id(dev.morphia.annotations.Id) Property(dev.morphia.annotations.Property)

Example 2 with PropertyModelBuilder

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

the class ConfigureProperties method apply.

@Override
public void apply(Mapper mapper, EntityModelBuilder modelBuilder) {
    MapperOptions options = mapper.getOptions();
    processProperties(modelBuilder, options);
    if (modelBuilder.idPropertyName() == null) {
        IdField idProperty = modelBuilder.getAnnotation(IdField.class);
        if (idProperty != null) {
            modelBuilder.idPropertyName(idProperty.value());
            PropertyModelBuilder propertyModelBuilder = modelBuilder.propertyModelByName(idProperty.value());
            propertyModelBuilder.mappedName("_id");
        }
    }
}
Also used : MapperOptions(dev.morphia.mapping.MapperOptions) PropertyModelBuilder(dev.morphia.mapping.codec.pojo.PropertyModelBuilder) IdField(dev.morphia.annotations.experimental.IdField)

Aggregations

PropertyModelBuilder (dev.morphia.mapping.codec.pojo.PropertyModelBuilder)2 AlsoLoad (dev.morphia.annotations.AlsoLoad)1 Id (dev.morphia.annotations.Id)1 Property (dev.morphia.annotations.Property)1 Version (dev.morphia.annotations.Version)1 IdField (dev.morphia.annotations.experimental.IdField)1 MapperOptions (dev.morphia.mapping.MapperOptions)1 TypeData (dev.morphia.mapping.codec.pojo.TypeData)1