Example usage for org.springframework.data.mongodb.core.mapping DetectedCollectionWithIndex DetectedCollectionWithIndex

List of usage examples for org.springframework.data.mongodb.core.mapping DetectedCollectionWithIndex DetectedCollectionWithIndex

Introduction

In this page you can find the example usage for org.springframework.data.mongodb.core.mapping DetectedCollectionWithIndex DetectedCollectionWithIndex.

Prototype

public DetectedCollectionWithIndex(String name) 

Source Link

Usage

From source file:org.springframework.data.mongodb.core.mapping.MappingTests.java

@Test
public void testIndexesCreatedInRightCollection() {
    CustomCollectionWithIndex ccwi = new CustomCollectionWithIndex("test");
    template.insert(ccwi);/* w w  w. j  av a  2 s  .  c  o m*/

    assertTrue(template.execute("foobar", new CollectionCallback<Boolean>() {
        public Boolean doInCollection(DBCollection collection) throws MongoException, DataAccessException {
            List<DBObject> indexes = collection.getIndexInfo();
            for (DBObject dbo : indexes) {
                if (dbo.get("name") != null && dbo.get("name") instanceof String
                        && ((String) dbo.get("name")).startsWith("name")) {
                    return true;
                }
            }
            return false;
        }
    }));

    DetectedCollectionWithIndex dcwi = new DetectedCollectionWithIndex("test");
    template.insert(dcwi);

    assertTrue(
            template.execute(MongoCollectionUtils.getPreferredCollectionName(DetectedCollectionWithIndex.class),
                    new CollectionCallback<Boolean>() {
                        public Boolean doInCollection(DBCollection collection)
                                throws MongoException, DataAccessException {
                            List<DBObject> indexes = collection.getIndexInfo();
                            for (DBObject dbo : indexes) {
                                if (dbo.get("name") != null && dbo.get("name") instanceof String
                                        && ((String) dbo.get("name")).startsWith("name")) {
                                    return true;
                                }
                            }
                            return false;
                        }
                    }));
}