use of org.mongodb.morphia.mapping.MappedClass in project morphia by mongodb.
the class IndexHelperTest method weightsOnNonTextIndex.
@Test(expected = MappingException.class)
public void weightsOnNonTextIndex() {
MongoCollection<Document> indexes = getDatabase().getCollection("indexes");
MappedClass mappedClass = getMorphia().getMapper().getMappedClass(IndexedClass.class);
IndexBuilder index = new IndexBuilder().fields(new FieldBuilder().value("name").weight(10));
indexHelper.createIndex(indexes, mappedClass, index, false);
}
use of org.mongodb.morphia.mapping.MappedClass in project morphia by mongodb.
the class ContainsEmbeddedWithId method checkRecursivelyHasNoIdAnnotationPresent.
private void checkRecursivelyHasNoIdAnnotationPresent(final Set<Class<?>> classesToInspect, final HashSet<Class<?>> alreadyInspectedClasses, final MappedClass mc, final Set<ConstraintViolation> ve) {
for (final Class<?> clazz : classesToInspect) {
if (alreadyInspectedClasses.contains(clazz)) {
continue;
}
if (hasTypeFieldAnnotation(clazz, Id.class)) {
ve.add(new ConstraintViolation(Level.FATAL, mc, getClass(), "You cannot use @Id on any field of an Embedded/Property object"));
}
alreadyInspectedClasses.add(clazz);
final Set<Class<?>> extraClassesToInspect = new HashSet<Class<?>>();
for (final Field field : ReflectionUtils.getDeclaredAndInheritedFields(clazz, true)) {
if (isFieldToInspect(field)) {
extraClassesToInspect.add(field.getType());
}
}
checkRecursivelyHasNoIdAnnotationPresent(extraClassesToInspect, alreadyInspectedClasses, mc, ve);
}
}
use of org.mongodb.morphia.mapping.MappedClass in project morphia by mongodb.
the class IndexHelperTest method calculateKeys.
@Test
public void calculateKeys() {
MappedClass mappedClass = getMorphia().getMapper().getMappedClass(IndexedClass.class);
BsonDocument keys = indexHelper.calculateKeys(mappedClass, new IndexBuilder().fields(new FieldBuilder().value("text").type(IndexType.TEXT).weight(1), new FieldBuilder().value("nest").type(IndexType.DESC)));
assertEquals(new BsonDocument().append("text", new BsonString("text")).append("nest", new BsonInt32(-1)), keys);
}
use of org.mongodb.morphia.mapping.MappedClass in project morphia by mongodb.
the class IndexHelperTest method wildcardTextIndex.
@Test
public void wildcardTextIndex() {
MongoCollection<Document> indexes = getDatabase().getCollection("indexes");
MappedClass mappedClass = getMorphia().getMapper().getMappedClass(IndexedClass.class);
IndexBuilder index = new IndexBuilder().fields(new FieldBuilder().value("$**").type(IndexType.TEXT));
indexHelper.createIndex(indexes, mappedClass, index, false);
List<DBObject> wildcard = getDb().getCollection("indexes").getIndexInfo();
boolean found = false;
for (DBObject dbObject : wildcard) {
found |= dbObject.get("name").equals("$**_text");
}
assertTrue("Should have found the wildcard index", found);
}
use of org.mongodb.morphia.mapping.MappedClass in project morphia by mongodb.
the class IndexHelperTest method textPartialFilters.
@Test
public void textPartialFilters() {
MongoCollection<Document> collection = getDatabase().getCollection("indexes");
MappedClass mappedClass = getMorphia().getMapper().getMappedClass(IndexedClass.class);
Text text = new TextBuilder().value(4).options(new IndexOptionsBuilder().partialFilter("{ name : { $gt : 13 } }"));
indexHelper.createIndex(collection, mappedClass, indexHelper.convert(text, "text"), false);
findPartialIndex(BasicDBObject.parse(text.options().partialFilter()));
}
Aggregations