use of io.seata.sqlparser.ParametersHolder in project seata by seata.
the class OracleUpdateRecognizerTest method testGetWhereCondition_0.
@Test
public void testGetWhereCondition_0() {
String sql = "update t set a = 1";
List<SQLStatement> asts = SQLUtils.parseStatements(sql, DB_TYPE);
OracleUpdateRecognizer recognizer = new OracleUpdateRecognizer(sql, asts.get(0));
String whereCondition = recognizer.getWhereCondition(new ParametersHolder() {
@Override
public Map<Integer, ArrayList<Object>> getParameters() {
return null;
}
}, new ArrayList<>());
Assertions.assertEquals("", whereCondition);
}
use of io.seata.sqlparser.ParametersHolder in project seata by seata.
the class PostgresqlUpdateRecognizerTest method testGetWhereCondition_0.
@Test
public void testGetWhereCondition_0() {
String sql = "update t set a = 1";
SQLUpdateRecognizer recognizer = (SQLUpdateRecognizer) SQLVisitorFactory.get(sql, DB_TYPE).get(0);
String whereCondition = recognizer.getWhereCondition(new ParametersHolder() {
@Override
public Map<Integer, ArrayList<Object>> getParameters() {
return null;
}
}, new ArrayList<>());
Assertions.assertEquals("", whereCondition);
}
use of io.seata.sqlparser.ParametersHolder in project seata by seata.
the class OracleSelectForUpdateRecognizerTest method testGetWhereCondition_0.
@Test
public void testGetWhereCondition_0() {
String sql = "select * from t for update";
List<SQLStatement> asts = SQLUtils.parseStatements(sql, DB_TYPE);
OracleSelectForUpdateRecognizer recognizer = new OracleSelectForUpdateRecognizer(sql, asts.get(0));
String whereCondition = recognizer.getWhereCondition(new ParametersHolder() {
@Override
public Map<Integer, ArrayList<Object>> getParameters() {
return null;
}
}, new ArrayList<>());
Assertions.assertEquals("", whereCondition);
}
use of io.seata.sqlparser.ParametersHolder in project seata by seata.
the class PostgresqlSelectForUpdateRecognizerTest method testGetWhereCondition_0.
@Test
public void testGetWhereCondition_0() {
String sql = "select * from t for update";
SQLSelectRecognizer recognizer = (SQLSelectRecognizer) SQLVisitorFactory.get(sql, DB_TYPE).get(0);
String whereCondition = recognizer.getWhereCondition(new ParametersHolder() {
@Override
public Map<Integer, ArrayList<Object>> getParameters() {
return null;
}
}, new ArrayList<>());
Assertions.assertEquals("", whereCondition);
}
use of io.seata.sqlparser.ParametersHolder in project seata by seata.
the class MultiUpdateExecutor method beforeImage.
@Override
protected TableRecords beforeImage() throws SQLException {
if (sqlRecognizers.size() == 1) {
UpdateExecutor executor = new UpdateExecutor<>(statementProxy, statementCallback, sqlRecognizers.get(0));
return executor.beforeImage();
}
final TableMeta tmeta = getTableMeta(sqlRecognizers.get(0).getTableName());
final ArrayList<List<Object>> paramAppenderList = new ArrayList<>();
Set<String> updateColumnsSet = new HashSet<>();
StringBuilder whereCondition = new StringBuilder();
boolean noWhereCondition = false;
for (SQLRecognizer recognizer : sqlRecognizers) {
sqlRecognizer = recognizer;
SQLUpdateRecognizer sqlUpdateRecognizer = (SQLUpdateRecognizer) recognizer;
ParametersHolder parametersHolder = statementProxy instanceof ParametersHolder ? (ParametersHolder) statementProxy : null;
if (StringUtils.isNotBlank(sqlUpdateRecognizer.getLimit(parametersHolder, paramAppenderList))) {
throw new NotSupportYetException("Multi update SQL with limit condition is not support yet !");
}
if (StringUtils.isNotBlank(sqlUpdateRecognizer.getOrderBy())) {
throw new NotSupportYetException("Multi update SQL with orderBy condition is not support yet !");
}
List<String> updateColumns = sqlUpdateRecognizer.getUpdateColumns();
updateColumnsSet.addAll(updateColumns);
if (noWhereCondition) {
continue;
}
String whereConditionStr = buildWhereCondition(sqlUpdateRecognizer, paramAppenderList);
if (StringUtils.isBlank(whereConditionStr)) {
noWhereCondition = true;
} else {
if (whereCondition.length() > 0) {
whereCondition.append(" OR ");
}
whereCondition.append(whereConditionStr);
}
}
StringBuilder prefix = new StringBuilder("SELECT ");
final StringBuilder suffix = new StringBuilder(" FROM ").append(getFromTableInSQL());
if (noWhereCondition) {
// select all rows
paramAppenderList.clear();
} else {
suffix.append(" WHERE ").append(whereCondition);
}
suffix.append(" FOR UPDATE");
final StringJoiner selectSQLAppender = new StringJoiner(", ", prefix, suffix.toString());
if (ONLY_CARE_UPDATE_COLUMNS) {
if (!containsPK(new ArrayList<>(updateColumnsSet))) {
selectSQLAppender.add(getColumnNamesInSQL(tmeta.getEscapePkNameList(getDbType())));
}
for (String updateCol : updateColumnsSet) {
selectSQLAppender.add(updateCol);
}
} else {
for (String columnName : tmeta.getAllColumns().keySet()) {
selectSQLAppender.add(ColumnUtils.addEscape(columnName, getDbType()));
}
}
return buildTableRecords(tmeta, selectSQLAppender.toString(), paramAppenderList);
}
Aggregations