当前位置: 首页>>代码示例>>Java>>正文


Java TAtomDataSource类代码示例

本文整理汇总了Java中com.taobao.tddl.atom.TAtomDataSource的典型用法代码示例。如果您正苦于以下问题:Java TAtomDataSource类的具体用法?Java TAtomDataSource怎么用?Java TAtomDataSource使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


TAtomDataSource类属于com.taobao.tddl.atom包,在下文中一共展示了TAtomDataSource类的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: createTAtomDataSource

import com.taobao.tddl.atom.TAtomDataSource; //导入依赖的package包/类
@Test
public void testInitTAtomDataSource_初始化() throws Exception {
    String appName = "tddl_sample";
    String dbKey = "tddl_sample_0";
    // Oracle测试
    // TAtomDataSource tAtomDataSource = createTAtomDataSource(appName,
    // dbKey, "oracle");
    // JdbcTemplate jtp = new JdbcTemplate(tAtomDataSource);
    // int actual = jtp.queryForInt(TAtomDataSourceUnitTest.TEST_SQL);
    // Assert.assertEquals(actual, 1);
    // tAtomDataSource.destroyDataSource();
    // mysql测试
    TAtomDataSource tAtomDataSource = createTAtomDataSource(appName, dbKey, "mysql");
    JdbcTemplate jtp = new JdbcTemplate(tAtomDataSource);
    int actual = jtp.queryForInt(TAtomDataSourceTest.TEST_SQL);
    Assert.assertEquals(actual, 1);
    tAtomDataSource.destroyDataSource();
}
 
开发者ID:loye168,项目名称:tddl5,代码行数:19,代码来源:TAtomDataSourceTest.java

示例2: initAtomDataSource

import com.taobao.tddl.atom.TAtomDataSource; //导入依赖的package包/类
private TAtomDsStandard initAtomDataSource(String appName, String dsKey, String unitName) {
    try {
        if (tGroupDataSource.getDataSourceType().equals(DataSourceType.DruidDataSource)) {
            TAtomDsStandard atomDataSource = new TAtomDataSource();
            atomDataSource.init(appName, dsKey, unitName);
            atomDataSource.setLogWriter(tGroupDataSource.getLogWriter());
            atomDataSource.setLoginTimeout(tGroupDataSource.getLoginTimeout());
            return atomDataSource;
        } else {
            throw new IllegalArgumentException("do not have this datasource type : "
                                               + tGroupDataSource.getDataSourceType());
        }
    } catch (Exception e) {
        throw new TAtomDataSourceException("TAtomDataSource无法初始化: dsKey=" + dsKey, e);
    }
}
 
开发者ID:beebeandwer,项目名称:TDDL,代码行数:17,代码来源:GroupConfigManager.java

示例3: getAtomDatasource

import com.taobao.tddl.atom.TAtomDataSource; //导入依赖的package包/类
public TAtomDataSource getAtomDatasource(DataSource s) {
    if (s instanceof TAtomDataSource) {
        return (TAtomDataSource) s;
    }

    if (s instanceof DataSourceWrapper) {
        return getAtomDatasource(((DataSourceWrapper) s).getWrappedDataSource());
    }

    throw new IllegalAccessError();
}
 
开发者ID:loye168,项目名称:tddl5,代码行数:12,代码来源:ShowDatasourcesHandler.java

示例4: main

import com.taobao.tddl.atom.TAtomDataSource; //导入依赖的package包/类
public static void main(String[] args) throws Exception {

        TAtomDataSource ds = new TAtomDataSource();
        ds.setDbKey("my193179_sqa_yh_mydevice_3407");
        System.out.println("init done");

        Connection conn = ds.getConnection();

        // insert a record
        // conn.prepareStatement("replace into sample_table (id,name,address) values (1,'sun','hz')").executeUpdate();

        System.out.println("insert done");

        // select all records
        PreparedStatement ps = conn.prepareStatement("SELECT * from sample_table a where a.id = any (select id from sample_table where id='1')");

        ResultSet rs = ps.executeQuery();
        while (rs.next()) {
            StringBuilder sb = new StringBuilder();
            int count = rs.getMetaData().getColumnCount();
            for (int i = 1; i <= count; i++) {

                String key = rs.getMetaData().getColumnLabel(i);
                Object val = rs.getObject(i);
                sb.append("[" + rs.getMetaData().getTableName(i) + "." + key + "->" + val + "]");
            }
            System.out.println(sb.toString());
        }

        rs.close();
        ps.close();
        conn.close();

        System.out.println("query done");

    }
 
开发者ID:loye168,项目名称:tddl5,代码行数:37,代码来源:CopyOfDynamicConfigSample.java

示例5: testChange

import com.taobao.tddl.atom.TAtomDataSource; //导入依赖的package包/类
private void testChange(ChangeTestConfig change, ChangeTestConfig restore, String type, String dbType,
                        String methodName) throws IOException, TddlException, Exception {
    String appName = "tddl_sample";
    String dbKey = "unitTestDb-" + methodName;
    String configName = dbType;
    String testSql = TAtomDataSourceTest.TEST_SQL;
    TAtomDataSource tAtomDataSource = createTAtomDataSource(appName, dbKey, configName);
    JdbcTemplate jtp = new JdbcTemplate(tAtomDataSource);
    int actual = jtp.queryForInt(testSql);
    Assert.assertEquals(actual, 1);
    // 设置错误的IP进行推送
    String fileName = "";
    String dataId = "";
    if (type.equals("globa")) {
        fileName = "/globa.properties";
        dataId = TAtomConstants.getGlobalDataId(dbKey);
    } else if (type.equals("app")) {
        fileName = "/app.properties";
        dataId = TAtomConstants.getAppDataId(appName, dbKey);
    }
    Properties prop = PropLoadTestUtil.loadPropFromFile("conf/" + configName + fileName);
    MockServer.setConfigInfo(dataId, PropLoadTestUtil.convertProp2Str(change.doChange(prop)));
    Thread.sleep(3000);
    // 期待出现错误
    boolean result = false;
    try {
        actual = jtp.queryForInt(testSql);
    } catch (Throwable e) {
        result = true;
    }
    Assert.assertTrue(result);
    MockServer.setConfigInfo(dataId,
        PropLoadTestUtil.convertProp2Str(restore.doChange(PropLoadTestUtil.loadPropFromFile("conf/" + configName
                                                                                            + fileName))));
    Thread.sleep(3000);
    // 期待结果正常
    actual = jtp.queryForInt(testSql);
    Assert.assertEquals(actual, 1);
    tAtomDataSource.destroyDataSource();
}
 
开发者ID:loye168,项目名称:tddl5,代码行数:41,代码来源:TAtomDataSourceTest.java

示例6: setUp

import com.taobao.tddl.atom.TAtomDataSource; //导入依赖的package包/类
@BeforeClass
public static void setUp() throws Exception {
    setAtomMockInfo(ATOM_NORMAL_0_PATH, APPNAME, DBKEY_0);
    tds = new TAtomDataSource();
    tds.setAppName(APPNAME);
    tds.setDbKey(DBKEY_0);
    tds.init();
    tddlJT = getJT();
}
 
开发者ID:loye168,项目名称:tddl5,代码行数:10,代码来源:AtomTestCase.java

示例7: getJT

import com.taobao.tddl.atom.TAtomDataSource; //导入依赖的package包/类
protected static JdbcTemplate getJT(String path, String appName, String dbKey) throws Exception {
    setAtomMockInfo(path, appName, dbKey);
    TAtomDataSource atomDs = new TAtomDataSource();
    atomDs.setAppName(appName);
    atomDs.setDbKey(dbKey);
    atomDs.init();
    return new JdbcTemplate(atomDs);
}
 
开发者ID:loye168,项目名称:tddl5,代码行数:9,代码来源:AtomTestCase.java

示例8: testChange

import com.taobao.tddl.atom.TAtomDataSource; //导入依赖的package包/类
private void testChange(ChangeTestConfig change, ChangeTestConfig restore, String type, String dbType,
                        String methodName) throws IOException, AtomAlreadyInitException, Exception {
    String appName = "tddl_sample";
    String dbKey = "unitTestDb-" + methodName;
    String configName = dbType;
    String testSql = TAtomDataSourceTest.TEST_SQL;
    TAtomDataSource tAtomDataSource = createTAtomDataSource(appName, dbKey, configName);
    JdbcTemplate jtp = new JdbcTemplate(tAtomDataSource);
    int actual = jtp.queryForInt(testSql);
    Assert.assertEquals(actual, 1);
    // 设置错误的IP进行推送
    String fileName = "";
    String dataId = "";
    if (type.equals("globa")) {
        fileName = "/globa.properties";
        dataId = TAtomConstants.getGlobalDataId(dbKey);
    } else if (type.equals("app")) {
        fileName = "/app.properties";
        dataId = TAtomConstants.getAppDataId(appName, dbKey);
    }
    Properties prop = PropLoadTestUtil.loadPropFromFile("conf/" + configName + fileName);
    MockServer.setConfigInfo(dataId, PropLoadTestUtil.convertProp2Str(change.doChange(prop)));
    Thread.sleep(3000);
    // 期待出现错误
    boolean result = false;
    try {
        actual = jtp.queryForInt(testSql);
    } catch (Throwable e) {
        result = true;
    }
    Assert.assertTrue(result);
    MockServer.setConfigInfo(dataId,
        PropLoadTestUtil.convertProp2Str(restore.doChange(PropLoadTestUtil.loadPropFromFile("conf/" + configName
                                                                                            + fileName))));
    Thread.sleep(3000);
    // 期待结果正常
    actual = jtp.queryForInt(testSql);
    Assert.assertEquals(actual, 1);
    tAtomDataSource.destroyDataSource();
}
 
开发者ID:beebeandwer,项目名称:TDDL,代码行数:41,代码来源:TAtomDataSourceTest.java

示例9: handle

import com.taobao.tddl.atom.TAtomDataSource; //导入依赖的package包/类
@Override
public ISchematicCursor handle(IDataNodeExecutor executor, ExecutionContext executionContext) throws TddlException {
    ArrayResultCursor result = new ArrayResultCursor("TRACE", executionContext);
    result.addColumn("ID", DataType.IntegerType);
    result.addColumn("SCHEMA", DataType.StringType);
    result.addColumn("NAME", DataType.StringType);

    result.addColumn("GROUP", DataType.StringType);
    result.addColumn("URL", DataType.StringType);
    result.addColumn("USER", DataType.StringType);
    result.addColumn("TYPE", DataType.StringType);
    result.addColumn("INIT", DataType.StringType);
    result.addColumn("MIN", DataType.StringType);

    result.addColumn("MAX", DataType.StringType);
    result.addColumn("IDLE_TIMEOUT", DataType.StringType);
    result.addColumn("MAX_WAIT", DataType.StringType);

    result.addColumn("ACTIVE_COUNT", DataType.StringType);
    result.addColumn("POOLING_COUNT", DataType.StringType);

    result.initMeta();
    int index = 0;

    Matrix matrix = ExecutorContext.getContext().getTopologyHandler().getMatrix();
    TopologyHandler topology = ExecutorContext.getContext().getTopologyHandler();

    for (Group group : matrix.getGroups()) {
        IGroupExecutor groupExecutor = topology.get(group.getName());

        Object o = groupExecutor.getRemotingExecutableObject();

        if (o != null && o instanceof TGroupDataSource) {
            TGroupDataSource ds = (TGroupDataSource) o;

            for (DataSource atom : ds.getDataSourceMap().values()) {
                TAtomDataSource atomDs = this.getAtomDatasource(atom);
                DruidDataSource d;
                try {

                    if (!(atomDs.getDataSource().getTargetDataSource() instanceof DruidDataSource)) {
                        logger.warn("atom datasource is not druid?"
                                    + atomDs.getDataSource().getTargetDataSource().getClass());
                        continue;
                    }
                    d = (DruidDataSource) atomDs.getDataSource().getTargetDataSource();
                    result.addRow(new Object[] { index++, topology.getAppName(), d.getName(), group.getName(),
                            d.getUrl(), d.getUsername(), d.getDbType(), d.getInitialSize(), d.getMinIdle(),
                            d.getMaxActive(), d.getTimeBetweenEvictionRunsMillis() / (1000 * 60), d.getMaxWait(),
                            d.getActiveCount(), d.getPoolingCount() });

                } catch (SQLException e) {
                    logger.error("", e);
                }

            }
        }
    }

    return result;

}
 
开发者ID:loye168,项目名称:tddl5,代码行数:63,代码来源:ShowDatasourcesHandler.java

示例10: testChangePasswd

import com.taobao.tddl.atom.TAtomDataSource; //导入依赖的package包/类
private void testChangePasswd(ChangeTestConfig change, ChangeTestConfig restore, String dbType) throws IOException,
                                                                                               TddlException,
                                                                                               Exception {
    String appName = "tddl_sample";
    String dbKey = "unitTestDb-" + dbType;
    String configName = "";
    String testSql = TAtomDataSourceTest.TEST_SQL;
    configName = dbType;
    TAtomDataSource tAtomDataSource = createTAtomDataSource(appName, dbKey, configName);
    JdbcTemplate jtp = new JdbcTemplate(tAtomDataSource);
    int actual = jtp.queryForInt(testSql);
    Assert.assertEquals(actual, 1);
    // 设置错误的IP进行推送
    // 全局配置
    String globaStr = PropLoadTestUtil.loadPropFile2String("conf/" + configName + "/globa.properties");
    MockServer.setConfigInfo(TAtomConstants.getGlobalDataId(dbKey), globaStr);
    // 应用配置
    String appStr = PropLoadTestUtil.loadPropFile2String("conf/" + configName + "/app.properties");
    MockServer.setConfigInfo(TAtomConstants.getAppDataId(appName, dbKey), appStr);
    // 解析配置
    TAtomDsConfDO tAtomDsConfDO = TAtomConfParser.parserTAtomDsConfDO(globaStr, appStr);
    Properties passwdProp = PropLoadTestUtil.loadPropFromFile("conf/" + configName + "/passwd.properties");
    String passwdDataId = TAtomConstants.getPasswdDataId(tAtomDsConfDO.getDbName(),
        tAtomDsConfDO.getDbType(),
        tAtomDsConfDO.getUserName());
    MockServer.setConfigInfo(passwdDataId, PropLoadTestUtil.convertProp2Str(change.doChange(passwdProp)));
    Thread.sleep(3000);
    // 期待出现错误
    boolean result = false;
    try {
        actual = jtp.queryForInt(testSql);
    } catch (Throwable e) {
        result = true;
    }
    Assert.assertTrue(result);
    MockServer.setConfigInfo(passwdDataId,
        PropLoadTestUtil.convertProp2Str(restore.doChange(PropLoadTestUtil.loadPropFromFile("conf/" + configName
                                                                                            + "/passwd.properties"))));
    Thread.sleep(3000);
    // 期待结果正常
    actual = jtp.queryForInt(testSql);
    Assert.assertEquals(actual, 1);
    tAtomDataSource.destroyDataSource();

}
 
开发者ID:loye168,项目名称:tddl5,代码行数:46,代码来源:TAtomDataSourceTest.java

示例11: atomSetUp

import com.taobao.tddl.atom.TAtomDataSource; //导入依赖的package包/类
@BeforeClass
public static void atomSetUp() {
    TAtomDataSource.cleanAllDataSource();
}
 
开发者ID:loye168,项目名称:tddl5,代码行数:5,代码来源:BaseAtomGroupTestCase.java

示例12: atomTearDown

import com.taobao.tddl.atom.TAtomDataSource; //导入依赖的package包/类
@AfterClass
public static void atomTearDown() {
    TAtomDataSource.cleanAllDataSource();
}
 
开发者ID:loye168,项目名称:tddl5,代码行数:5,代码来源:BaseAtomGroupTestCase.java

示例13: testChangePasswd

import com.taobao.tddl.atom.TAtomDataSource; //导入依赖的package包/类
private void testChangePasswd(ChangeTestConfig change, ChangeTestConfig restore, String dbType)
                                                                                               throws IOException,
                                                                                               AtomAlreadyInitException,
                                                                                               Exception {
    String appName = "tddl_sample";
    String dbKey = "unitTestDb-" + dbType;
    String configName = "";
    String testSql = TAtomDataSourceTest.TEST_SQL;
    configName = dbType;
    TAtomDataSource tAtomDataSource = createTAtomDataSource(appName, dbKey, configName);
    JdbcTemplate jtp = new JdbcTemplate(tAtomDataSource);
    int actual = jtp.queryForInt(testSql);
    Assert.assertEquals(actual, 1);
    // 设置错误的IP进行推送
    // 全局配置
    String globaStr = PropLoadTestUtil.loadPropFile2String("conf/" + configName + "/globa.properties");
    MockServer.setConfigInfo(TAtomConstants.getGlobalDataId(dbKey), globaStr);
    // 应用配置
    String appStr = PropLoadTestUtil.loadPropFile2String("conf/" + configName + "/app.properties");
    MockServer.setConfigInfo(TAtomConstants.getAppDataId(appName, dbKey), appStr);
    // 解析配置
    TAtomDsConfDO tAtomDsConfDO = TAtomConfParser.parserTAtomDsConfDO(globaStr, appStr);
    Properties passwdProp = PropLoadTestUtil.loadPropFromFile("conf/" + configName + "/passwd.properties");
    String passwdDataId = TAtomConstants.getPasswdDataId(tAtomDsConfDO.getDbName(),
        tAtomDsConfDO.getDbType(),
        tAtomDsConfDO.getUserName());
    MockServer.setConfigInfo(passwdDataId, PropLoadTestUtil.convertProp2Str(change.doChange(passwdProp)));
    Thread.sleep(3000);
    // 期待出现错误
    boolean result = false;
    try {
        actual = jtp.queryForInt(testSql);
    } catch (Throwable e) {
        result = true;
    }
    Assert.assertTrue(result);
    MockServer.setConfigInfo(passwdDataId,
        PropLoadTestUtil.convertProp2Str(restore.doChange(PropLoadTestUtil.loadPropFromFile("conf/" + configName
                                                                                            + "/passwd.properties"))));
    Thread.sleep(3000);
    // 期待结果正常
    actual = jtp.queryForInt(testSql);
    Assert.assertEquals(actual, 1);
    tAtomDataSource.destroyDataSource();

}
 
开发者ID:beebeandwer,项目名称:TDDL,代码行数:47,代码来源:TAtomDataSourceTest.java


注:本文中的com.taobao.tddl.atom.TAtomDataSource类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。