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


Java FabricMySQLDataSource.getConnection方法代码示例

本文整理汇总了Java中com.mysql.fabric.jdbc.FabricMySQLDataSource.getConnection方法的典型用法代码示例。如果您正苦于以下问题:Java FabricMySQLDataSource.getConnection方法的具体用法?Java FabricMySQLDataSource.getConnection怎么用?Java FabricMySQLDataSource.getConnection使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在com.mysql.fabric.jdbc.FabricMySQLDataSource的用法示例。


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

示例1: testConnectionDataSource

import com.mysql.fabric.jdbc.FabricMySQLDataSource; //导入方法依赖的package包/类
/**
 * Test that we can connect with the data source, given a server group name
 */
public void testConnectionDataSource() throws Exception {
    if (!this.isSetForFabricTest) {
        return;
    }
    FabricMySQLDataSource ds = getNewDefaultDataSource();
    ds.setFabricServerGroup("fabric_test1_global");
    Connection c = ds.getConnection(this.username, this.password);
    // same as above
    ResultSet rs = c.createStatement().executeQuery("select user()");
    rs.next();
    String userFromDb = rs.getString(1).split("@")[0];
    assertEquals(this.username, userFromDb);
    rs.close();
    c.close();
}
 
开发者ID:bragex,项目名称:the-vigilantes,代码行数:19,代码来源:TestBasicConnection.java

示例2: testBug21876798

import com.mysql.fabric.jdbc.FabricMySQLDataSource; //导入方法依赖的package包/类
public void testBug21876798() throws Exception {
    if (!this.isSetForFabricTest) {
        return;
    }

    FabricMySQLDataSource ds = getNewDefaultDataSource();
    ds.setRewriteBatchedStatements(true);

    this.conn = (FabricMySQLConnection) ds.getConnection(this.username, this.password);
    this.conn.setServerGroupName("ha_config1_group");

    this.conn.createStatement().executeUpdate("drop table if exists bug21876798");
    this.conn.createStatement().executeUpdate("create table bug21876798(x varchar(100))");
    PreparedStatement ps = this.conn.prepareStatement("update bug21876798 set x = ?");
    ps.setString(1, "abc");
    ps.addBatch();
    ps.setString(1, "def");
    ps.addBatch();
    ps.setString(1, "def");
    ps.addBatch();
    ps.setString(1, "def");
    ps.addBatch();
    ps.setString(1, "def");
    ps.addBatch();
    // this would throw a ClassCastException
    ps.executeBatch();
}
 
开发者ID:bragex,项目名称:the-vigilantes,代码行数:28,代码来源:TestRegressions.java

示例3: testBug82094

import com.mysql.fabric.jdbc.FabricMySQLDataSource; //导入方法依赖的package包/类
/**
 * Test Bug#82094 - ConcurrentModificationException on Fabric connections after topology changes.
 * 
 * This test requires a Fabric instance running with a HA group (ha_config1_group) containing three servers, one promoted to master and failure detection
 * turned on.
 * Note that removing one or the other secondary server is a distinct case and only one of them causes the reported failure. This is so because of the order
 * the elements on the slave servers HashSet, from the ReplicationConnectionGroup object, are iterated. So, we remove one at a time in this test to make
 * sure we cover both cases.
 */
public void testBug82094() throws Exception {
    if (!this.isSetForFabricTest) {
        return;
    }

    FabricMySQLDataSource ds = getNewDefaultDataSource();
    ds.setFabricServerGroup("ha_config1_group");
    this.conn = (FabricMySQLConnection) ds.getConnection(this.username, this.password);
    this.conn.createStatement().close(); // Make sure there is an internal ReplicationConnection.

    FabricConnection fabricConn = new FabricConnection(this.fabricUrl, this.fabricUsername, this.fabricPassword);

    for (Server server : fabricConn.getServerGroup("ha_config1_group").getServers()) {
        if (server.isSlave()) {
            try {
                this.conn.transactionCompleted();

                // Remove Secondary server.
                fabricConn.getClient().removeServerFromGroup(server.getGroupName(), server.getHostname(), server.getPort());
                // Make sure the TTL expires before moving on.
                fabricConn.refreshState();
                while (!fabricConn.isStateExpired()) {
                    Thread.sleep(1000);
                }

                this.conn.transactionCompleted();
            } finally {
                // Add Secondary server back.
                fabricConn.getClient().addServerToGroup(server.getGroupName(), server.getHostname(), server.getPort());
                // Make sure the TTL expires before moving on.
                fabricConn.refreshState();
                while (!fabricConn.isStateExpired()) {
                    Thread.sleep(1000);
                }
            }
        }
    }
    this.conn.close();
}
 
开发者ID:bragex,项目名称:the-vigilantes,代码行数:49,代码来源:TestRegressions.java

示例4: testConnectionDataSource

import com.mysql.fabric.jdbc.FabricMySQLDataSource; //导入方法依赖的package包/类
/**
 * Test that we can connect with the data source, given a server group name
 */
public void testConnectionDataSource() throws Exception {
	FabricMySQLDataSource ds = getNewDefaultDataSource();
	ds.setFabricServerGroup("fabric_test1_global");
	Connection c = ds.getConnection(this.username, this.password);
	// same as above
	ResultSet rs = c.createStatement().executeQuery("select user()");
	rs.next();
	String userFromDb = rs.getString(1).split("@")[0];
	assertEquals(this.username, userFromDb);
	rs.close();
	c.close();
}
 
开发者ID:hinsenchan,项目名称:fil_project_mgmt_app_v2,代码行数:16,代码来源:TestBasicConnection.java

示例5: testConnectionDataSource

import com.mysql.fabric.jdbc.FabricMySQLDataSource; //导入方法依赖的package包/类
/**
 * Test that we can connect with the data source, given a server group name
 */
public void testConnectionDataSource() throws Exception {
    FabricMySQLDataSource ds = getNewDefaultDataSource();
    ds.setFabricServerGroup("fabric_test1_global");
    Connection c = ds.getConnection(this.username, this.password);
    // same as above
    ResultSet rs = c.createStatement().executeQuery("select user()");
    rs.next();
    String userFromDb = rs.getString(1).split("@")[0];
    assertEquals(this.username, userFromDb);
    rs.close();
    c.close();
}
 
开发者ID:Prometheus-ETSIIT,项目名称:locaviewer,代码行数:16,代码来源:TestBasicConnection.java


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