Search in sources :

Example 36 with MappedClass

use of org.mongodb.morphia.mapping.MappedClass in project morphia by mongodb.

the class MappedFieldTypeValidatorTest method shouldAllowAListThatDoesNotContainNumbers.

@Test
public void shouldAllowAListThatDoesNotContainNumbers() {
    // given
    MappedClass mappedClass = new MappedClass(EntityWithListsAndArrays.class, new Mapper());
    MappedField mappedField = mappedClass.getMappedField("listOfIntegers");
    // expect
    assertThat(MappedFieldTypeValidator.isIterableOfNumbers(mappedField), is(true));
}
Also used : MappedField(org.mongodb.morphia.mapping.MappedField) Mapper(org.mongodb.morphia.mapping.Mapper) MappedClass(org.mongodb.morphia.mapping.MappedClass) Test(org.junit.Test)

Example 37 with MappedClass

use of org.mongodb.morphia.mapping.MappedClass in project morphia by mongodb.

the class MappedFieldTypeValidatorTest method shouldAllowArraysOfNumbers.

@Test
public void shouldAllowArraysOfNumbers() {
    // given
    MappedClass mappedClass = new MappedClass(EntityWithListsAndArrays.class, new Mapper());
    MappedField mappedField = mappedClass.getMappedField("arrayOfInts");
    // expect
    assertThat(MappedFieldTypeValidator.isArrayOfNumbers(mappedField), is(true));
}
Also used : MappedField(org.mongodb.morphia.mapping.MappedField) Mapper(org.mongodb.morphia.mapping.Mapper) MappedClass(org.mongodb.morphia.mapping.MappedClass) Test(org.junit.Test)

Example 38 with MappedClass

use of org.mongodb.morphia.mapping.MappedClass in project morphia by mongodb.

the class SizeOperationValidatorTest method shouldAllowSizeOperatorForIterableTypesAndIntegerValues.

@Test
public void shouldAllowSizeOperatorForIterableTypesAndIntegerValues() {
    // given
    MappedClass mappedClass = new MappedClass(EntityWithListsAndArrays.class, new Mapper());
    MappedField mappedField = mappedClass.getMappedField("setOfIntegers");
    List<ValidationFailure> validationFailures = new ArrayList<ValidationFailure>();
    // when
    boolean validationApplied = SizeOperationValidator.getInstance().apply(mappedField, SIZE, 3, validationFailures);
    // then
    assertThat(validationApplied, is(true));
    assertThat(validationFailures.size(), is(0));
}
Also used : MappedField(org.mongodb.morphia.mapping.MappedField) Mapper(org.mongodb.morphia.mapping.Mapper) ArrayList(java.util.ArrayList) MappedClass(org.mongodb.morphia.mapping.MappedClass) Test(org.junit.Test)

Example 39 with MappedClass

use of org.mongodb.morphia.mapping.MappedClass in project morphia by mongodb.

the class PathTarget method resolveField.

private MappedField resolveField(final String segment) {
    MappedField mf = context.getMappedField(segment);
    if (mf == null) {
        mf = context.getMappedFieldByJavaField(segment);
    }
    if (mf == null) {
        Iterator<MappedClass> subTypes = mapper.getSubTypes(context).iterator();
        while (mf == null && subTypes.hasNext()) {
            context = subTypes.next();
            mf = resolveField(segment);
        }
    }
    if (mf != null) {
        context = mapper.getMappedClass(mf.getSubClass() != null ? mf.getSubClass() : mf.getConcreteType());
    }
    return mf;
}
Also used : MappedField(org.mongodb.morphia.mapping.MappedField) MappedClass(org.mongodb.morphia.mapping.MappedClass)

Example 40 with MappedClass

use of org.mongodb.morphia.mapping.MappedClass 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

MappedClass (org.mongodb.morphia.mapping.MappedClass)92 Test (org.junit.Test)73 MappedField (org.mongodb.morphia.mapping.MappedField)56 Mapper (org.mongodb.morphia.mapping.Mapper)53 ArrayList (java.util.ArrayList)48 BasicDBObject (com.mongodb.BasicDBObject)18 DBObject (com.mongodb.DBObject)12 BsonDocument (org.bson.BsonDocument)8 Document (org.bson.Document)8 MappingException (org.mongodb.morphia.mapping.MappingException)6 DBCollection (com.mongodb.DBCollection)5 List (java.util.List)5 SimpleEntity (org.mongodb.morphia.entities.SimpleEntity)5 ObjectId (org.bson.types.ObjectId)4 Key (org.mongodb.morphia.Key)4 Index (org.mongodb.morphia.annotations.Index)4 LinkedHashMap (java.util.LinkedHashMap)3 NotSaved (org.mongodb.morphia.annotations.NotSaved)3 UpdateResults (org.mongodb.morphia.query.UpdateResults)3 WriteResult (com.mongodb.WriteResult)2