Search in sources :

Example 31 with EntityModel

use of dev.morphia.mapping.codec.pojo.EntityModel in project morphia by MorphiaOrg.

the class IndexHelperTest method weightsOnNonTextIndex.

@Test(expectedExceptions = MappingException.class)
public void weightsOnNonTextIndex() {
    MongoCollection<Document> indexes = getDatabase().getCollection("indexes");
    EntityModel model = getMapper().getEntityModel(IndexedClass.class);
    Index index = indexBuilder().fields(fieldBuilder().value("name").weight(10).build()).build();
    getIndexHelper().createIndex(indexes, model, index);
}
Also used : EntityModel(dev.morphia.mapping.codec.pojo.EntityModel) Index(dev.morphia.annotations.Index) Document(org.bson.Document) Test(org.testng.annotations.Test)

Example 32 with EntityModel

use of dev.morphia.mapping.codec.pojo.EntityModel in project morphia by MorphiaOrg.

the class IndexHelperTest method index.

@Test
public void index() {
    MongoCollection<Document> collection = getDatabase().getCollection("indexes");
    EntityModel model = getMapper().getEntityModel(IndexedClass.class);
    IndexOptions options = indexOptionsBuilder().name("index_name").background(true).collation(collation().build()).disableValidation(true).language("en").languageOverride("de").sparse(true).unique(true).build();
    Index index = indexBuilder().fields(fieldBuilder().value("indexName").build(), fieldBuilder().value("text").type(IndexType.DESC).build()).options(options).build();
    getIndexHelper().createIndex(collection, model, index);
    List<Document> indexInfo = getIndexInfo(IndexedClass.class);
    for (Document document : indexInfo) {
        if (document.get("name").equals("indexName")) {
            checkIndex(document);
            assertEquals(document.get("default_language"), "en");
            assertEquals(document.get("language_override"), "de");
            assertEquals(document.get("collation"), new Document().append("locale", "en").append("caseLevel", true).append("caseFirst", "upper").append("strength", 5).append("numericOrdering", true).append("alternate", "shifted").append("maxVariable", "space").append("backwards", true).append("normalization", true).append("version", "57.1"));
        }
    }
}
Also used : IndexOptions(dev.morphia.annotations.IndexOptions) EntityModel(dev.morphia.mapping.codec.pojo.EntityModel) Index(dev.morphia.annotations.Index) Document(org.bson.Document) Test(org.testng.annotations.Test)

Example 33 with EntityModel

use of dev.morphia.mapping.codec.pojo.EntityModel in project morphia by MorphiaOrg.

the class IndexHelperTest method indexPartialFilters.

@Test
public void indexPartialFilters() {
    MongoCollection<Document> collection = getDatabase().getCollection("indexes");
    EntityModel model = getMapper().getEntityModel(IndexedClass.class);
    Index index = indexBuilder().fields(fieldBuilder().value("text").build()).options(indexOptionsBuilder().partialFilter("{ name : { $gt : 13 } }").build()).build();
    getIndexHelper().createIndex(collection, model, index);
    findPartialIndex(Document.parse(index.options().partialFilter()));
}
Also used : EntityModel(dev.morphia.mapping.codec.pojo.EntityModel) Index(dev.morphia.annotations.Index) Document(org.bson.Document) Test(org.testng.annotations.Test)

Example 34 with EntityModel

use of dev.morphia.mapping.codec.pojo.EntityModel in project morphia by MorphiaOrg.

the class TestIndexes method testClassIndexInherit.

@Test
public void testClassIndexInherit() {
    getMapper().map(Shape.class, Circle.class);
    final EntityModel entityModel = getMapper().getEntityModel(Circle.class);
    assertNotNull(entityModel);
    assertNotNull(entityModel.getAnnotation(Indexes.class));
    getDs().ensureIndexes();
    assertEquals(getIndexInfo(Circle.class).size(), 4);
}
Also used : EntityModel(dev.morphia.mapping.codec.pojo.EntityModel) Indexes(dev.morphia.annotations.Indexes) Test(org.testng.annotations.Test)

Example 35 with EntityModel

use of dev.morphia.mapping.codec.pojo.EntityModel in project morphia by MorphiaOrg.

the class PathTargetTest method maps.

@Test
public void maps() {
    getMapper().map(Student.class);
    Mapper mapper = getMapper();
    EntityModel entityModel = mapper.getEntityModel(Student.class);
    PathTarget pathTarget = new PathTarget(mapper, entityModel, "grades.$.data.name");
    Assert.assertEquals(pathTarget.translatedPath(), "grades.$.d.name");
    Assert.assertEquals(mapper.getEntityModel(Grade.class).getProperty("data"), pathTarget.getTarget());
    pathTarget = new PathTarget(mapper, entityModel, "grades.$.d.name");
    Assert.assertEquals(pathTarget.translatedPath(), "grades.$.d.name");
    Assert.assertEquals(mapper.getEntityModel(Grade.class).getProperty("d"), pathTarget.getTarget());
}
Also used : Mapper(dev.morphia.mapping.Mapper) PathTarget(dev.morphia.internal.PathTarget) EntityModel(dev.morphia.mapping.codec.pojo.EntityModel) Test(org.testng.annotations.Test)

Aggregations

EntityModel (dev.morphia.mapping.codec.pojo.EntityModel)94 Test (org.testng.annotations.Test)56 Document (org.bson.Document)36 PropertyModel (dev.morphia.mapping.codec.pojo.PropertyModel)22 ArrayList (java.util.ArrayList)16 Datastore (dev.morphia.Datastore)14 Entity (dev.morphia.annotations.Entity)14 PathTarget (dev.morphia.internal.PathTarget)12 Mapper (dev.morphia.mapping.Mapper)12 Nullable (com.mongodb.lang.Nullable)10 Index (dev.morphia.annotations.Index)10 Morphia.createDatastore (dev.morphia.Morphia.createDatastore)8 VersionedChildEntity (dev.morphia.test.models.versioned.VersionedChildEntity)8 List (java.util.List)8 ExternalEntity (dev.morphia.annotations.experimental.ExternalEntity)6 WriteConcern (com.mongodb.WriteConcern)4 Key (dev.morphia.Key)4 IndexOptions (dev.morphia.annotations.IndexOptions)4 MappingException (dev.morphia.mapping.MappingException)4 EntityModelBuilder (dev.morphia.mapping.codec.pojo.EntityModelBuilder)4