use of io.seata.sqlparser.SQLInsertRecognizer in project seata by seata.
the class BaseInsertExecutor method containsPK.
protected boolean containsPK() {
SQLInsertRecognizer recognizer = (SQLInsertRecognizer) sqlRecognizer;
List<String> insertColumns = recognizer.getInsertColumns();
if (CollectionUtils.isEmpty(insertColumns)) {
return false;
}
return containsPK(insertColumns);
}
use of io.seata.sqlparser.SQLInsertRecognizer in project seata by seata.
the class PostgresqlInsertExecutorTest method init.
@BeforeEach
public void init() {
ConnectionProxy connectionProxy = mock(ConnectionProxy.class);
when(connectionProxy.getDbType()).thenReturn(JdbcConstants.POSTGRESQL);
statementProxy = mock(PreparedStatementProxy.class);
when(statementProxy.getConnectionProxy()).thenReturn(connectionProxy);
StatementCallback statementCallback = mock(StatementCallback.class);
sqlInsertRecognizer = mock(SQLInsertRecognizer.class);
tableMeta = mock(TableMeta.class);
insertExecutor = Mockito.spy(new PostgresqlInsertExecutor(statementProxy, statementCallback, sqlInsertRecognizer));
pkIndexMap = new HashMap<String, Integer>() {
{
put(ID_COLUMN, pkIndex);
}
};
}
use of io.seata.sqlparser.SQLInsertRecognizer in project seata by seata.
the class MySQLInsertExecutorTest method init.
@BeforeEach
public void init() throws SQLException {
ConnectionProxy connectionProxy = mock(ConnectionProxy.class);
when(connectionProxy.getDbType()).thenReturn(JdbcConstants.MYSQL);
DataSourceProxy dataSourceProxy = new DataSourceProxy(new MockDataSource());
when(connectionProxy.getDataSourceProxy()).thenReturn(dataSourceProxy);
statementProxy = mock(PreparedStatementProxy.class);
when(statementProxy.getConnectionProxy()).thenReturn(connectionProxy);
when(statementProxy.getTargetStatement()).thenReturn(statementProxy);
MockResultSet resultSet = new MockResultSet(statementProxy);
resultSet.mockResultSet(Arrays.asList("Variable_name", "Value"), new Object[][] { { "auto_increment_increment", "1" } });
when(statementProxy.getTargetStatement().executeQuery("SHOW VARIABLES LIKE 'auto_increment_increment'")).thenReturn(resultSet);
StatementCallback statementCallback = mock(StatementCallback.class);
sqlInsertRecognizer = mock(SQLInsertRecognizer.class);
tableMeta = mock(TableMeta.class);
insertExecutor = Mockito.spy(new MySQLInsertExecutor(statementProxy, statementCallback, sqlInsertRecognizer));
pkIndexMap = new HashMap<String, Integer>() {
{
put(ID_COLUMN, pkIndex);
}
};
}
use of io.seata.sqlparser.SQLInsertRecognizer in project seata by seata.
the class PostgresqlInsertRecognizerTest method testGetInsertRows.
@Test
public void testGetInsertRows() {
final int pkIndex = 0;
// test for null value
String sql = "insert into t(id, no, name, age, time) values (nextval('id_seq'), null, 'a', ?, now())";
SQLInsertRecognizer recognizer = (SQLInsertRecognizer) SQLVisitorFactory.get(sql, DB_TYPE).get(0);
List<List<Object>> insertRows = recognizer.getInsertRows(Collections.singletonList(pkIndex));
Assertions.assertTrue(insertRows.size() == 1);
// test for exception
Assertions.assertThrows(SQLParsingException.class, () -> {
String s = "insert into t(a) values (?)";
List<SQLStatement> sqlStatements = SQLUtils.parseStatements(s, DB_TYPE);
SQLInsertStatement sqlInsertStatement = (SQLInsertStatement) sqlStatements.get(0);
sqlInsertStatement.getValuesList().get(0).getValues().set(pkIndex, new SQLBetweenExpr());
PostgresqlInsertRecognizer postgresqlInsertRecognizer = new PostgresqlInsertRecognizer(s, sqlInsertStatement);
postgresqlInsertRecognizer.getInsertRows(Collections.singletonList(pkIndex));
});
}
use of io.seata.sqlparser.SQLInsertRecognizer in project seata by seata.
the class PostgresqlInsertRecognizerTest method testGetSqlType.
@Test
public void testGetSqlType() {
String sql = "insert into t(id) values (?)";
List<SQLRecognizer> sqlRecognizers = SQLVisitorFactory.get(sql, DB_TYPE);
SQLInsertRecognizer recognizer = (SQLInsertRecognizer) sqlRecognizers.get(0);
Assertions.assertEquals(recognizer.getSQLType(), SQLType.INSERT);
}
Aggregations