use of org.springframework.data.mongodb.core.mapping.Document in project spring-data-mongodb by spring-projects.
the class QueryMapperUnitTests method translates$NeCorrectly.
// DATAMONGO-278
@Test
void translates$NeCorrectly() {
Criteria criteria = where("foo").ne(new ObjectId().toString());
org.bson.Document result = mapper.getMappedObject(criteria.getCriteriaObject(), context.getPersistentEntity(Sample.class));
Object object = result.get("_id");
assertThat(object).isInstanceOf(org.bson.Document.class);
org.bson.Document document = (org.bson.Document) object;
assertThat(document.get("$ne")).isInstanceOf(ObjectId.class);
}
use of org.springframework.data.mongodb.core.mapping.Document in project spring-data-mongodb by spring-projects.
the class GeoJsonTests method shouldConvertPointRepresentationCorrectlyWhenSourceCoordinatesUsesInteger.
// DATAMONGO-1453
@Test
public void shouldConvertPointRepresentationCorrectlyWhenSourceCoordinatesUsesInteger() {
this.template.execute(template.getCollectionName(DocumentWithPropertyUsingGeoJsonType.class), new CollectionCallback<Object>() {
@Override
public Object doInCollection(MongoCollection<org.bson.Document> collection) throws MongoException, DataAccessException {
org.bson.Document pointRepresentation = new org.bson.Document();
pointRepresentation.put("type", "Point");
pointRepresentation.put("coordinates", new BasicDbListBuilder().add(0).add(0).get());
org.bson.Document document = new org.bson.Document();
document.append("_id", "datamongo-1453");
document.append("geoJsonPoint", pointRepresentation);
collection.insertOne(document);
return document;
}
});
assertThat(template.findOne(query(where("id").is("datamongo-1453")), DocumentWithPropertyUsingGeoJsonType.class).geoJsonPoint).isEqualTo(new GeoJsonPoint(0D, 0D));
}
use of org.springframework.data.mongodb.core.mapping.Document in project spring-data-mongodb by spring-projects.
the class MongoPersistentEntityIndexResolver method resolveIndexForEntity.
/**
* Resolve the {@link IndexDefinition}s for a given {@literal root} entity by traversing
* {@link MongoPersistentProperty} scanning for index annotations {@link Indexed}, {@link CompoundIndex} and
* {@link GeospatialIndex}. The given {@literal root} has therefore to be annotated with {@link Document}.
*
* @param root must not be null.
* @return List of {@link IndexDefinitionHolder}. Will never be {@code null}.
* @throws IllegalArgumentException in case of missing {@link Document} annotation marking root entities.
*/
public List<IndexDefinitionHolder> resolveIndexForEntity(MongoPersistentEntity<?> root) {
Assert.notNull(root, "MongoPersistentEntity must not be null!");
Document document = root.findAnnotation(Document.class);
Assert.notNull(document, () -> String.format("Entity %s is not a collection root. Make sure to annotate it with @Document!", root.getName()));
verifyWildcardIndexedProjection(root);
List<IndexDefinitionHolder> indexInformation = new ArrayList<>();
String collection = root.getCollection();
indexInformation.addAll(potentiallyCreateCompoundIndexDefinitions("", collection, root));
indexInformation.addAll(potentiallyCreateWildcardIndexDefinitions("", collection, root));
indexInformation.addAll(potentiallyCreateTextIndexDefinition(root, collection));
root.doWithProperties((PropertyHandler<MongoPersistentProperty>) property -> this.potentiallyAddIndexForProperty(root, property, indexInformation, new CycleGuard()));
indexInformation.addAll(resolveIndexesForDbrefs("", collection, root));
return indexInformation;
}
use of org.springframework.data.mongodb.core.mapping.Document in project spring-data-mongodb by spring-projects.
the class MappingMongoConverterUnitTests method readsPlainDBRefObject.
// DATAMONGO-424
@Test
void readsPlainDBRefObject() {
DBRef dbRef = new DBRef("foo", 2);
org.bson.Document document = new org.bson.Document("ref", dbRef);
DBRefWrapper result = converter.read(DBRefWrapper.class, document);
assertThat(result.ref).isEqualTo(dbRef);
}
use of org.springframework.data.mongodb.core.mapping.Document in project spring-data-mongodb by spring-projects.
the class MappingMongoConverterUnitTests method readsCollectionOfDBRefs.
// DATAMONGO-424
@Test
void readsCollectionOfDBRefs() {
DBRef dbRef = new DBRef("foo", 2);
BasicDBList refs = new BasicDBList();
refs.add(dbRef);
org.bson.Document document = new org.bson.Document("refs", refs);
DBRefWrapper result = converter.read(DBRefWrapper.class, document);
assertThat(result.refs).hasSize(1);
assertThat(result.refs).contains(dbRef);
}
Aggregations