private void createCollection(String collectionName) {

    mongoTemplate.createCollection(collectionName);
    IndexDefinition index =
        new CompoundIndexDefinition(new BasicDBObject().append("m_tag", 1)).unique();
    mongoTemplate.indexOps(collectionName).ensureIndex(index);
  }
 @Override
 public void addProductDetail(ProductDetail productDetail) {
   if (!mongoTemplate.collectionExists(ProductDetail.class)) {
     mongoTemplate.createCollection(ProductDetail.class);
   }
   // insert a document
   logger.info("ProductDetailDAOMongo add productDetail");
   mongoTemplate.insert(productDetail, COLLECTION_NAME);
 }
 @Override
 public void saveUser(UserAccount user) {
   if (mongoTemplate.collectionExists("userAccount")) {
     mongoTemplate.save(user);
   } else {
     mongoTemplate.createCollection("userAccount");
     mongoTemplate.save(user);
   }
 }
Beispiel #4
0
  private void dropCreateMongoSchema() {
    for (Class cls : collections) {
      mongoTemplate.dropCollection(cls);
      mongoTemplate.createCollection(cls);
    }

    // perform any index operations here

    // perform imports
    importMongoSchema();
  }
  @Override
  public RfidDao getRfidByNumber(String number) {

    if (!mongoTemplate.collectionExists(RfidDao.class)) {
      mongoTemplate.createCollection(RfidDao.class);
    }
    // System.out.println(mongoTemplate.findOne(new
    // Query(where("rfid_number").is(number)),RfidDao.class));
    return mongoTemplate.findOne(
        new Query(where("rfid_number").is(number).and("status").is("notavailable")), RfidDao.class);
  }
 // Creating an user in the repository.
 public void createUsuario(UsuarioSiar usuarioSiar) {
   if (!siarmongoTemplate.collectionExists(UsuarioSiar.class)) {
     siarmongoTemplate.createCollection(UsuarioSiar.class);
   }
   siarmongoTemplate.insert(usuarioSiar, "usuarioSiarTable");
 }
 /** * Create a {@link Person} collection if the collection does not already exists */
 public void createInventoryCollection() {
   if (!mongoTemplate.collectionExists(Inventory.class)) {
     mongoTemplate.createCollection(Inventory.class);
   }
 }
 public void createCollection(String name) {
   if (!mongoTemplate.collectionExists(Task.class)) {
     mongoTemplate.createCollection(name);
   }
 }
 /**
  * Create a {<span class="referer">@link</span> Task} collection if the collection does not
  * already exists
  */
 public void createCollection() {
   if (!mongoTemplate.collectionExists(Task.class)) {
     mongoTemplate.createCollection(Task.class);
   }
 }
 @Before
 public void testSetup() {
   mongoTemplate.createCollection(User.class);
 }