Search in sources :

Example 1 with MongoUpdate

use of com.duangframework.mongodb.common.MongoUpdate in project duangframework by tcrct.

the class CurdService method delete.

/**
 * 删除记录
 */
public boolean delete(String id) throws ServiceException {
    if (!ToolsKit.isValidDuangId(id)) {
        throw new ServiceException("it is not ObjectId");
    }
    MongoQuery<T> mongoQuery = new MongoQuery<>();
    mongoQuery.eq(IdEntity.ID_FIELD, id);
    MongoUpdate<T> mongoUpdate = new MongoUpdate<>();
    mongoUpdate.set(IdEntity.STATUS_FIELD, IdEntity.STATUS_FIELD_DELETE);
    try {
        long count = getMongoDao().update(mongoQuery, mongoUpdate);
        if (count > 0 && (getCacheDao() != null)) {
            getCacheDao().delete(entityClass, id);
        }
        return true;
    } catch (Exception e) {
        throw new ServiceException("delete id[" + id + "] record is fail: " + e.getMessage(), e);
    }
}
Also used : ServiceException(com.duangframework.core.exceptions.ServiceException) MongoUpdate(com.duangframework.mongodb.common.MongoUpdate) MongoQuery(com.duangframework.mongodb.common.MongoQuery) ServiceException(com.duangframework.core.exceptions.ServiceException) EmptyNullException(com.duangframework.core.exceptions.EmptyNullException)

Example 2 with MongoUpdate

use of com.duangframework.mongodb.common.MongoUpdate in project duangframework by tcrct.

the class MongoKit method clear.

private static void clear() {
    mongoQuery = new MongoQuery();
    mongoUpdate = new MongoUpdate();
}
Also used : MongoUpdate(com.duangframework.mongodb.common.MongoUpdate) MongoQuery(com.duangframework.mongodb.common.MongoQuery)

Aggregations

MongoQuery (com.duangframework.mongodb.common.MongoQuery)2 MongoUpdate (com.duangframework.mongodb.common.MongoUpdate)2 EmptyNullException (com.duangframework.core.exceptions.EmptyNullException)1 ServiceException (com.duangframework.core.exceptions.ServiceException)1