本文整理汇总了Java中com.taobao.tddl.matrix.jdbc.TDataSource.getConnection方法的典型用法代码示例。如果您正苦于以下问题:Java TDataSource.getConnection方法的具体用法?Java TDataSource.getConnection怎么用?Java TDataSource.getConnection使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.taobao.tddl.matrix.jdbc.TDataSource
的用法示例。
在下文中一共展示了TDataSource.getConnection方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: initTestWithDS
import com.taobao.tddl.matrix.jdbc.TDataSource; //导入方法依赖的package包/类
@Test
public void initTestWithDS() throws TddlException, SQLException {
TDataSource ds = new TDataSource();
ds.setAppName("andor_show");
ds.setTopologyFile("test_matrix.xml");
ds.setSchemaFile("test_schema.xml");
ds.init();
Connection conn = ds.getConnection();
PreparedStatement ps = conn.prepareStatement("select * from bmw_users limit 10");
ResultSet rs = ps.executeQuery();
Assert.assertTrue(rs.next());
rs.close();
ps.close();
conn.close();
}
示例2: testTraceId
import com.taobao.tddl.matrix.jdbc.TDataSource; //导入方法依赖的package包/类
public static void testTraceId(TDataSource ds) throws TddlException, SQLException {
// insert a record
Connection conn = ds.getConnection();
String sql = " /* ANDOR ALLOW_TEMPORARY_TABLE=True */ select traceid,tracetime,span1 from eaglelog "
+ "where tracetime>=? and tracetime<=? and rootAppName=? group by traceid,tracetime,span1 "
+ "order by tracetime desc limit 15";
PreparedStatement ps = conn.prepareStatement(sql);
ps.setObject(1, 1399514386000L);
ps.setObject(2, 1399514686000L);
ps.setObject(3, "cybertron:default-ide-projectid");
// select all records
long start = System.currentTimeMillis();
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");
System.out.println(System.currentTimeMillis() - start);
}
示例3: testJaeTraceId
import com.taobao.tddl.matrix.jdbc.TDataSource; //导入方法依赖的package包/类
public static void testJaeTraceId(TDataSource ds) throws SQLException {
Connection conn = ds.getConnection();
// insert a record
String sql = "/* ANDOR ALLOW_TEMPORARY_TABLE=True */ select jaelog1.traceid,jaelog1.tracetime,max(jaelog2.span1),jaelog1.groupToken,jaelog2.result from";
sql += " jaelog jaelog1 left join jaelog jaelog2 on jaelog1.traceid=jaelog2.traceid and jaelog2.tracetime>= ? and jaelog2.tracetime<= ? and jaelog2.rpcType=253 where jaelog1.tracetime>= ? and jaelog1.tracetime<= ? ";
sql += "and jaelog1.rpcType!=253 and jaelog1.groupToken=? group by jaelog1.traceid,jaelog1.groupToken,jaelog2.result limit 20";
PreparedStatement ps = conn.prepareStatement(sql);
// ps.setString(1, "2a784acf13946236294728641e");
ps.setLong(1, 1394553600000L);
ps.setLong(2, 1394630000000L);
ps.setLong(3, 1394553600000L);
ps.setLong(4, 1394630000000L);
ps.setString(5, "3229$$$");
// select all records
long start = System.currentTimeMillis();
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");
System.out.println(System.currentTimeMillis() - start);
}
示例4: main
import com.taobao.tddl.matrix.jdbc.TDataSource; //导入方法依赖的package包/类
public static void main(String[] args) throws TddlException, SQLException {
TDataSource ds = new TDataSource();
// init a datasource with dynamic config on diamond
ds.setAppName("XIAMI_WEB_ATHENA");
Map cp = new HashMap();
cp.put(ConnectionProperties.ALLOW_TEMPORARY_TABLE, "true");
// cp.put(ConnectionProperties.MERGE_CONCURRENT, "true");
ds.setConnectionProperties(cp);
ds.init();
System.out.println("init done");
Connection conn = ds.getConnection();
// select all records
PreparedStatement ps = conn.prepareStatement("select user_id,num from (SELECT user_id, count(*) AS num FROM receive_flowers GROUP BY user_id having num >= 100) t ORDER BY num desc");
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");
}
示例5: main
import com.taobao.tddl.matrix.jdbc.TDataSource; //导入方法依赖的package包/类
public static void main(String[] args) throws TddlException, SQLException {
TDataSource ds = new TDataSource();
// init a datasource with dynamic config on diamond
ds.setAppName("INTL_COMM_DEV_APP");
ds.init();
System.out.println("init done");
Connection conn = ds.getConnection();
// select all records
PreparedStatement ps = conn.prepareStatement("SELECT * from ae_macro_daily_target a left join ae_macro_daily_target_value b on a.target_id=b.target_id where a.type=? and b.stat_date=? order by a.target_id desc");
ps.setObject(1, "'ae_byr'");
ps.setObject(2, "2013-12-11");
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");
}
示例6: testClient
import com.taobao.tddl.matrix.jdbc.TDataSource; //导入方法依赖的package包/类
public static void testClient(TDataSource ds) throws TddlException, SQLException {
// insert a record
Connection conn = ds.getConnection();
String sql = "select * from client_test " + "where trace_time>=? and trace_time<=? limit 10";
PreparedStatement ps = conn.prepareStatement(sql);
ps.setObject(1, "2014-06-23 00:00:00");
ps.setObject(2, "2014-06-23 23:59:59");
// select all records
long start = System.currentTimeMillis();
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");
System.out.println(System.currentTimeMillis() - start);
}
示例7: main
import com.taobao.tddl.matrix.jdbc.TDataSource; //导入方法依赖的package包/类
public static void main(String[] args) throws TddlException, SQLException, FileNotFoundException {
Log4jConfigurer.initLogging("src/main/resources/log4j.properties");
TDataSource ds = new TDataSource();
// 设置默认db(ob)
ds.setAppName("DEV_DPS_APP");
ds.setTopologyFile("tddl-topology-dps.xml");
ds.setRuleFile("tddl-rule-dps-nonmysql.xml");
// 设置simba2的mysql
App subApp = new App();
subApp.setAppName("DAILY_SOLAR_MERCURY_APP");
subApp.setRuleFile("tddl-rule-dps-simba2-mysql.xml");
ds.addSubApp(subApp);
// 添加subway的mysql
subApp = new App();
subApp.setAppName("DEV_SUBWAY_MYSQL");
subApp.setRuleFile("tddl-rule-dps-subway-mysql.xml");
ds.addSubApp(subApp);
Map cp = new HashMap();
cp.put("ALLOW_TEMPORARY_TABLE", "True");
cp.put(ConnectionProperties.TEMP_TABLE_DIR, ".\\temp\\");
cp.put(ConnectionProperties.TEMP_TABLE_CUT_ROWS, false);
cp.put(ConnectionProperties.TEMP_TABLE_MAX_ROWS, 1000);
ds.setConnectionProperties(cp);
ds.init();
System.out.println("init done");
// subway_adgroup_list.sql
// solar_adgroup_list.sql
String sql = SqlFileUtil.getSql("replace.txt");
// sql = SqlFileUtil.getSql("solar_adgroup_list.sql");
Connection conn = ds.getConnection();
{
PreparedStatement ps = conn.prepareStatement(sql);
long start = System.currentTimeMillis();
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());
}
System.out.println("done " + (System.currentTimeMillis() - start));
rs.close();
ps.close();
}
conn.close();
}
示例8: getConnection
import com.taobao.tddl.matrix.jdbc.TDataSource; //导入方法依赖的package包/类
private TConnection getConnection(SchemaConfig schema) throws TddlException, SQLException {
if (this.conn == null) {
synchronized (this) {
if (this.conn == null) {// double-check
TDataSource ds = schema.getDataSource();
if (!ds.isInited()) {
ds.init();
}
this.conn = ds.getConnection();
if (txIsolation >= 0) {
this.conn.setTransactionIsolation(txIsolation);
}
if (!autocommit) {
this.conn.setAutoCommit(autocommit);
}
if (sqlMode != null) {
this.conn.setSqlMode(sqlMode);
}
if (charset != null) {
this.conn.setEncoding(charset);
}
if (this.trxPolicy != null) {
this.conn.setTrxPolicy(this.trxPolicy);
}
}
}
}
return this.conn;
}
示例9: main
import com.taobao.tddl.matrix.jdbc.TDataSource; //导入方法依赖的package包/类
public static void main(String[] args) throws TddlException, SQLException {
TDataSource ds = new TDataSource();
// init a datasource with dynamic config on diamond
ds.setAppName("ACSS_BILL_APP");
ds.init();
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 bill_detail BILL_DETAIL limit 100,200");
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");
}
示例10: main
import com.taobao.tddl.matrix.jdbc.TDataSource; //导入方法依赖的package包/类
public static void main(String[] args) throws TddlException, SQLException {
TDataSource ds = new TDataSource();
// init a datasource with dynamic config on diamond
ds.setAppName("CREDITCTRL_APP");
Map cp = new HashMap();
// cp.put(ConnectionProperties.MERGE_CONCURRENT, "false");
ds.setConnectionProperties(cp);
ds.init();
System.out.println("init done");
Connection conn = ds.getConnection();
System.out.println("insert done");
// select all records
PreparedStatement ps = conn.prepareStatement("SELECT * from SYS_LOG");
// PreparedStatement ps =
// conn.prepareStatement("SELECT device_id from bullet_dt_device_content limit 10");
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");
}
示例11: main
import com.taobao.tddl.matrix.jdbc.TDataSource; //导入方法依赖的package包/类
public static void main(String[] args) throws TddlException, SQLException {
TDataSource ds = new TDataSource();
// init a datasource with local config file
ds.setAppName("tddl5_sample");
ds.setRuleFile("classpath:sample_rule.xml");
ds.setTopologyFile("sample_topology.xml");
ds.setSchemaFile("test_schema.xml");
ds.init();
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");
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");
}
示例12: main
import com.taobao.tddl.matrix.jdbc.TDataSource; //导入方法依赖的package包/类
public static void main(String[] args) throws TddlException, SQLException {
TDataSource ds = new TDataSource();
// init a datasource with dynamic config on diamond
ds.setAppName("tddl5_sample");
ds.init();
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("/*+TDDL({\"type\":\"direct\",\"realtabs\":[traa],\"dbid\":\"tddl5_sample_group\",\"vtab\":\"sample_table\"})*/ SELECT * from sample_table");
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");
}
示例13: main
import com.taobao.tddl.matrix.jdbc.TDataSource; //导入方法依赖的package包/类
public static void main(String[] args) throws TddlException, SQLException {
TDataSource ds = new TDataSource();
// init a datasource with local config file
ds.setAppName("tddl5_sample");
ds.setRuleFile("classpath:sample_rule.xml");
ds.setTopologyFile("sample_topology.xml");
ds.setSchemaFile("demo_repo_schema.xml");
ds.init();
System.out.println("init done");
Connection conn = ds.getConnection();
// insert a record
conn.prepareStatement("replace into _tddl_ (id,name) values (1,'sun1')").executeUpdate();
conn.prepareStatement("replace into _tddl_ (id,name) values (2,'sun1')").executeUpdate();
conn.prepareStatement("replace into _tddl_ (id,name) values (3,'sun1')").executeUpdate();
conn.prepareStatement("replace into _tddl_ (id,name) values (4,'sun2')").executeUpdate();
conn.prepareStatement("replace into _tddl_ (id,name) values (5,'sun2')").executeUpdate();
System.out.println("insert done");
// select all records
PreparedStatement ps = conn.prepareStatement("SELECT id from _tddl_ order by id");
// PreparedStatement ps =
// conn.prepareStatement("SELECT * from _tddl_ t1 join _tddl_ t2 where t1.name=t2.name and t2.name='sun1' and t1.id=1");
// PreparedStatement ps =
// conn.prepareStatement("SELECT * from _tddl_ t1 where name='sun'");
// PreparedStatement ps =
// conn.prepareStatement("SELECT count(*)+1 from _tddl_ t1 where t1.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");
}
示例14: main
import com.taobao.tddl.matrix.jdbc.TDataSource; //导入方法依赖的package包/类
public static void main(String[] args) throws TddlException, SQLException {
TDataSource ds = new TDataSource();
// init a datasource with dynamic config on diamond
ds.setAppName("BULLET_APP");
ds.setRuleFile("xuezhu.xml");
ds.init();
System.out.println("init done");
Connection conn = ds.getConnection();
System.out.println("insert done");
// select all records
PreparedStatement ps = conn.prepareStatement("SELECT sum(TO_SECONDS(end_time)-TO_SECONDS(start_time)) as totalTime from bullet_dt_device_content where device_id>0 LIMIT 10");
// PreparedStatement ps =
// conn.prepareStatement("SELECT device_id from bullet_dt_device_content limit 10");
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");
}