use of io.seata.sqlparser.ParametersHolder in project seata by seata.
the class MySQLUpdateRecognizerTest method updateRecognizerTest_5.
/**
* Update recognizer test 5.
*/
@Test
public void updateRecognizerTest_5() {
String sql = "UPDATE t1 SET name1 = 'name1', name2 = 'name2' WHERE id between ? and ?";
SQLStatement statement = getSQLStatement(sql);
MySQLUpdateRecognizer mySQLUpdateRecognizer = new MySQLUpdateRecognizer(sql, statement);
Assertions.assertEquals(sql, mySQLUpdateRecognizer.getOriginalSQL());
Assertions.assertEquals("t1", mySQLUpdateRecognizer.getTableName());
Assertions.assertEquals(2, mySQLUpdateRecognizer.getUpdateColumns().size());
Assertions.assertEquals("name1", mySQLUpdateRecognizer.getUpdateColumns().get(0));
Assertions.assertEquals("name1", mySQLUpdateRecognizer.getUpdateValues().get(0));
Assertions.assertEquals("name2", mySQLUpdateRecognizer.getUpdateColumns().get(1));
Assertions.assertEquals("name2", mySQLUpdateRecognizer.getUpdateValues().get(1));
ArrayList<List<Object>> paramAppenderList = new ArrayList<>();
String whereCondition = mySQLUpdateRecognizer.getWhereCondition(new ParametersHolder() {
@Override
public Map<Integer, ArrayList<Object>> getParameters() {
ArrayList<Object> id1Param = new ArrayList<>();
id1Param.add("id1");
ArrayList<Object> id2Param = new ArrayList<>();
id2Param.add("id2");
Map result = new HashMap();
result.put(1, id1Param);
result.put(2, id2Param);
return result;
}
}, paramAppenderList);
Assertions.assertEquals(Collections.singletonList(Arrays.asList("id1", "id2")), paramAppenderList);
Assertions.assertEquals("id BETWEEN ? AND ?", whereCondition);
}
use of io.seata.sqlparser.ParametersHolder in project seata by seata.
the class MySQLUpdateRecognizerTest method updateRecognizerTest_2.
/**
* Update recognizer test 2.
*/
@Test
public void updateRecognizerTest_2() {
String sql = "UPDATE t1 SET name1 = 'name1', name2 = 'name2' WHERE id = ?";
SQLStatement statement = getSQLStatement(sql);
MySQLUpdateRecognizer mySQLUpdateRecognizer = new MySQLUpdateRecognizer(sql, statement);
Assertions.assertEquals(sql, mySQLUpdateRecognizer.getOriginalSQL());
Assertions.assertEquals("t1", mySQLUpdateRecognizer.getTableName());
Assertions.assertEquals(2, mySQLUpdateRecognizer.getUpdateColumns().size());
Assertions.assertEquals("name1", mySQLUpdateRecognizer.getUpdateColumns().get(0));
Assertions.assertEquals("name1", mySQLUpdateRecognizer.getUpdateValues().get(0));
Assertions.assertEquals("name2", mySQLUpdateRecognizer.getUpdateColumns().get(1));
Assertions.assertEquals("name2", mySQLUpdateRecognizer.getUpdateValues().get(1));
ArrayList<List<Object>> paramAppenderList = new ArrayList<>();
String whereCondition = mySQLUpdateRecognizer.getWhereCondition(new ParametersHolder() {
@Override
public Map<Integer, ArrayList<Object>> getParameters() {
ArrayList<Object> idParam = new ArrayList<>();
idParam.add("id1");
Map result = new HashMap();
result.put(1, idParam);
return result;
}
}, paramAppenderList);
Assertions.assertEquals(Collections.singletonList(Collections.singletonList("id1")), paramAppenderList);
Assertions.assertEquals("id = ?", whereCondition);
}
use of io.seata.sqlparser.ParametersHolder in project seata by seata.
the class MySQLDeleteRecognizerTest method deleteRecognizerTest_3.
/**
* Delete recognizer test 3.
*/
@Test
public void deleteRecognizerTest_3() {
String sql = "DELETE FROM t1 WHERE id between ? AND ?";
SQLStatement statement = getSQLStatement(sql);
MySQLDeleteRecognizer mySQLDeleteRecognizer = new MySQLDeleteRecognizer(sql, statement);
Assertions.assertEquals(sql, mySQLDeleteRecognizer.getOriginalSQL());
Assertions.assertEquals("t1", mySQLDeleteRecognizer.getTableName());
// test overflow parameters
ArrayList<List<Object>> paramAppenderList = new ArrayList<>();
String whereCondition = mySQLDeleteRecognizer.getWhereCondition(new ParametersHolder() {
@Override
public Map<Integer, ArrayList<Object>> getParameters() {
ArrayList<Object> idParam = new ArrayList<>();
idParam.add("id1");
ArrayList<Object> id2Param = new ArrayList<>();
id2Param.add("id2");
Map result = new HashMap();
result.put(1, idParam);
result.put(2, id2Param);
return result;
}
}, paramAppenderList);
Assertions.assertEquals(Collections.singletonList(Arrays.asList("id1", "id2")), paramAppenderList);
Assertions.assertEquals("id BETWEEN ? AND ?", whereCondition);
}
use of io.seata.sqlparser.ParametersHolder in project seata by seata.
the class MySQLDeleteRecognizerTest method deleteRecognizerTest_1.
/**
* Delete recognizer test 1.
*/
@Test
public void deleteRecognizerTest_1() {
String sql = "DELETE FROM t1 WHERE id = ?";
SQLStatement statement = getSQLStatement(sql);
MySQLDeleteRecognizer mySQLDeleteRecognizer = new MySQLDeleteRecognizer(sql, statement);
Assertions.assertEquals(sql, mySQLDeleteRecognizer.getOriginalSQL());
Assertions.assertEquals("t1", mySQLDeleteRecognizer.getTableName());
// test overflow parameters
ArrayList<List<Object>> paramAppenderList = new ArrayList<>();
String whereCondition = mySQLDeleteRecognizer.getWhereCondition(new ParametersHolder() {
@Override
public Map<Integer, ArrayList<Object>> getParameters() {
ArrayList<Object> idParam = new ArrayList<>();
idParam.add("id1");
Map result = new HashMap<>();
result.put(1, idParam);
return result;
}
}, paramAppenderList);
Assertions.assertEquals(Collections.singletonList(Collections.singletonList("id1")), paramAppenderList);
Assertions.assertEquals("id = ?", whereCondition);
}
use of io.seata.sqlparser.ParametersHolder in project seata by seata.
the class MySQLDeleteRecognizerTest method deleteRecognizerTest_2.
/**
* Delete recognizer test 2.
*/
@Test
public void deleteRecognizerTest_2() {
String sql = "DELETE FROM t1 WHERE id IN (?, ?)";
SQLStatement statement = getSQLStatement(sql);
MySQLDeleteRecognizer mySQLDeleteRecognizer = new MySQLDeleteRecognizer(sql, statement);
Assertions.assertEquals(sql, mySQLDeleteRecognizer.getOriginalSQL());
Assertions.assertEquals("t1", mySQLDeleteRecognizer.getTableName());
// test overflow parameters
ArrayList<List<Object>> paramAppenderList = new ArrayList<>();
String whereCondition = mySQLDeleteRecognizer.getWhereCondition(new ParametersHolder() {
@Override
public Map<Integer, ArrayList<Object>> getParameters() {
ArrayList<Object> idParam = new ArrayList<>();
idParam.add("id1");
ArrayList<Object> id2Param = new ArrayList<>();
id2Param.add("id2");
Map result = new HashMap();
result.put(1, idParam);
result.put(2, id2Param);
return result;
}
}, paramAppenderList);
Assertions.assertEquals(Arrays.asList(Arrays.asList("id1", "id2")), paramAppenderList);
Assertions.assertEquals("id IN (?, ?)", whereCondition);
}
Aggregations