All Downloads are FREE. Search and download functionalities are using the official Maven repository.

io.datarouter.jobletmysql.txn.ReserveJobletRequest Maven / Gradle / Ivy

There is a newer version: 0.0.126
Show newest version
/*
 * Copyright © 2009 HotPads ([email protected])
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package io.datarouter.jobletmysql.txn;

import io.datarouter.client.mysql.op.BaseMysqlOp;
import io.datarouter.client.mysql.op.Isolation;
import io.datarouter.client.mysql.sql.MysqlSql;
import io.datarouter.client.mysql.sql.MysqlSqlFactory;
import io.datarouter.client.mysql.util.MysqlTool;
import io.datarouter.joblet.JobletRequestSqlBuilder;
import io.datarouter.joblet.storage.jobletrequest.DatarouterJobletRequestDao;
import io.datarouter.joblet.type.JobletType;
import io.datarouter.storage.client.ClientId;
import io.datarouter.storage.client.DatarouterClients;

public class ReserveJobletRequest extends BaseMysqlOp{

	private final ClientId clientId;
	private final String tableName;
	private final boolean disableIntroducer;
	private final String reservedBy;
	private final JobletType jobletType;
	private final MysqlSqlFactory mysqlSqlFactory;
	private final JobletRequestSqlBuilder jobletRequestSqlBuilder;

	public ReserveJobletRequest(
			String reservedBy,
			JobletType jobletType,
			DatarouterClients datarouterClients,
			DatarouterJobletRequestDao jobletRequestDao,
			MysqlSqlFactory mysqlSqlFactory,
			JobletRequestSqlBuilder jobletRequestSqlBuilder){
		super(datarouterClients,
				jobletRequestDao.getPhysicalNode().getClientId(),
				Isolation.repeatableRead,
				false);
		this.clientId = jobletRequestDao.getPhysicalNode().getClientId();
		this.tableName = jobletRequestDao.getPhysicalNode().getFieldInfo().getTableName();
		this.disableIntroducer = jobletRequestDao.getPhysicalNode().getFieldInfo().getDisableIntroducer();
		this.reservedBy = reservedBy;
		this.jobletType = jobletType;
		this.mysqlSqlFactory = mysqlSqlFactory;
		this.jobletRequestSqlBuilder = jobletRequestSqlBuilder;
	}

	@Override
	public Boolean runOnce(){
		MysqlSql sql = mysqlSqlFactory.createSql(clientId, tableName, disableIntroducer);
		jobletRequestSqlBuilder.makeReserveJobletRequest(sql, jobletType, reservedBy);
		int numRowsModified = MysqlTool.update(sql.prepare(getConnection()));
		return numRowsModified > 0;
	}

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy