/basic/mongodb/src/main/java/org/springframework/integration/samples/mongodb/util/DemoUtils.java

https://gitlab.com/sarabjeet437114/spring-integration-samples · Java · 40 lines · 17 code · 4 blank · 19 comment · 1 complexity · 8675115cd831cfbdf7566fd698991952 MD5 · raw file

  1. /*
  2. * Copyright 2002-2012 the original author or authors.
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. */
  16. package org.springframework.integration.samples.mongodb.util;
  17. import com.mongodb.MongoClient;
  18. import org.springframework.data.mongodb.MongoDbFactory;
  19. import org.springframework.data.mongodb.core.MongoTemplate;
  20. import org.springframework.data.mongodb.core.SimpleMongoDbFactory;
  21. /**
  22. *
  23. * @author Oleg Zhurakousky
  24. */
  25. public class DemoUtils {
  26. public static MongoDbFactory prepareMongoFactory(String... additionalCollectionToDrop) throws Exception{
  27. MongoDbFactory mongoDbFactory = new SimpleMongoDbFactory(new MongoClient(), "test");
  28. MongoTemplate template = new MongoTemplate(mongoDbFactory);
  29. template.dropCollection("messages");
  30. template.dropCollection("data");
  31. for (String additionalCollection : additionalCollectionToDrop) {
  32. template.dropCollection(additionalCollection);
  33. }
  34. return mongoDbFactory;
  35. }
  36. }