use of org.mongodb.morphia.annotations.Indexed in project morphia by mongodb.
the class IndexHelper method collectFieldIndexes.
@SuppressWarnings("deprecation")
private List<Index> collectFieldIndexes(final MappedClass mc) {
List<Index> list = new ArrayList<Index>();
for (final MappedField mf : mc.getPersistenceFields()) {
if (mf.hasAnnotation(Indexed.class)) {
final Indexed indexed = mf.getAnnotation(Indexed.class);
list.add(convert(indexed, mf.getNameToStore()));
} else if (mf.hasAnnotation(Text.class)) {
final Text text = mf.getAnnotation(Text.class);
list.add(convert(text, mf.getNameToStore()));
}
}
return list;
}
use of org.mongodb.morphia.annotations.Indexed in project morphia by mongodb.
the class IndexHelperTest method oldIndexedForm.
@Test
@SuppressWarnings("deprecation")
public void oldIndexedForm() {
Indexed indexed = new IndexedBuilder().name("index_name").background(true).dropDups(true).expireAfterSeconds(42).sparse(true).unique(true).value(IndexDirection.DESC);
assertEquals(indexed.options().name(), "");
Index converted = indexHelper.convert(indexed, "oldstyle");
assertEquals(converted.options().name(), "index_name");
assertTrue(converted.options().background());
assertTrue(converted.options().dropDups());
assertTrue(converted.options().sparse());
assertTrue(converted.options().unique());
assertEquals(new FieldBuilder().value("oldstyle").type(IndexType.DESC), converted.fields()[0]);
}
use of org.mongodb.morphia.annotations.Indexed in project morphia by mongodb.
the class IndexHelperTest method normalizeIndexed.
@Test
@SuppressWarnings("deprecation")
public void normalizeIndexed() {
Indexed indexed = new IndexedBuilder().value(IndexDirection.DESC).options(new IndexOptionsBuilder().name("index_name").background(true).dropDups(true).expireAfterSeconds(42).sparse(true).unique(true));
Index converted = indexHelper.convert(indexed, "oldstyle");
assertEquals(converted.options().name(), "index_name");
assertTrue(converted.options().background());
assertTrue(converted.options().dropDups());
assertTrue(converted.options().sparse());
assertTrue(converted.options().unique());
assertEquals(new FieldBuilder().value("oldstyle").type(IndexType.DESC), converted.fields()[0]);
}
use of org.mongodb.morphia.annotations.Indexed in project morphia by mongodb.
the class IndexHelperTest method indexedPartialFilters.
@Test
public void indexedPartialFilters() {
MongoCollection<Document> collection = getDatabase().getCollection("indexes");
MappedClass mappedClass = getMorphia().getMapper().getMappedClass(IndexedClass.class);
Indexed indexed = new IndexedBuilder().options(new IndexOptionsBuilder().partialFilter("{ name : { $gt : 13 } }"));
indexHelper.createIndex(collection, mappedClass, indexHelper.convert(indexed, "text"), false);
findPartialIndex(BasicDBObject.parse(indexed.options().partialFilter()));
}
Aggregations