use of org.mongodb.morphia.mapping.MappedClass in project morphia by mongodb.
the class IndexHelper method collectNestedIndexes.
private List<Index> collectNestedIndexes(final MappedClass mc, final List<MappedClass> parentMCs) {
List<Index> list = new ArrayList<Index>();
for (final MappedField mf : mc.getPersistenceFields()) {
if (!mf.isTypeMongoCompatible() && !mf.hasAnnotation(Reference.class) && !mf.hasAnnotation(Serialized.class) && !mf.hasAnnotation(NotSaved.class) && !mf.isTransient()) {
final List<MappedClass> parents = new ArrayList<MappedClass>(parentMCs);
parents.add(mc);
List<MappedClass> classes = new ArrayList<MappedClass>();
MappedClass mappedClass = mapper.getMappedClass(mf.isSingleValue() ? mf.getType() : mf.getSubClass());
classes.add(mappedClass);
classes.addAll(mapper.getSubTypes(mappedClass));
for (MappedClass aClass : classes) {
for (Index index : collectIndexes(aClass, parents)) {
List<Field> fields = new ArrayList<Field>();
for (Field field : index.fields()) {
fields.add(new FieldBuilder().value(field.value().equals("$**") ? field.value() : mf.getNameToStore() + "." + field.value()).type(field.type()).weight(field.weight()));
}
list.add(new IndexBuilder(index).fields(fields));
}
}
}
}
return list;
}
use of org.mongodb.morphia.mapping.MappedClass in project morphia by mongodb.
the class TestIndexInheritance method testClassIndexInherit.
@Test
public void testClassIndexInherit() throws Exception {
getMorphia().map(Circle.class).map(Shape.class);
final MappedClass mc = getMorphia().getMapper().getMappedClass(Circle.class);
assertNotNull(mc);
assertEquals(2, mc.getAnnotations(Indexes.class).size());
getDs().ensureIndexes();
final DBCollection coll = getDs().getCollection(Circle.class);
assertEquals(4, coll.getIndexInfo().size());
}
use of org.mongodb.morphia.mapping.MappedClass in project morphia by mongodb.
the class TestIndexed method testMultipleIndexedFields.
@Test
@SuppressWarnings("deprecation")
public void testMultipleIndexedFields() {
final MappedClass mc = getMorphia().getMapper().getMappedClass(Ad.class);
getMorphia().map(Ad.class);
assertThat(getDb().getCollection(mc.getCollectionName()).getIndexInfo(), doesNotHaveIndexNamed("lastMod_1_active_-1"));
getDs().ensureIndex(Ad.class, "lastMod, -active");
assertThat(getDb().getCollection(mc.getCollectionName()).getIndexInfo(), hasIndexNamed("lastMod_1_active_-1"));
}
use of org.mongodb.morphia.mapping.MappedClass in project morphia by mongodb.
the class TestIndexed method testIndexes.
@Test
public void testIndexes() {
final MappedClass mc = getMorphia().getMapper().addMappedClass(Ad2.class);
assertThat(getDb().getCollection(mc.getCollectionName()).getIndexInfo(), doesNotHaveIndexNamed("active_1_lastMod_-1"));
getDs().ensureIndexes(Ad2.class);
assertThat(getDb().getCollection(mc.getCollectionName()).getIndexInfo(), hasIndexNamed("active_1_lastMod_-1"));
}
use of org.mongodb.morphia.mapping.MappedClass in project morphia by mongodb.
the class TestIndexed method testEmbeddedIndex.
@Test
public void testEmbeddedIndex() {
final MappedClass mc = getMorphia().getMapper().addMappedClass(ContainsIndexedEmbed.class);
assertThat(getDb().getCollection(mc.getCollectionName()).getIndexInfo(), doesNotHaveIndexNamed("e.name_-1"));
getDs().ensureIndexes(ContainsIndexedEmbed.class);
assertThat(getDb().getCollection(mc.getCollectionName()).getIndexInfo(), hasIndexNamed("e.name_-1"));
}
Aggregations