Search in sources :

Example 1 with Indexes

use of org.mongodb.morphia.annotations.Indexes in project morphia by mongodb.

the class IndexHelper method collectTopLevelIndexes.

private List<Index> collectTopLevelIndexes(final MappedClass mc) {
    List<Index> list = new ArrayList<Index>();
    if (mc != null) {
        final List<Indexes> annotations = mc.getAnnotations(Indexes.class);
        if (annotations != null) {
            for (final Indexes indexes : annotations) {
                for (final Index index : indexes.value()) {
                    Index updated = index;
                    if (index.fields().length == 0) {
                        LOG.warning(format("This index on '%s' is using deprecated configuration options.  Please update to use the " + "fields value on @Index: %s", mc.getClazz().getName(), index.toString()));
                        updated = new IndexBuilder().migrate(index);
                    }
                    List<Field> fields = new ArrayList<Field>();
                    for (Field field : updated.fields()) {
                        fields.add(new FieldBuilder().value(findField(mc, index.options(), asList(field.value().split("\\.")))).type(field.type()).weight(field.weight()));
                    }
                    list.add(replaceFields(updated, fields));
                }
            }
        }
        list.addAll(collectTopLevelIndexes(mc.getSuperClass()));
    }
    return list;
}
Also used : MappedField(org.mongodb.morphia.mapping.MappedField) Field(org.mongodb.morphia.annotations.Field) ArrayList(java.util.ArrayList) Index(org.mongodb.morphia.annotations.Index) Indexes(org.mongodb.morphia.annotations.Indexes)

Aggregations

ArrayList (java.util.ArrayList)1 Field (org.mongodb.morphia.annotations.Field)1 Index (org.mongodb.morphia.annotations.Index)1 Indexes (org.mongodb.morphia.annotations.Indexes)1 MappedField (org.mongodb.morphia.mapping.MappedField)1