Search in sources :

Example 1 with PreparedStatementProxy

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;
}
Also used : HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) SqlSequenceExpr(io.seata.sqlparser.struct.SqlSequenceExpr) PreparedStatementProxy(io.seata.rm.datasource.PreparedStatementProxy)

Example 2 with PreparedStatementProxy

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);
}
Also used : HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) PreparedStatementProxy(io.seata.rm.datasource.PreparedStatementProxy)

Example 3 with PreparedStatementProxy

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));
}
Also used : OracleInsertExecutor(io.seata.rm.datasource.exec.oracle.OracleInsertExecutor) ConnectionContext(io.seata.rm.datasource.ConnectionContext) TableMeta(io.seata.rm.datasource.sql.struct.TableMeta) PreparedStatementProxy(io.seata.rm.datasource.PreparedStatementProxy) SQLInsertRecognizer(io.seata.sqlparser.SQLInsertRecognizer) Test(org.junit.jupiter.api.Test)

Example 4 with PreparedStatementProxy

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);
}
Also used : Connection(java.sql.Connection) ConnectionProxy(io.seata.rm.datasource.ConnectionProxy) TableRecords(io.seata.rm.datasource.sql.struct.TableRecords) Field(java.lang.reflect.Field) MySQLInsertExecutor(io.seata.rm.datasource.exec.mysql.MySQLInsertExecutor) ConnectionContext(io.seata.rm.datasource.ConnectionContext) TableMeta(io.seata.rm.datasource.sql.struct.TableMeta) PreparedStatementProxy(io.seata.rm.datasource.PreparedStatementProxy) SQLInsertRecognizer(io.seata.sqlparser.SQLInsertRecognizer) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 5 with PreparedStatementProxy

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);
}
Also used : HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) PreparedStatementProxy(io.seata.rm.datasource.PreparedStatementProxy)

Aggregations

PreparedStatementProxy (io.seata.rm.datasource.PreparedStatementProxy)9 ArrayList (java.util.ArrayList)6 HashMap (java.util.HashMap)6 SQLInsertRecognizer (io.seata.sqlparser.SQLInsertRecognizer)3 List (java.util.List)3 ConnectionContext (io.seata.rm.datasource.ConnectionContext)2 TableMeta (io.seata.rm.datasource.sql.struct.TableMeta)2 NotSupportYetException (io.seata.common.exception.NotSupportYetException)1 ShouldNeverHappenException (io.seata.common.exception.ShouldNeverHappenException)1 ConnectionProxy (io.seata.rm.datasource.ConnectionProxy)1 MySQLInsertExecutor (io.seata.rm.datasource.exec.mysql.MySQLInsertExecutor)1 OracleInsertExecutor (io.seata.rm.datasource.exec.oracle.OracleInsertExecutor)1 TableRecords (io.seata.rm.datasource.sql.struct.TableRecords)1 SqlSequenceExpr (io.seata.sqlparser.struct.SqlSequenceExpr)1 Field (java.lang.reflect.Field)1 Connection (java.sql.Connection)1 Map (java.util.Map)1 BeforeEach (org.junit.jupiter.api.BeforeEach)1 Test (org.junit.jupiter.api.Test)1