Search in sources :

Example 1 with YamlShardingDataSource

use of com.dangdang.ddframe.rdb.sharding.config.yaml.api.YamlShardingDataSource in project sharding-jdbc by dangdangdotcom.

the class YamlWithDefaultDataSourceMain method main.

// CHECKSTYLE:OFF
public static void main(final String[] args) throws Exception {
    // CHECKSTYLE:ON
    YamlShardingDataSource dataSource = new YamlShardingDataSource(new File(YamlWithDefaultDataSourceMain.class.getResource("/META-INF/withDefaultDataSource.yaml").getFile()));
    printJoinSelect(dataSource);
    printGroupBy(dataSource);
}
Also used : YamlShardingDataSource(com.dangdang.ddframe.rdb.sharding.config.yaml.api.YamlShardingDataSource) File(java.io.File)

Example 2 with YamlShardingDataSource

use of com.dangdang.ddframe.rdb.sharding.config.yaml.api.YamlShardingDataSource in project sharding-jdbc by dangdangdotcom.

the class YamlIntegratedTest method testWithDataSource.

@Test
public void testWithDataSource() throws SQLException, URISyntaxException, IOException {
    File yamlFile = new File(YamlIntegratedTest.class.getResource(filePath).toURI());
    DataSource dataSource;
    if (hasDataSource) {
        dataSource = new YamlShardingDataSource(yamlFile);
    } else {
        dataSource = new YamlShardingDataSource(Maps.asMap(Sets.newHashSet("db0", "db1"), new Function<String, DataSource>() {

            @Override
            public DataSource apply(final String key) {
                return createDataSource(key);
            }
        }), yamlFile);
    }
    try (Connection conn = dataSource.getConnection();
        Statement stm = conn.createStatement()) {
        stm.executeQuery("SELECT * FROM t_order");
        stm.executeQuery("SELECT * FROM t_order_item");
        stm.executeQuery("SELECT * FROM config");
    }
}
Also used : Statement(java.sql.Statement) YamlShardingDataSource(com.dangdang.ddframe.rdb.sharding.config.yaml.api.YamlShardingDataSource) Connection(java.sql.Connection) File(java.io.File) YamlShardingDataSource(com.dangdang.ddframe.rdb.sharding.config.yaml.api.YamlShardingDataSource) DataSource(javax.sql.DataSource) Test(org.junit.Test)

Example 3 with YamlShardingDataSource

use of com.dangdang.ddframe.rdb.sharding.config.yaml.api.YamlShardingDataSource in project sharding-jdbc by dangdangdotcom.

the class YamlWithAssignedDataSourceMain method main.

// CHECKSTYLE:OFF
public static void main(final String[] args) throws Exception {
    // CHECKSTYLE:ON
    YamlShardingDataSource dataSource = new YamlShardingDataSource(new File(YamlWithAssignedDataSourceMain.class.getResource("/META-INF/withAssignedDataSource.yaml").getFile()));
    printSimpleSelect(dataSource);
    printJoinSelect(dataSource);
    printGroupBy(dataSource);
}
Also used : YamlShardingDataSource(com.dangdang.ddframe.rdb.sharding.config.yaml.api.YamlShardingDataSource) File(java.io.File)

Aggregations

YamlShardingDataSource (com.dangdang.ddframe.rdb.sharding.config.yaml.api.YamlShardingDataSource)3 File (java.io.File)3 Connection (java.sql.Connection)1 Statement (java.sql.Statement)1 DataSource (javax.sql.DataSource)1 Test (org.junit.Test)1