當前位置: 首頁>>代碼示例>>Java>>正文


Java TGroupDataSource.init方法代碼示例

本文整理匯總了Java中com.taobao.tddl.group.jdbc.TGroupDataSource.init方法的典型用法代碼示例。如果您正苦於以下問題:Java TGroupDataSource.init方法的具體用法?Java TGroupDataSource.init怎麽用?Java TGroupDataSource.init使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在com.taobao.tddl.group.jdbc.TGroupDataSource的用法示例。


在下文中一共展示了TGroupDataSource.init方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: testGroupDataSourceRouteHelper

import com.taobao.tddl.group.jdbc.TGroupDataSource; //導入方法依賴的package包/類
@Test
public void testGroupDataSourceRouteHelper() throws Exception {
    try {
        TGroupDataSource ds = new TGroupDataSource(GROUP0, APPNAME);
        MockServer.setConfigInfo(ds.getFullDbGroupKey(), DSKEY0 + ":rw" + "," + DSKEY1 + ":r");
        ds.init();

        GroupDataSourceRouteHelper.executeByGroupDataSourceIndex(0);
        Connection conn = ds.getConnection();
        Statement stmt = conn.createStatement();
        assertEquals(stmt.executeUpdate("insert into tddl_test_0000(id,name) values(100,'str')"), 1);
        ResultSet rs = stmt.executeQuery("select id,name from tddl_test_0000 where id=100");
        assertTrue(rs.next());
        // 如果指定了index,忽略rw限製
        ThreadLocalMap.put(ThreadLocalString.DATASOURCE_INDEX, 1);
        assertEquals(stmt.executeUpdate("insert into tddl_test_0000(id,name) values(100,'str')"), 1);
        rs = stmt.executeQuery("select count(*) from tddl_test_0000 where id=100");
        assertTrue(rs.next());
        assertEquals(rs.getInt(1), 1);

        stmt.close();
        conn.close();
    } finally {
        ThreadLocalMap.put(ThreadLocalString.DATASOURCE_INDEX, null);
    }
}
 
開發者ID:beebeandwer,項目名稱:TDDL,代碼行數:27,代碼來源:DataSourceIndexTest.java

示例2: testThreadLocalDataSourceIndex

import com.taobao.tddl.group.jdbc.TGroupDataSource; //導入方法依賴的package包/類
@Test
public void testThreadLocalDataSourceIndex() throws Exception {
    try {
        TGroupDataSource ds = new TGroupDataSource(GROUP0, APPNAME);
        MockServer.setConfigInfo(ds.getFullDbGroupKey(), DSKEY0 + ":rw" + "," + DSKEY1 + ":r");
        ds.init();

        ThreadLocalMap.put(ThreadLocalString.DATASOURCE_INDEX, 0);
        Connection conn = ds.getConnection();
        Statement stmt = conn.createStatement();
        assertEquals(stmt.executeUpdate("insert into tddl_test_0000(id,name) values(100,'str')"), 1);
        ResultSet rs = stmt.executeQuery("select id,name from tddl_test_0000 where id=100");
        assertTrue(rs.next());
        // 如果指定了index,忽略rw限製
        ThreadLocalMap.put(ThreadLocalString.DATASOURCE_INDEX, 1);
        assertEquals(stmt.executeUpdate("insert into tddl_test_0000(id,name) values(100,'str')"), 1);
        rs = stmt.executeQuery("select count(*) from tddl_test_0000 where id=100");
        assertTrue(rs.next());
        assertEquals(rs.getInt(1), 1);

        stmt.close();
        conn.close();
    } finally {
        ThreadLocalMap.put(ThreadLocalString.DATASOURCE_INDEX, null);
    }
}
 
開發者ID:loye168,項目名稱:tddl5,代碼行數:27,代碼來源:DataSourceIndexTest.java

示例3: doInit

import com.taobao.tddl.group.jdbc.TGroupDataSource; //導入方法依賴的package包/類
/**
 * 初試化
 */
public void doInit() throws TddlException {
    // 如果應用名為空,直接拋出
    if (StringUtils.isEmpty(appName)) {
        SequenceException sequenceException = new SequenceException("appName is Null ");
        logger.error("沒有配置appName", sequenceException);
        throw sequenceException;
    }

    if (dbGroupKeys == null || dbGroupKeys.size() == 0) {
        logger.error("沒有配置dbgroupKeys");
        throw new SequenceException("dbgroupKeys為空!");
    }

    // 取得unit數據
    this.changeConfig(false, null);
    RouterUnitsHelper.registerUnitsListener(this);
    dataSourceMap = new HashMap<String, DataSource>();
    for (String dbGroupKey : dbGroupKeys) {
        if (dbGroupKey.toUpperCase().endsWith("-OFF")) {
            continue;
        }
        // TGroupDataSource tGroupDataSource = new TGroupDataSource(
        // dbGroupKey, appName, dataSourceType);
        TGroupDataSource tGroupDataSource = new TGroupDataSource(dbGroupKey, appName);
        tGroupDataSource.init();
        dataSourceMap.put(dbGroupKey, tGroupDataSource);
    }

    outputInitResult();
}
 
開發者ID:loye168,項目名稱:tddl5,代碼行數:34,代碼來源:UnitGroupSequenceDao.java

示例4: DataSourceWrapper

import com.taobao.tddl.group.jdbc.TGroupDataSource; //導入方法依賴的package包/類
@Test
public void 測試DataSourceWrapper() throws Exception {
    List<DataSourceWrapper> dataSourceWrappers = new ArrayList<DataSourceWrapper>();
    dataSourceWrappers.add(new DataSourceWrapper(DSKEY1, "rw", getMySQLDataSource(1), DBType.MYSQL));
    dataSourceWrappers.add(new DataSourceWrapper(DSKEY2, "r", getMySQLDataSource(2), DBType.MYSQL));

    TGroupDataSource ds = new TGroupDataSource();
    ds.setDbGroupKey(GROUP0);
    ds.init(dataSourceWrappers);

    testCrud(ds);
}
 
開發者ID:beebeandwer,項目名稱:TDDL,代碼行數:13,代碼來源:CrudTest.java

示例5: setUp

import com.taobao.tddl.group.jdbc.TGroupDataSource; //導入方法依賴的package包/類
@Before
public void setUp() throws Exception {
    s1 = new TGroupDataSource();
    s1.setAppName("TDDLSEQUENCE");
    s1.setDbGroupKey("TDDL_SEQUENCE_GROUP0");
    s1.init();

    s2 = new TGroupDataSource();
    s2.setAppName("TDDLSEQUENCE");
    s2.setDbGroupKey("TDDL_SEQUENCE_GROUP1");
    s2.init();

    dao = new GroupSequenceDao();
    // 設置adjust為true,這樣不必關心怎麽樣去設置有規律的值。單元化部署必須設置這個值為true,切換的時候自動更新
    dao.setAdjust(true);
    dao.setAppName("TDDLSEQUENCE");
    List<String> dbGroups = new ArrayList<String>();
    dbGroups.add("TDDL_SEQUENCE_GROUP0");
    dbGroups.add("TDDL_SEQUENCE_GROUP1");
    dao.setDbGroupKeys(dbGroups);
    dao.setDscount(2);
    dao.setInnerStep(1000);
    dao.init();

    updateNormalTable(0);
    updateTestTable(testStart);

    GroupSequence s = new GroupSequence();
    s.setName("ladygaga");
    s.setSequenceDao(dao);
    s.init();
    sequence = s;
}
 
開發者ID:loye168,項目名稱:tddl5,代碼行數:34,代碼來源:PerfGroupSequenceDaoTest.java

示例6: main

import com.taobao.tddl.group.jdbc.TGroupDataSource; //導入方法依賴的package包/類
public static void main(String[] args) throws Exception {

        TGroupDataSource ds = new TGroupDataSource();
        // init a datasource with dynamic config on diamond
        ds.setAppName("ICBU_PB_METADATA_TEST_APP");
        ds.setDbGroupKey("PBSERVER_GROUP");
        ds.init();

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

        Connection conn = ds.getConnection();

        PreparedStatement ps = conn.prepareStatement("select * from auks_task_detail_normal");

        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,代碼行數:35,代碼來源:XuqiangSample.java

示例7: getMySQLDataSource

import com.taobao.tddl.group.jdbc.TGroupDataSource; //導入方法依賴的package包/類
@Test
public void 三個數據庫_測試db1可讀寫_db2與db3隻能讀() throws Exception {
    DataSource ds0 = getMySQLDataSource(0);
    DataSource ds1 = getMySQLDataSource(1);
    DataSource ds2 = getMySQLDataSource(2);

    // 讀庫時最有可能從db3讀,然後是db2,db1的權重最小
    TGroupDataSource ds = new TGroupDataSource();
    DataSourceWrapper dsw0 = new DataSourceWrapper(DSKEY0, "r10w", ds0, DBType.MYSQL);
    DataSourceWrapper dsw1 = new DataSourceWrapper(DSKEY1, "r20", ds1, DBType.MYSQL);
    DataSourceWrapper dsw2 = new DataSourceWrapper(DSKEY2, "r30", ds2, DBType.MYSQL);
    ds.init(dsw0, dsw1, dsw2);

    testCrud(ds);
}
 
開發者ID:beebeandwer,項目名稱:TDDL,代碼行數:16,代碼來源:CrudTest.java

示例8: getJT

import com.taobao.tddl.group.jdbc.TGroupDataSource; //導入方法依賴的package包/類
protected static JdbcTemplate getJT(String dbGroupKey) {
    tds = new TGroupDataSource();
    tds.setAppName(APPNAME);
    tds.setDbGroupKey(dbGroupKey);
    try {
        tds.init();
    } catch (TddlException e) {
        Assert.fail();
    }
    return new JdbcTemplate(tds);
}
 
開發者ID:loye168,項目名稱:tddl5,代碼行數:12,代碼來源:GroupTestCase.java

示例9: TGroupDataSource

import com.taobao.tddl.group.jdbc.TGroupDataSource; //導入方法依賴的package包/類
@Test
public void 單個數據庫() throws Exception {
    TGroupDataSource ds = new TGroupDataSource();
    DataSourceWrapper dsw = new DataSourceWrapper(DSKEY0, "rw", getMySQLDataSource(), DBType.MYSQL);
    ds.init(dsw);

    testCrud(ds);
}
 
開發者ID:beebeandwer,項目名稱:TDDL,代碼行數:9,代碼來源:CrudTest.java

示例10: init

import com.taobao.tddl.group.jdbc.TGroupDataSource; //導入方法依賴的package包/類
/**
 * 初試化
 * 
 * @throws SequenceException
 */
public void init() throws SequenceException {
    // 如果應用名為空,直接拋出
    if (StringUtils.isEmpty(appName)) {
        SequenceException sequenceException = new SequenceException("appName is Null ");
        logger.error("沒有配置appName", sequenceException);
        throw sequenceException;
    }
    if (dbGroupKeys == null || dbGroupKeys.size() == 0) {
        logger.error("沒有配置dbgroupKeys");
        throw new SequenceException("dbgroupKeys為空!");
    }

    dataSourceMap = new HashMap<String, DataSource>();
    for (String dbGroupKey : dbGroupKeys) {
        if (dbGroupKey.toUpperCase().endsWith("-OFF")) {
            continue;
        }
        // TGroupDataSource tGroupDataSource = new TGroupDataSource(
        // dbGroupKey, appName, dataSourceType);
        TGroupDataSource tGroupDataSource = new TGroupDataSource(dbGroupKey, appName);
        tGroupDataSource.init();
        dataSourceMap.put(dbGroupKey, tGroupDataSource);
    }
    if (dbGroupKeys.size() >= dscount) {
        dscount = dbGroupKeys.size();
    } else {
        for (int ii = dbGroupKeys.size(); ii < dscount; ii++) {
            dbGroupKeys.add(dscount + "-OFF");
        }
    }
    outStep = innerStep * dscount;// 計算外步長

    outputInitResult();
}
 
開發者ID:cpsing,項目名稱:tddl,代碼行數:40,代碼來源:GroupSequenceDao.java

示例11: getJT

import com.taobao.tddl.group.jdbc.TGroupDataSource; //導入方法依賴的package包/類
protected static JdbcTemplate getJT(String dbGroupKey) {
    tds = new TGroupDataSource();
    tds.setAppName(APPNAME);
    tds.setDbGroupKey(dbGroupKey);
    tds.init();
    return new JdbcTemplate(tds);
}
 
開發者ID:cpsing,項目名稱:tddl,代碼行數:8,代碼來源:GroupTestCase.java

示例12: setUpBeforeClass

import com.taobao.tddl.group.jdbc.TGroupDataSource; //導入方法依賴的package包/類
@BeforeClass
public static void setUpBeforeClass() throws Exception {
    tgds = new TGroupDataSource();
    tgds.setDbGroupKey("dbKey0");
    List<DataSourceWrapper> dataSourceWrappers = new ArrayList<DataSourceWrapper>();
    DataSourceWrapper dsw1 = new DataSourceWrapper("db1", "rw", db1, DBType.MYSQL);
    DataSourceWrapper dsw2 = new DataSourceWrapper("db2", "r", db2, DBType.MYSQL);
    dataSourceWrappers.add(dsw1);
    dataSourceWrappers.add(dsw2);
    tgds.init(dataSourceWrappers);
}
 
開發者ID:cpsing,項目名稱:tddl,代碼行數:12,代碼來源:TGroupStatementTest.java

示例13: setBeforeClass

import com.taobao.tddl.group.jdbc.TGroupDataSource; //導入方法依賴的package包/類
@BeforeClass
public static void setBeforeClass() {
    TGroupDataSource ds = new TGroupDataSource("tddl_sample_group_0", "tddl_sample");
    ds.init();
    dataSource = ds;
    jdbcTemplate = new JdbcTemplate(dataSource);
}
 
開發者ID:cpsing,項目名稱:tddl,代碼行數:8,代碼來源:ExchangeInTranslation.java

示例14: setUp

import com.taobao.tddl.group.jdbc.TGroupDataSource; //導入方法依賴的package包/類
@Before
public void setUp() throws Exception {
    s1 = new TGroupDataSource();
    s1.setAppName("TDDLSEQUENCE");
    s1.setDbGroupKey("TDDL_SEQUENCE_GROUP0");
    s1.init();

    s2 = new TGroupDataSource();
    s2.setAppName("TDDLSEQUENCE");
    s2.setDbGroupKey("TDDL_SEQUENCE_GROUP1");
    s2.init();

    dao = new UnitGroupSequenceDao();
    // 設置adjust為true,這樣不必關心怎麽樣去設置有規律的值。單元化部署必須設置這個值為true,切換的時候自動更新
    dao.setAdjust(true);
    dao.setAppName("TDDLSEQUENCE");
    List<String> dbGroups = new ArrayList<String>();
    dbGroups.add("TDDL_SEQUENCE_GROUP0");
    dbGroups.add("TDDL_SEQUENCE_GROUP1");
    dao.setDbGroupKeys(dbGroups);
    dao.setDscount(2);
    dao.setInnerStep(1000);
    // 設定切換時候的零時表
    dao.setSwitchTempTable("sequence_temp");

    // 測試時先將主sequence表值設置下,具體使用時可能是應用最大的sequence id
    this.updateNormalTable(0);

    testUnits = new HashSet<String>();
    testUnits.add("UNIT_CM3");
    testUnits.add("UNIT_XINGYI");
    testUnits.add("UNIT_DONGGUAN");
    testUnits.add("UNIT_CM9");
    currentUnit = "UNIT_CM9";

    // 設置測試參數
    RouterTestHelper.setTestData(testUnits, currentUnit, false);
    dao.init();

    // 有個名字叫ladygaga的sequence,自動初始化值
    GroupSequence s = new GroupSequence();
    s.setName("ladygaga");
    s.setSequenceDao(dao);
    s.init();
    sequence = s;
}
 
開發者ID:loye168,項目名稱:tddl5,代碼行數:47,代碼來源:UnitGroupSequenceExtendTest.java

示例15: setUp

import com.taobao.tddl.group.jdbc.TGroupDataSource; //導入方法依賴的package包/類
@Before
public void setUp() throws Exception {
    s1 = new TGroupDataSource();
    s1.setAppName("TDDLSEQUENCE");
    s1.setDbGroupKey("TDDL_SEQUENCE_GROUP0");
    s1.init();

    s2 = new TGroupDataSource();
    s2.setAppName("TDDLSEQUENCE");
    s2.setDbGroupKey("TDDL_SEQUENCE_GROUP1");
    s2.init();

    dao = new UnitGroupSequenceDao();
    // 設置adjust為true,這樣不必關心怎麽樣去設置有規律的值。單元化部署必須設置這個值為true,切換的時候自動更新
    dao.setAdjust(true);
    dao.setAppName("TDDLSEQUENCE");
    List<String> dbGroups = new ArrayList<String>();
    dbGroups.add("TDDL_SEQUENCE_GROUP0");
    dbGroups.add("TDDL_SEQUENCE_GROUP1");
    dao.setDbGroupKeys(dbGroups);
    dao.setDscount(2);
    dao.setInnerStep(1000);
    // 設定切換時候的零時表
    dao.setSwitchTempTable("sequence_temp");

    // 測試時先將主sequence表值設置下,具體使用時可能是應用最大的sequence id
    this.updateNormalTable(0);
    this.updateTestTable(testStart);

    testUnits = new HashSet<String>();
    testUnits.add("UNIT_CM3");
    testUnits.add("UNIT_XINGYI");
    testUnits.add("UNIT_DONGGUAN");
    testUnits.add("UNIT_CM9");
    currentUnit = "UNIT_CM9";

    // 設置測試參數
    RouterTestHelper.setTestData(testUnits, currentUnit, false);
    dao.init();

    // 有個名字叫ladygaga的sequence,自動初始化值
    GroupSequence s = new GroupSequence();
    s.setName("ladygaga");
    s.setSequenceDao(dao);
    s.init();
    sequence = s;
}
 
開發者ID:loye168,項目名稱:tddl5,代碼行數:48,代碼來源:PerfUnitGroupSequenceExtendTest.java


注:本文中的com.taobao.tddl.group.jdbc.TGroupDataSource.init方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。