org.mongodb.morphia.query.UpdateOperations Java Examples

The following examples show how to use org.mongodb.morphia.query.UpdateOperations. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: AbstractMongoJobQueue.java    From light-task-scheduler with Apache License 2.0 6 votes vote down vote up
private UpdateOperations<JobPo> buildUpdateOperations(JobQueueReq request) {
    UpdateOperations<JobPo> operations = template.createUpdateOperations(JobPo.class);
    addUpdateField(operations, "cronExpression", request.getCronExpression());
    addUpdateField(operations, "needFeedback", request.getNeedFeedback());
    addUpdateField(operations, "extParams", request.getExtParams());
    addUpdateField(operations, "triggerTime", request.getTriggerTime() == null ? null : request.getTriggerTime().getTime());
    addUpdateField(operations, "priority", request.getPriority());
    addUpdateField(operations, "maxRetryTimes", request.getMaxRetryTimes());
    addUpdateField(operations, "relyOnPrevCycle", request.getRelyOnPrevCycle() == null ? true : request.getRelyOnPrevCycle());
    addUpdateField(operations, "submitNodeGroup", request.getSubmitNodeGroup());
    addUpdateField(operations, "taskTrackerNodeGroup", request.getTaskTrackerNodeGroup());
    addUpdateField(operations, "repeatCount", request.getRepeatCount());
    addUpdateField(operations, "repeatInterval", request.getRepeatInterval());
    addUpdateField(operations, "gmtModified", SystemClock.now());
    return operations;
}
 
Example #2
Source File: MongoPreLoader.java    From light-task-scheduler with Apache License 2.0 6 votes vote down vote up
protected boolean lockJob(String taskTrackerNodeGroup, String jobId, String taskTrackerIdentity, Long triggerTime, Long gmtModified) {
    UpdateOperations<JobPo> operations =
            template.createUpdateOperations(JobPo.class)
                    .set("isRunning", true)
                    .set("taskTrackerIdentity", taskTrackerIdentity)
                    .set("gmtModified", SystemClock.now());

    String tableName = JobQueueUtils.getExecutableQueueName(taskTrackerNodeGroup);

    Query<JobPo> updateQuery = template.createQuery(tableName, JobPo.class);
    updateQuery.field("jobId").equal(jobId)
            .field("isRunning").equal(false)
            .field("triggerTime").equal(triggerTime)
            .field("gmtModified").equal(gmtModified);
    UpdateResults updateResult = template.update(updateQuery, operations);
    return updateResult.getUpdatedCount() == 1;
}
 
Example #3
Source File: MongoRepeatJobQueue.java    From light-task-scheduler with Apache License 2.0 6 votes vote down vote up
@Override
public int incRepeatedCount(String jobId) {
    while (true) {
        JobPo jobPo = getJob(jobId);
        if (jobPo == null) {
            return -1;
        }
        Query<JobPo> query = template.createQuery(JobPo.class);
        query.field("jobId").equal(jobId);
        query.field("repeatedCount").equal(jobPo.getRepeatedCount());

        UpdateOperations<JobPo> opts = template.createUpdateOperations(JobPo.class);
        opts.set("repeatedCount", jobPo.getRepeatedCount() + 1);

        UpdateResults ur = template.update(query, opts);
        if (ur.getUpdatedCount() == 1) {
            return jobPo.getRepeatedCount() + 1;
        }
    }
}
 
Example #4
Source File: HallInfoDao.java    From game-server with MIT License 5 votes vote down vote up
/**
 * 增加属性的值
 * 
 * @param num
 *            增加量
 * @param fieldName
 *            属性名称
 * @return
 */
public static HallInfo incFieldNum(int num, String fieldName) {
	Query<HallInfo> query = hallInfoDao.createQuery();
	UpdateOperations<HallInfo> updateOperations = hallInfoDao.createUpdateOperations().inc(fieldName, num);
	HallInfo hallInfo = hallInfoDao.getDs().findAndModify(query, updateOperations);
	if (hallInfo == null) {
		hallInfo = new HallInfo();
		hallInfoDao.save(hallInfo);
		hallInfo = hallInfoDao.getDs().findAndModify(query, updateOperations);
	}
	return hallInfo;
}
 
Example #5
Source File: MongoExecutableJobQueue.java    From light-task-scheduler with Apache License 2.0 5 votes vote down vote up
public void resume(JobPo jobPo) {
    String tableName = JobQueueUtils.getExecutableQueueName(jobPo.getTaskTrackerNodeGroup());
    Query<JobPo> query = template.createQuery(tableName, JobPo.class);

    query.field("jobId").equal(jobPo.getJobId());

    UpdateOperations<JobPo> operations =
            template.createUpdateOperations(JobPo.class)
                    .set("isRunning", false)
                    .set("taskTrackerIdentity", "")
                    .set("gmtModified", SystemClock.now());
    template.update(query, operations);
}
 
Example #6
Source File: MongoSchedulerJobQueue.java    From light-task-scheduler with Apache License 2.0 5 votes vote down vote up
@Override
public boolean updateLastGenerateTriggerTime(String jobId, Long lastGenerateTriggerTime) {
    Query<JobPo> query = template.createQuery(getTableName(), JobPo.class);

    query.field("jobId").equal(jobId);

    UpdateOperations<JobPo> operations =
            template.createUpdateOperations(JobPo.class)
                    .set("lastGenerateTriggerTime", lastGenerateTriggerTime)
                    .set("gmtModified", SystemClock.now());

    UpdateResults ur = template.update(query, operations);
    return ur.getUpdatedCount() == 1;
}
 
Example #7
Source File: AbstractMongoJobQueue.java    From light-task-scheduler with Apache License 2.0 5 votes vote down vote up
private UpdateOperations<JobPo> addUpdateField(UpdateOperations<JobPo> operations, String field, Object o) {
    if (!checkCondition(o)) {
        return operations;
    }
    operations.set(field, o);
    return operations;
}
 
Example #8
Source File: AbstractMongoJobQueue.java    From light-task-scheduler with Apache License 2.0 5 votes vote down vote up
@Override
public boolean selectiveUpdateByTaskId(JobQueueReq request) {
    Assert.hasLength(request.getRealTaskId(), "Only allow update by realTaskId and taskTrackerNodeGroup");
    Assert.hasLength(request.getTaskTrackerNodeGroup(), "Only allow update by realTaskId and taskTrackerNodeGroup");

    Query<JobPo> query = template.createQuery(getTargetTable(request.getTaskTrackerNodeGroup()), JobPo.class);
    query.field("realTaskId").equal(request.getRealTaskId());
    query.field("taskTrackerNodeGroup").equal(request.getTaskTrackerNodeGroup());

    UpdateOperations<JobPo> operations = buildUpdateOperations(request);
    UpdateResults ur = template.update(query, operations);
    return ur.getUpdatedCount() == 1;
}
 
Example #9
Source File: AbstractMongoJobQueue.java    From light-task-scheduler with Apache License 2.0 5 votes vote down vote up
@Override
public boolean selectiveUpdateByJobId(JobQueueReq request) {
    Assert.hasLength(request.getJobId(), "Only allow update by jobId");

    Query<JobPo> query = template.createQuery(getTargetTable(request.getTaskTrackerNodeGroup()), JobPo.class);
    query.field("jobId").equal(request.getJobId());

    UpdateOperations<JobPo> operations = buildUpdateOperations(request);
    UpdateResults ur = template.update(query, operations);
    return ur.getUpdatedCount() == 1;
}
 
Example #10
Source File: MongoTemplate.java    From light-task-scheduler with Apache License 2.0 4 votes vote down vote up
public <T> UpdateOperations<T> createUpdateOperations(final Class<T> clazz) {
    return ds.createUpdateOperations(clazz);
}
 
Example #11
Source File: MongoTemplate.java    From light-task-scheduler with Apache License 2.0 4 votes vote down vote up
public <T> T findAndModify(final Query<T> query, final UpdateOperations<T> ops) {
    return findAndModify(query, ops, false);
}
 
Example #12
Source File: MongoTemplate.java    From light-task-scheduler with Apache License 2.0 4 votes vote down vote up
public <T> T findAndModify(final Query<T> query, final UpdateOperations<T> ops, final boolean oldVersion) {
    return findAndModify(query, ops, oldVersion, false);
}
 
Example #13
Source File: MongoTemplate.java    From light-task-scheduler with Apache License 2.0 4 votes vote down vote up
public <T> T findAndModify(final Query<T> query, final UpdateOperations<T> ops, final boolean oldVersion, final boolean createIfMissing) {
    return ds.findAndModify(query, ops, oldVersion, createIfMissing);
}
 
Example #14
Source File: MongoTemplate.java    From light-task-scheduler with Apache License 2.0 4 votes vote down vote up
public <T> UpdateResults update(final Query<T> query, final UpdateOperations<T> ops, final boolean createIfMissing) {
    return ds.update(query, ops, createIfMissing);
}
 
Example #15
Source File: MongoTemplate.java    From light-task-scheduler with Apache License 2.0 4 votes vote down vote up
public <T> UpdateResults update(final Query<T> query, final UpdateOperations<T> ops) {
    return ds.update(query, ops);
}
 
Example #16
Source File: MongoTemplate.java    From light-task-scheduler with Apache License 2.0 4 votes vote down vote up
public <T> UpdateResults updateFirst(final Query<T> query, final UpdateOperations<T> ops, final boolean createIfMissing) {
    return ds.updateFirst(query, ops, createIfMissing);
}
 
Example #17
Source File: MongoTemplate.java    From light-task-scheduler with Apache License 2.0 4 votes vote down vote up
public <T> UpdateResults updateFirst(final Query<T> query, final UpdateOperations<T> ops) {
    return ds.updateFirst(query, ops);
}
 
Example #18
Source File: MailDao.java    From game-server with MIT License 2 votes vote down vote up
/**
 * 改变邮件状态
 * 
 * @author JiangZhiYong
 * @QQ 359135103 2017年9月21日 下午4:15:10
 * @param id
 * @param mailState
 */
public static Mail modifyMailState(long id, int mailState) {
	Query<Mail> query = mailDao.createQuery().filter("id", id);
	UpdateOperations<Mail> operations = mailDao.createUpdateOperations().set("state", mailState);
	return mailDao.getDs().findAndModify(query, operations);
}