use of io.seata.rm.datasource.PreparedStatementProxy in project seata by seata.
the class OracleInsertExecutorTest method mockParametersPkWithSeq.
private SqlSequenceExpr mockParametersPkWithSeq() {
SqlSequenceExpr expr = new SqlSequenceExpr("seq", "nextval");
Map<Integer, ArrayList<Object>> paramters = new HashMap(4);
ArrayList arrayList0 = new ArrayList<>();
arrayList0.add(expr);
ArrayList arrayList1 = new ArrayList<>();
arrayList1.add("userId1");
ArrayList arrayList2 = new ArrayList<>();
arrayList2.add("userName1");
ArrayList arrayList3 = new ArrayList<>();
arrayList3.add("userStatus1");
paramters.put(1, arrayList0);
paramters.put(2, arrayList1);
paramters.put(3, arrayList2);
paramters.put(4, arrayList3);
PreparedStatementProxy psp = (PreparedStatementProxy) this.statementProxy;
when(psp.getParameters()).thenReturn(paramters);
List<List<Object>> rows = new ArrayList<>();
rows.add(Arrays.asList("?", "?", "?"));
when(sqlInsertRecognizer.getInsertRows(pkIndexMap.values())).thenReturn(rows);
return expr;
}
use of io.seata.rm.datasource.PreparedStatementProxy in project seata by seata.
the class OracleInsertExecutorTest method mockParametersPkWithAuto.
private void mockParametersPkWithAuto() {
Map<Integer, ArrayList<Object>> paramters = new HashMap<>(4);
ArrayList arrayList0 = new ArrayList<>();
arrayList0.add(Null.get());
ArrayList arrayList1 = new ArrayList<>();
arrayList1.add("userId1");
ArrayList arrayList2 = new ArrayList<>();
arrayList2.add("userName1");
ArrayList arrayList3 = new ArrayList<>();
arrayList3.add("userStatus1");
paramters.put(1, arrayList0);
paramters.put(2, arrayList1);
paramters.put(3, arrayList2);
paramters.put(4, arrayList3);
PreparedStatementProxy psp = (PreparedStatementProxy) this.statementProxy;
when(psp.getParameters()).thenReturn(paramters);
List<List<Object>> rows = new ArrayList<>();
rows.add(Arrays.asList("?", "?", "?", "?"));
when(sqlInsertRecognizer.getInsertRows(pkIndexMap.values())).thenReturn(rows);
}
use of io.seata.rm.datasource.PreparedStatementProxy in project seata by seata.
the class AbstractDMLBaseExecutorTest method testOnlySupportMysqlWhenUseMultiPk.
@Test
public void testOnlySupportMysqlWhenUseMultiPk() {
Mockito.when(connectionProxy.getContext()).thenReturn(new ConnectionContext());
PreparedStatementProxy statementProxy = Mockito.mock(PreparedStatementProxy.class);
Mockito.when(statementProxy.getConnectionProxy()).thenReturn(connectionProxy);
StatementCallback statementCallback = Mockito.mock(StatementCallback.class);
SQLInsertRecognizer sqlInsertRecognizer = Mockito.mock(SQLInsertRecognizer.class);
TableMeta tableMeta = Mockito.mock(TableMeta.class);
executor = Mockito.spy(new OracleInsertExecutor(statementProxy, statementCallback, sqlInsertRecognizer));
Mockito.when(executor.getDbType()).thenReturn(JdbcConstants.ORACLE);
Mockito.doReturn(tableMeta).when(executor).getTableMeta();
Mockito.when(tableMeta.getPrimaryKeyOnlyName()).thenReturn(Arrays.asList("id", "userCode"));
Assertions.assertThrows(NotSupportYetException.class, () -> executor.executeAutoCommitFalse(null));
}
use of io.seata.rm.datasource.PreparedStatementProxy in project seata by seata.
the class AbstractDMLBaseExecutorTest method initBeforeEach.
@BeforeEach
public void initBeforeEach() throws Exception {
branchRollbackFlagField = ConnectionProxy.LockRetryPolicy.class.getDeclaredField("LOCK_RETRY_POLICY_BRANCH_ROLLBACK_ON_CONFLICT");
Field modifiersField = Field.class.getDeclaredField("modifiers");
modifiersField.setAccessible(true);
modifiersField.setInt(branchRollbackFlagField, branchRollbackFlagField.getModifiers() & ~Modifier.FINAL);
branchRollbackFlagField.setAccessible(true);
boolean branchRollbackFlag = (boolean) branchRollbackFlagField.get(null);
Assertions.assertTrue(branchRollbackFlag);
Connection targetConnection = Mockito.mock(Connection.class);
connectionProxy = Mockito.mock(ConnectionProxy.class);
Mockito.doThrow(new LockConflictException()).when(connectionProxy).commit();
Mockito.when(connectionProxy.getAutoCommit()).thenReturn(Boolean.TRUE);
Mockito.when(connectionProxy.getTargetConnection()).thenReturn(targetConnection);
Mockito.when(connectionProxy.getContext()).thenReturn(new ConnectionContext());
PreparedStatementProxy statementProxy = Mockito.mock(PreparedStatementProxy.class);
Mockito.when(statementProxy.getConnectionProxy()).thenReturn(connectionProxy);
StatementCallback statementCallback = Mockito.mock(StatementCallback.class);
SQLInsertRecognizer sqlInsertRecognizer = Mockito.mock(SQLInsertRecognizer.class);
TableMeta tableMeta = Mockito.mock(TableMeta.class);
executor = Mockito.spy(new MySQLInsertExecutor(statementProxy, statementCallback, sqlInsertRecognizer));
Mockito.doReturn(tableMeta).when(executor).getTableMeta();
TableRecords tableRecords = new TableRecords();
Mockito.doReturn(tableRecords).when(executor).beforeImage();
Mockito.doReturn(tableRecords).when(executor).afterImage(tableRecords);
}
use of io.seata.rm.datasource.PreparedStatementProxy in project seata by seata.
the class MySQLInsertExecutorTest method mockParametersPkWithNull.
private void mockParametersPkWithNull() {
Map<Integer, ArrayList<Object>> parameters = new HashMap<>(4);
ArrayList arrayList0 = new ArrayList<>();
arrayList0.add(Null.get());
ArrayList arrayList1 = new ArrayList<>();
arrayList1.add("userId1");
ArrayList arrayList2 = new ArrayList<>();
arrayList2.add("userName1");
ArrayList arrayList3 = new ArrayList<>();
arrayList3.add("userStatus1");
parameters.put(1, arrayList0);
parameters.put(2, arrayList1);
parameters.put(3, arrayList2);
parameters.put(4, arrayList3);
PreparedStatementProxy psp = (PreparedStatementProxy) this.statementProxy;
when(psp.getParameters()).thenReturn(parameters);
}
Aggregations