List of usage examples for org.springframework.data.mongodb MongoCollectionUtils getPreferredCollectionName
public static String getPreferredCollectionName(Class<?> entityClass)
From source file:com.avanza.ymer.MirroredObjectDefinition.java
String collectionName() { return Optional.ofNullable(this.collectionName) .orElseGet(() -> MongoCollectionUtils.getPreferredCollectionName(mirroredType)); }
From source file:com.avanza.ymer.MirroredObjectTest.java
@Test public void collectionName() throws Exception { DocumentPatch[] patches = { new FakePatch(2), new FakePatch(3) }; MirroredObject<MirroredType> document = MirroredObjectDefinition.create(MirroredType.class) .documentPatches(patches).buildMirroredDocument(); assertEquals(MongoCollectionUtils.getPreferredCollectionName(document.getMirroredType()), document.getCollectionName()); }
From source file:org.springframework.data.mongodb.core.mapping.MappingTests.java
@Test @SuppressWarnings({ "unchecked", "rawtypes" }) public void testUniqueIndex() { Address addr = new Address(); addr.setLines(new String[] { "1234 W. 1st Street", "Apt. 12" }); addr.setCity("Anytown"); addr.setPostalCode(12345);//from w w w . jav a2 s . c o m addr.setCountry("USA"); Person p1 = new Person(1234567890, "John", "Doe", 37, addr); Person p2 = new Person(1234567890, "Jane", "Doe", 38, addr); List<Person> persons = new ArrayList<Person>(); persons.add(p1); persons.add(p2); template.insert(persons, MongoCollectionUtils.getPreferredCollectionName(Person.class)); List<Person> result = template.find(new Query(Criteria.where("ssn").is(1234567890)), Person.class); assertThat(result.size(), is(1)); }
From source file:org.springframework.data.mongodb.core.mapping.MappingTests.java
@Test public void testIndexesCreatedInRightCollection() { CustomCollectionWithIndex ccwi = new CustomCollectionWithIndex("test"); template.insert(ccwi);/*from ww w . ja v a 2 s.co 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; } })); }