Search in sources :

Example 1 with Indexed

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;
}
Also used : MappedField(org.mongodb.morphia.mapping.MappedField) ArrayList(java.util.ArrayList) Index(org.mongodb.morphia.annotations.Index) Text(org.mongodb.morphia.annotations.Text) Indexed(org.mongodb.morphia.annotations.Indexed)

Example 2 with Indexed

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]);
}
Also used : Index(org.mongodb.morphia.annotations.Index) Indexed(org.mongodb.morphia.annotations.Indexed) Test(org.junit.Test)

Example 3 with Indexed

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]);
}
Also used : Index(org.mongodb.morphia.annotations.Index) Indexed(org.mongodb.morphia.annotations.Indexed) Test(org.junit.Test)

Example 4 with Indexed

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()));
}
Also used : MappedClass(org.mongodb.morphia.mapping.MappedClass) Document(org.bson.Document) BsonDocument(org.bson.BsonDocument) Indexed(org.mongodb.morphia.annotations.Indexed) Test(org.junit.Test)

Aggregations

Indexed (org.mongodb.morphia.annotations.Indexed)4 Test (org.junit.Test)3 Index (org.mongodb.morphia.annotations.Index)3 ArrayList (java.util.ArrayList)1 BsonDocument (org.bson.BsonDocument)1 Document (org.bson.Document)1 Text (org.mongodb.morphia.annotations.Text)1 MappedClass (org.mongodb.morphia.mapping.MappedClass)1 MappedField (org.mongodb.morphia.mapping.MappedField)1