use of io.seata.sqlparser.SQLDeleteRecognizer in project seata by seata.
the class PostgresqlDeleteRecognizerTest method testGetWhereCondition_0.
@Test
public void testGetWhereCondition_0() {
String sql = "delete from t";
List<SQLRecognizer> sqlRecognizers = SQLVisitorFactory.get(sql, DB_TYPE);
SQLDeleteRecognizer recognizer = (SQLDeleteRecognizer) sqlRecognizers.get(0);
String whereCondition = recognizer.getWhereCondition(new ParametersHolder() {
@Override
public Map<Integer, ArrayList<Object>> getParameters() {
return null;
}
}, new ArrayList<>());
// test for no condition
Assertions.assertEquals("", whereCondition);
}
use of io.seata.sqlparser.SQLDeleteRecognizer in project seata by seata.
the class PostgresqlDeleteRecognizerTest method testGetSqlType.
@Test
public void testGetSqlType() {
String sql = "delete from t where id = ?";
List<SQLRecognizer> sqlRecognizers = SQLVisitorFactory.get(sql, DB_TYPE);
SQLDeleteRecognizer recognizer = (SQLDeleteRecognizer) sqlRecognizers.get(0);
Assertions.assertEquals(recognizer.getSQLType(), SQLType.DELETE);
}
use of io.seata.sqlparser.SQLDeleteRecognizer in project seata by seata.
the class MultiDeleteExecutor method beforeImage.
@Override
protected TableRecords beforeImage() throws SQLException {
if (sqlRecognizers.size() == 1) {
DeleteExecutor executor = new DeleteExecutor(statementProxy, statementCallback, sqlRecognizers.get(0));
return executor.beforeImage();
}
final TableMeta tmeta = getTableMeta(sqlRecognizers.get(0).getTableName());
final ArrayList<List<Object>> paramAppenderList = new ArrayList<>();
StringBuilder whereCondition = new StringBuilder();
for (SQLRecognizer recognizer : sqlRecognizers) {
sqlRecognizer = recognizer;
SQLDeleteRecognizer visitor = (SQLDeleteRecognizer) recognizer;
ParametersHolder parametersHolder = statementProxy instanceof ParametersHolder ? (ParametersHolder) statementProxy : null;
if (StringUtils.isNotBlank(visitor.getLimit(parametersHolder, paramAppenderList))) {
throw new NotSupportYetException("Multi delete SQL with limit condition is not support yet !");
}
if (StringUtils.isNotBlank(visitor.getOrderBy())) {
throw new NotSupportYetException("Multi delete SQL with orderBy condition is not support yet !");
}
String whereConditionStr = buildWhereCondition(visitor, paramAppenderList);
if (StringUtils.isBlank(whereConditionStr)) {
whereCondition = new StringBuilder();
paramAppenderList.clear();
break;
}
if (whereCondition.length() > 0) {
whereCondition.append(" OR ");
}
whereCondition.append(whereConditionStr);
}
StringBuilder suffix = new StringBuilder(" FROM ").append(getFromTableInSQL());
if (whereCondition.length() > 0) {
suffix.append(" WHERE ").append(whereCondition);
}
suffix.append(" FOR UPDATE");
final StringJoiner selectSQLAppender = new StringJoiner(", ", "SELECT ", suffix.toString());
for (String column : tmeta.getAllColumns().keySet()) {
selectSQLAppender.add(getColumnNameInSQL(ColumnUtils.addEscape(column, getDbType())));
}
return buildTableRecords(tmeta, selectSQLAppender.toString(), paramAppenderList);
}
use of io.seata.sqlparser.SQLDeleteRecognizer in project seata by seata.
the class PostgresqlDeleteRecognizerTest method testGetWhereCondition_1.
@Test
public void testGetWhereCondition_1() {
String sql = "delete from t";
List<SQLRecognizer> sqlRecognizers = SQLVisitorFactory.get(sql, DB_TYPE);
SQLDeleteRecognizer recognizer = (SQLDeleteRecognizer) sqlRecognizers.get(0);
String whereCondition = recognizer.getWhereCondition();
// test for no condition
Assertions.assertEquals("", whereCondition);
}
use of io.seata.sqlparser.SQLDeleteRecognizer in project seata by seata.
the class PostgresqlDeleteRecognizerTest method testGetTableAlias.
@Test
public void testGetTableAlias() {
String sql = "delete from t where id = ?";
List<SQLRecognizer> sqlRecognizers = SQLVisitorFactory.get(sql, DB_TYPE);
SQLDeleteRecognizer recognizer = (SQLDeleteRecognizer) sqlRecognizers.get(0);
Assertions.assertNull(recognizer.getTableAlias());
}
Aggregations