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

com.github.antelopeframework.mybatis.shard.converter.UpdateSqlConverter Maven / Gradle / Ivy

There is a newer version: 1.1.5
Show newest version
package com.github.antelopeframework.mybatis.shard.converter;

import java.util.List;
import java.util.Map;

import com.github.antelopeframework.mybatis.shard.ShardContext.ShardOnPair;

import net.sf.jsqlparser.schema.Table;
import net.sf.jsqlparser.statement.Statement;
import net.sf.jsqlparser.statement.update.Update;

/**
 * UPDATE 语句表名替换.
 * 
 * @author yangzhi.yzh
 *
 */
class UpdateSqlConverter extends AbstractSqlConverter {
	
	@Override
	protected Statement doConvert(String sqlMapperId, Statement statement, Map shardOns) {
		if (!(statement instanceof Update)) {
			throw new IllegalArgumentException("The argument statement must is instance of Update.");
		}
		
		Update update = (Update) statement;
		List tables = update.getTables();
		for (Table table : tables) {
			String tableName = table.getName();
			table.setName(convertTableName(sqlMapperId, tableName, shardOns));
		}
		
		return update;
	}
}