com.github.ltsopensource.queue.mysql.MysqlSuspendJobQueue Maven / Gradle / Ivy
package com.github.ltsopensource.queue.mysql;
import com.github.ltsopensource.core.cluster.Config;
import com.github.ltsopensource.core.support.JobQueueUtils;
import com.github.ltsopensource.queue.SuspendJobQueue;
import com.github.ltsopensource.queue.domain.JobPo;
import com.github.ltsopensource.queue.mysql.support.RshHolder;
import com.github.ltsopensource.store.jdbc.builder.DeleteSql;
import com.github.ltsopensource.store.jdbc.builder.SelectSql;
import com.github.ltsopensource.admin.request.JobQueueReq;
/**
* @author bug ([email protected]) on 3/4/16.
*/
public class MysqlSuspendJobQueue extends AbstractMysqlJobQueue implements SuspendJobQueue {
public MysqlSuspendJobQueue(Config config) {
super(config);
createTable(readSqlFile("sql/mysql/lts_suspend_job_queue.sql", getTableName()));
}
@Override
protected String getTableName(JobQueueReq request) {
return getTableName();
}
@Override
public boolean add(JobPo jobPo) {
return add(getTableName(), jobPo);
}
@Override
public JobPo getJob(String jobId) {
return new SelectSql(getSqlTemplate())
.select()
.all()
.from()
.table(getTableName())
.where("job_id = ?", jobId)
.single(RshHolder.JOB_PO_RSH);
}
@Override
public boolean remove(String jobId) {
return new DeleteSql(getSqlTemplate())
.delete()
.from()
.table(getTableName())
.where("job_id = ?", jobId)
.doDelete() == 1;
}
private String getTableName() {
return JobQueueUtils.SUSPEND_JOB_QUEUE;
}
}