Example usage for org.springframework.data.mongodb.core.query Update set

List of usage examples for org.springframework.data.mongodb.core.query Update set

Introduction

In this page you can find the example usage for org.springframework.data.mongodb.core.query Update set.

Prototype

public Update set(String key, Object value) 

Source Link

Document

Update using the $set update modifier

Usage

From source file:quanlyhocvu.api.mongodb.DAO.KhoiLopDAO.java

public boolean update(KhoiLopDTO dto) {
    boolean res = true;

    Query query = Query.query(Criteria.where("id").is(dto.getid()));
    Update update = new Update();
    update.set("tenKhoiLop", dto.gettenKhoiLop());
    update.set("moTa", dto.getmoTa());

    mongoOperation.findAndModify(query, update, KhoiLopDTO.class);
    return res;/*ww  w.  j av  a 2s.co m*/
}

From source file:quanlyhocvu.api.mongodb.DAO.GiaoVienDAO.java

public boolean updateTeacher(GiaoVienDTO teacher) {
    try {/* w ww  .ja  v a  2 s . c  om*/
        Query query = Query.query(Criteria.where("id").is(teacher.getid()));
        Update update = new Update();
        update.set("hoTen", teacher.gethoTen());
        update.set("gioiTinh", teacher.getgioiTinh());
        update.set("ngaySinh", teacher.getngaySinh());
        update.set("diaChi", teacher.getdiaChi());
        update.set("maGiaoVien", teacher.getmaGiaoVien());
        update.set("ngayVaoLam", teacher.getngayVaoLam());
        update.set("ngayNghiViec", teacher.getngayNghiViec());

        mongoOperations.findAndModify(query, update, GiaoVienDTO.class);
        return true;
    } catch (Exception ex) {
        logger.error("TeacherDAO - updateTeacher " + ex.getMessage());
        return false;
    }
}

From source file:quanlyhocvu.api.mongodb.DAO.ChiTietDiemDAO.java

public boolean update(ChiTietDiemDTO dto) {
    Query query = Query.query(Criteria.where("id").is(dto.getid()));
    Update update = new Update();

    update.set("diem", dto.getDiem());
    update.set("ktmieng_1", dto.getKtmieng_1());
    update.set("ktmieng_2", dto.getKtmieng_2());
    update.set("ktmieng_3", dto.getKtmieng_3());

    update.set("kt15_1", dto.getKt15_1());
    update.set("kt15_2", dto.getKt15_2());
    update.set("kt15_3", dto.getKt15_3());

    update.set("kt1tiet_1", dto.getKt1tiet_1());
    update.set("kt1tiet_2", dto.getKt1tiet_2());

    update.set("diemGiuaKy", dto.getDiemGiuaKy());
    update.set("diemCuoiKy", dto.getDiemCuoiKy());
    update.set("diemTB", dto.getDiemTB());

    return true;/*from w w w .j  ava  2 s  . co m*/
}

From source file:quanlyhocvu.api.mongodb.DAO.StaffDAO.java

/**
 * update staff current data//from   w  ww .  j a v a2 s  .co m
 *
 * @param staff
 * @return
 */
public boolean updateStaff(StaffDTO staff) {
    try {
        Query query = Query.query(Criteria.where("id").is(staff.getid()));
        Update update = new Update();
        update.set("hoTen", staff.gethoTen());
        update.set("gioiTinh", staff.getgioiTinh());
        update.set("ngaySinh", staff.getngaySinh());
        update.set("diaChi", staff.getdiaChi());
        update.set("manhanvien", staff.getManhanvien());
        update.set("ngayVaoLam", staff.getngayVaoLam());
        update.set("ngayNghiViec", staff.getngayNghiViec());

        mongoOperation.findAndModify(query, update, StaffDTO.class);
        return true;
    } catch (Exception ex) {
        return false;
    }
}

From source file:com.monkeyk.sos.infrastructure.mongo.UserRepositoryMongo.java

@Override
public boolean updateUser(User user) {
    Update update = new Update();
    update.set("password", user.password()).set("phone", user.phone())
            .set("lastLoginTime", user.lastLoginTime()).set("archived", user.archived())
            .set("email", user.email());

    update.set("privileges", user.privileges());

    Query query = createIDQuery(user.guid());
    this.mongoTemplate().updateFirst(query, update, User.class);
    return true;//from   ww  w . j a  v a2s  .c  o  m
}

From source file:com.springsource.html5expense.mongodb.services.ExpenseRepository.java

@Override
public Expense changeExpenseStatus(Long expenseId, String state) {
    Update update = new Update();
    update.set("state", State.valueOf(state));
    Expense exp = getExpense(expenseId);
    logger.debug("Get Expense " + exp.getDescription());
    mongoTemplate.updateFirst(new Query(Criteria.where("_id").is(expenseId)), update, EXPENSE_COLLECTION_NAME);
    return getExpense(expenseId);
}

From source file:no.nlf.dal.LicenseController.java

public License update(License license) {
    MongoLicense mongoLicense = new MongoLicense(license);
    Query searchQuery = new Query(Criteria.where("id").is(mongoLicense.getId()));

    Update updateLicense = new Update();

    updateLicense.set("melwinId", mongoLicense.getMelwinId());
    updateLicense.set("licenseName", mongoLicense.getLicenseName());
    updateLicense.set("active", mongoLicense.isActive());

    mongoLicense = appContext.mongoOperation().findAndModify(searchQuery, updateLicense,
            new FindAndModifyOptions().returnNew(true), MongoLicense.class);

    if (mongoLicense == null) {
        return new License();
    }//from  ww w . j  a v a 2  s  .  c  om

    return mongoLicense.toLicense();
}

From source file:quanlyhocvu.api.mongodb.DAO.CatalogNewsDAO.java

/**
 * update catalog info//www .j  a va  2s .  c  o  m
 * @param dto 
 */
public void udpateCatalog(CatalogNewsDTO dto) {
    Query query = Query.query(Criteria.where("id").is(dto.getId()));
    Update update = new Update();
    if (!"".equals(dto.getInfo())) {
        update.set("info", dto.getInfo());
    }
    if (!"".equals(dto.getName())) {
        update.set("name", dto.getName());
    }
    mongoOperation.findAndModify(query, update, CatalogNewsDTO.class);
}

From source file:quanlyhocvu.api.mongodb.DAO.HocSinhDAO.java

public boolean updateStudent(HocSinhDTO student) {
    try {//from w w  w.j a v  a  2  s.  c  o m
        Query query = Query.query(Criteria.where("id").is(student.getid()));
        Update update = new Update();
        update.set("hoTen", student.gethoTen());
        update.set("gioiTinh", student.getgioiTinh());
        update.set("ngaySinh", student.getngaySinh());
        update.set("diaChi", student.getdiaChi());
        update.set("maHocSinh", student.getmaHocSinh());
        update.set("ngayNhapHoc", student.getngayNhapHoc());
        update.set("ngayNghiHoc", student.getngayNghiHoc());
        update.set("maLopHoc", student.getMaLopHoc());

        mongoOperations.findAndModify(query, update, HocSinhDTO.class);
        return true;
    } catch (Exception ex) {
        logger.error("HocSinhDAO - updateStudent " + ex.getMessage());
        return false;
    }
}

From source file:quanlyhocvu.api.mongodb.DAO.LopHocDAO.java

public boolean addStudent(HocSinhDTO hs, String classId) {
    LopHocDTO lopHoc = getLopHocById(classId);
    List<HocSinhDTO> tempList = lopHoc.getlistHocSinh();
    tempList.add(hs);// w  ww . jav a  2 s . c  o  m
    Query query = Query.query(Criteria.where("id").is(classId));
    Update update = new Update();
    update.set("listHocSinh", tempList);
    mongoOperation.findAndModify(query, update, LopHocDTO.class);
    return true;
}