Search in sources :

Example 11 with DataSourceProxy

use of io.seata.rm.datasource.DataSourceProxy in project seata by seata.

the class PlainExecutorTest method init.

@BeforeEach
public void init() throws SQLException {
    List<String> returnValueColumnLabels = Lists.newArrayList("id", "name");
    Object[][] returnValue = new Object[][] { new Object[] { 1, "Tom" }, new Object[] { 2, "Jack" } };
    Object[][] columnMetas = new Object[][] { new Object[] { "", "", "table_plain_executor_test", "id", Types.INTEGER, "INTEGER", 64, 0, 10, 1, "", "", 0, 0, 64, 1, "NO", "YES" }, new Object[] { "", "", "table_plain_executor_test", "name", Types.VARCHAR, "VARCHAR", 64, 0, 10, 0, "", "", 0, 0, 64, 2, "YES", "NO" } };
    Object[][] indexMetas = new Object[][] { new Object[] { "PRIMARY", "id", false, "", 3, 1, "A", 34 } };
    MockDriver mockDriver = new MockDriver(returnValueColumnLabels, returnValue, columnMetas, indexMetas);
    DruidDataSource dataSource = new DruidDataSource();
    dataSource.setUrl("jdbc:mock:xxx");
    dataSource.setDriver(mockDriver);
    DataSourceProxy dataSourceProxy = new DataSourceProxy(dataSource);
    ConnectionProxy connectionProxy = new ConnectionProxy(dataSourceProxy, dataSource.getConnection().getConnection());
    MockStatementBase mockStatement = new MockStatement(dataSource.getConnection().getConnection());
    StatementProxy statementProxy = new StatementProxy(connectionProxy, mockStatement);
    plainExecutor = new PlainExecutor(statementProxy, (statement, args) -> null);
}
Also used : BeforeEach(org.junit.jupiter.api.BeforeEach) MockDriver(io.seata.rm.datasource.mock.MockDriver) StatementProxy(io.seata.rm.datasource.StatementProxy) Test(org.junit.jupiter.api.Test) MockStatementBase(com.alibaba.druid.mock.MockStatementBase) SQLException(java.sql.SQLException) List(java.util.List) Lists(com.google.common.collect.Lists) ConnectionProxy(io.seata.rm.datasource.ConnectionProxy) MockStatement(com.alibaba.druid.mock.MockStatement) DruidDataSource(com.alibaba.druid.pool.DruidDataSource) DataSourceProxy(io.seata.rm.datasource.DataSourceProxy) Types(java.sql.Types) MockDriver(io.seata.rm.datasource.mock.MockDriver) DataSourceProxy(io.seata.rm.datasource.DataSourceProxy) DruidDataSource(com.alibaba.druid.pool.DruidDataSource) ConnectionProxy(io.seata.rm.datasource.ConnectionProxy) MockStatementBase(com.alibaba.druid.mock.MockStatementBase) StatementProxy(io.seata.rm.datasource.StatementProxy) MockStatement(com.alibaba.druid.mock.MockStatement) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 12 with DataSourceProxy

use of io.seata.rm.datasource.DataSourceProxy in project seata by seata.

the class OracleTableMetaCacheTest method getTableMetaTest.

@Test
public void getTableMetaTest() throws SQLException {
    MockDriver mockDriver = new MockDriver(columnMetas, indexMetas, pkMetas);
    DruidDataSource dataSource = new DruidDataSource();
    dataSource.setUrl("jdbc:mock:xxx");
    dataSource.setDriver(mockDriver);
    DataSourceProxy proxy = new DataSourceProxy(dataSource);
    TableMetaCache tableMetaCache = TableMetaCacheFactory.getTableMetaCache(JdbcConstants.ORACLE);
    TableMeta tableMeta = tableMetaCache.getTableMeta(proxy.getPlainConnection(), "t.ot1", proxy.getResourceId());
    Assertions.assertNotNull(tableMeta);
    tableMeta = tableMetaCache.getTableMeta(proxy.getPlainConnection(), "t.\"ot1\"", proxy.getResourceId());
    Assertions.assertNotNull(tableMeta);
}
Also used : MockDriver(io.seata.rm.datasource.mock.MockDriver) DataSourceProxy(io.seata.rm.datasource.DataSourceProxy) TableMetaCache(io.seata.rm.datasource.sql.struct.TableMetaCache) TableMeta(io.seata.rm.datasource.sql.struct.TableMeta) DruidDataSource(com.alibaba.druid.pool.DruidDataSource) Test(org.junit.jupiter.api.Test)

Example 13 with DataSourceProxy

use of io.seata.rm.datasource.DataSourceProxy in project seata by seata.

the class PostgresqlTableMetaCacheTest method getTableMetaTest.

@Test
public void getTableMetaTest() throws SQLException {
    MockDriver mockDriver = new MockDriver(columnMetas, indexMetas, pkMetas);
    DruidDataSource dataSource = new DruidDataSource();
    dataSource.setUrl("jdbc:mock:xxx");
    dataSource.setDriver(mockDriver);
    DataSourceProxy proxy = new DataSourceProxy(dataSource);
    TableMetaCache tableMetaCache = TableMetaCacheFactory.getTableMetaCache(JdbcConstants.POSTGRESQL);
    TableMeta tableMeta = tableMetaCache.getTableMeta(proxy.getPlainConnection(), "pt1", proxy.getResourceId());
    Assertions.assertNotNull(tableMeta);
    tableMeta = tableMetaCache.getTableMeta(proxy.getPlainConnection(), "t.pt1", proxy.getResourceId());
    Assertions.assertNotNull(tableMeta);
    tableMeta = tableMetaCache.getTableMeta(proxy.getPlainConnection(), "t.\"pt1\"", proxy.getResourceId());
    Assertions.assertNotNull(tableMeta);
}
Also used : MockDriver(io.seata.rm.datasource.mock.MockDriver) DataSourceProxy(io.seata.rm.datasource.DataSourceProxy) TableMetaCache(io.seata.rm.datasource.sql.struct.TableMetaCache) TableMeta(io.seata.rm.datasource.sql.struct.TableMeta) DruidDataSource(com.alibaba.druid.pool.DruidDataSource) Test(org.junit.jupiter.api.Test)

Example 14 with DataSourceProxy

use of io.seata.rm.datasource.DataSourceProxy in project seata by seata.

the class MysqlTableMetaCacheTest method refreshTest_0.

@Test
public void refreshTest_0() throws SQLException {
    MockDriver mockDriver = new MockDriver(columnMetas, indexMetas);
    DruidDataSource druidDataSource = new DruidDataSource();
    druidDataSource.setUrl("jdbc:mock:xxx");
    druidDataSource.setDriver(mockDriver);
    DataSourceProxy dataSourceProxy = new DataSourceProxy(druidDataSource);
    TableMeta tableMeta = getTableMetaCache().getTableMeta(dataSourceProxy.getPlainConnection(), "t1", dataSourceProxy.getResourceId());
    // change the columns meta
    columnMetas = new Object[][] { new Object[] { "", "", "mt1", "id", Types.INTEGER, "INTEGER", 64, 0, 10, 1, "", "", 0, 0, 64, 1, "NO", "YES" }, new Object[] { "", "", "mt1", "name1", Types.VARCHAR, "VARCHAR", 65, 0, 10, 0, "", "", 0, 0, 64, 2, "YES", "NO" }, new Object[] { "", "", "mt1", "name2", Types.VARCHAR, "VARCHAR", 64, 0, 10, 0, "", "", 0, 0, 64, 3, "YES", "NO" }, new Object[] { "", "", "mt1", "name3", Types.VARCHAR, "VARCHAR", 64, 0, 10, 0, "", "", 0, 0, 64, 4, "YES", "NO" } };
    mockDriver.setMockColumnsMetasReturnValue(columnMetas);
    getTableMetaCache().refresh(dataSourceProxy.getPlainConnection(), dataSourceProxy.getResourceId());
}
Also used : MockDriver(io.seata.rm.datasource.mock.MockDriver) DataSourceProxy(io.seata.rm.datasource.DataSourceProxy) TableMeta(io.seata.rm.datasource.sql.struct.TableMeta) DruidDataSource(com.alibaba.druid.pool.DruidDataSource) Test(org.junit.jupiter.api.Test)

Example 15 with DataSourceProxy

use of io.seata.rm.datasource.DataSourceProxy in project dynamic-datasource-spring-boot-starter by baomidou.

the class AbstractDataSourceCreator method wrapDataSource.

private DataSource wrapDataSource(DataSource dataSource, DataSourceProperty dataSourceProperty) {
    String name = dataSourceProperty.getPoolName();
    DataSource targetDataSource = dataSource;
    Boolean enabledP6spy = properties.getP6spy() && dataSourceProperty.getP6spy();
    if (enabledP6spy) {
        targetDataSource = new P6DataSource(dataSource);
        log.debug("dynamic-datasource [{}] wrap p6spy plugin", name);
    }
    Boolean enabledSeata = properties.getSeata() && dataSourceProperty.getSeata();
    SeataMode seataMode = properties.getSeataMode();
    if (enabledSeata) {
        if (SeataMode.XA == seataMode) {
            targetDataSource = new DataSourceProxyXA(targetDataSource);
        } else {
            targetDataSource = new DataSourceProxy(targetDataSource);
        }
        log.debug("dynamic-datasource [{}] wrap seata plugin transaction mode ", name);
    }
    return new ItemDataSource(name, dataSource, targetDataSource, enabledP6spy, enabledSeata, seataMode);
}
Also used : P6DataSource(com.p6spy.engine.spy.P6DataSource) DataSourceProxyXA(io.seata.rm.datasource.xa.DataSourceProxyXA) DataSourceProxy(io.seata.rm.datasource.DataSourceProxy) ItemDataSource(com.baomidou.dynamic.datasource.ds.ItemDataSource) ItemDataSource(com.baomidou.dynamic.datasource.ds.ItemDataSource) P6DataSource(com.p6spy.engine.spy.P6DataSource) DataSource(javax.sql.DataSource) SeataMode(com.baomidou.dynamic.datasource.enums.SeataMode)

Aggregations

DataSourceProxy (io.seata.rm.datasource.DataSourceProxy)16 DruidDataSource (com.alibaba.druid.pool.DruidDataSource)12 MockDriver (io.seata.rm.datasource.mock.MockDriver)12 Test (org.junit.jupiter.api.Test)10 MockStatement (com.alibaba.druid.mock.MockStatement)7 ConnectionProxy (io.seata.rm.datasource.ConnectionProxy)7 MockStatementBase (com.alibaba.druid.mock.MockStatementBase)6 TableMeta (io.seata.rm.datasource.sql.struct.TableMeta)6 StatementProxy (io.seata.rm.datasource.StatementProxy)5 Field (java.lang.reflect.Field)5 SQLException (java.sql.SQLException)5 Lists (com.google.common.collect.Lists)4 Types (java.sql.Types)4 List (java.util.List)4 BeforeAll (org.junit.jupiter.api.BeforeAll)4 SQLUtils (com.alibaba.druid.sql.SQLUtils)3 SQLStatement (com.alibaba.druid.sql.ast.SQLStatement)3 JdbcConstants (com.alibaba.druid.util.JdbcConstants)3 Assertions (org.junit.jupiter.api.Assertions)3 BeforeEach (org.junit.jupiter.api.BeforeEach)3