Search in sources :

Example 1 with Property

use of dev.morphia.annotations.Property in project morphia by mongodb.

the class PropertyModelBuilder method discoverMappedName.

public PropertyModelBuilder discoverMappedName() {
    MapperOptions options = mapper.getOptions();
    Property property = getAnnotation(Property.class);
    Reference reference = getAnnotation(Reference.class);
    Version version = getAnnotation(Version.class);
    if (hasAnnotation(Id.class)) {
        mappedName("_id");
    } else if (property != null && !property.value().equals(Mapper.IGNORED_FIELDNAME)) {
        mappedName(property.value());
    } else if (reference != null && !reference.value().equals(Mapper.IGNORED_FIELDNAME)) {
        mappedName(reference.value());
    } else if (version != null && !version.value().equals(Mapper.IGNORED_FIELDNAME)) {
        mappedName(version.value());
    } else {
        mappedName(options.getFieldNaming().apply(name()));
    }
    return this;
}
Also used : MapperOptions(dev.morphia.mapping.MapperOptions) Version(dev.morphia.annotations.Version) Reference(dev.morphia.annotations.Reference) Property(dev.morphia.annotations.Property)

Example 2 with Property

use of dev.morphia.annotations.Property 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)

Aggregations

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