• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Java FabricMySQLConnection类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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

示例1: testBug73070

import com.mysql.fabric.jdbc.FabricMySQLConnection; //导入依赖的package包/类
/**
 * Test for Bug#73070 - prepareCall() throws NPE
 * 
 * To test this, we create a basic stored procedure with a
 * parameter, call it and check the result.
 */
public void testBug73070() throws Exception {
    if (!this.isSetForFabricTest) {
        return;
    }
    this.conn = (FabricMySQLConnection) getNewDefaultDataSource().getConnection(this.username, this.password);
    this.conn.setServerGroupName("fabric_test1_global");

    this.conn.createStatement().executeUpdate("drop procedure if exists bug73070");
    this.conn.createStatement().executeUpdate("create procedure bug73070(in x integer) select x");
    CallableStatement stmt = this.conn.prepareCall("{call bug73070(?)}");
    stmt.setInt(1, 42);
    ResultSet rs = stmt.executeQuery();
    rs.next();
    assertEquals(42, rs.getInt(1));
    rs.close();
    stmt.close();
    this.conn.createStatement().executeUpdate("drop procedure bug73070");

    this.conn.close();
}
 
开发者ID:bragex,项目名称:the-vigilantes,代码行数:27,代码来源:TestRegressions.java


示例2: testBug77217

import com.mysql.fabric.jdbc.FabricMySQLConnection; //导入依赖的package包/类
/**
 * Test Bug#77217 - ClassCastException when executing a PreparedStatement with Fabric (using a streaming result with timeout set)
 */
public void testBug77217() throws Exception {
    if (!this.isSetForFabricTest) {
        return;
    }

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

    PreparedStatement ps = this.conn.prepareStatement("select ? from dual");
    ps.setFetchSize(Integer.MIN_VALUE);
    ps.setString(1, "abc");
    ResultSet rs = ps.executeQuery();
    rs.next();
    assertEquals("abc", rs.getString(1));
    rs.close();
    ps.close();
    this.conn.close();
}
 
开发者ID:bragex,项目名称:the-vigilantes,代码行数:22,代码来源:TestRegressions.java


示例3: getConnection

import com.mysql.fabric.jdbc.FabricMySQLConnection; //导入依赖的package包/类
@Override
protected Connection getConnection(Properties arg0) throws SQLException {
	long time0 = System.currentTimeMillis();
	Connection rawConnection = super.getConnection(arg0);
	FabricMySQLConnection connection = (FabricMySQLConnection) rawConnection;
	log.debug("Creating new connection: " + connection);
	long time1 = System.currentTimeMillis();
	if (initRequired.get() != null) {
		log.debug("Initializing connection");
		try {
			this.connectionInitialization.get().apply(connection);
		} finally {
			this.clearInitOps();
		}
	}
	log.debug("It took " + (time1 - time0) + "ms to create connection and " + (System.currentTimeMillis() - time1)
			+ "ms to initialize.");
	return connection;
}
 
开发者ID:NewTranx,项目名称:newtranx-utils,代码行数:20,代码来源:FabricMySQLDataSourceEx.java


示例4: testBug73070

import com.mysql.fabric.jdbc.FabricMySQLConnection; //导入依赖的package包/类
/**
 * Test for Bug#73070 - prepareCall() throws NPE
 * 
 * To test this, we create a basic stored procedure with a
 * parameter, call it and check the result.
 */
public void testBug73070() throws Exception {
    this.conn = (FabricMySQLConnection) getNewDefaultDataSource().getConnection(this.username, this.password);
    this.conn.setServerGroupName("fabric_test1_global");

    this.conn.createStatement().executeUpdate("drop procedure if exists bug73070");
    this.conn.createStatement().executeUpdate("create procedure bug73070(in x integer) select x");
    CallableStatement stmt = this.conn.prepareCall("{call bug73070(?)}");
    stmt.setInt(1, 42);
    ResultSet rs = stmt.executeQuery();
    rs.next();
    assertEquals(42, rs.getInt(1));
    rs.close();
    stmt.close();
    this.conn.createStatement().executeUpdate("drop procedure bug73070");

    this.conn.close();
}
 
开发者ID:Prometheus-ETSIIT,项目名称:locaviewer,代码行数:24,代码来源:TestRegressions.java


示例5: setUp

import com.mysql.fabric.jdbc.FabricMySQLConnection; //导入依赖的package包/类
@Override
public void setUp() throws Exception {
    if (this.isSetForFabricTest) {
        this.conn = (FabricMySQLConnection) this.ds.getConnection(this.username, this.password);
        this.conn.setServerGroupName("ha_config1_group");
    }
}
 
开发者ID:bragex,项目名称:the-vigilantes,代码行数:8,代码来源:TestHABasics.java


示例6: setUp

import com.mysql.fabric.jdbc.FabricMySQLConnection; //导入依赖的package包/类
@Override
public void setUp() throws Exception {
    if (this.isSetForFabricTest) {
        this.conn = (FabricMySQLConnection) this.ds.getConnection(this.username, this.password);

        // create table globally
        this.conn.setServerGroupName("fabric_test1_global");
        Statement stmt = this.conn.createStatement();
        stmt.executeUpdate("drop table if exists employees");
        stmt.executeUpdate("create table employees (emp_no INT PRIMARY KEY, first_name CHAR(40), last_name CHAR(40))");
        this.conn.clearServerSelectionCriteria();
    }
}
 
开发者ID:bragex,项目名称:the-vigilantes,代码行数:14,代码来源:TestHashSharding.java


示例7: testBug21876798

import com.mysql.fabric.jdbc.FabricMySQLConnection; //导入依赖的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


示例8: manualTestRefreshFabricStateCache

import com.mysql.fabric.jdbc.FabricMySQLConnection; //导入依赖的package包/类
/**
 * Test Bug#21296840 - CONNECTION DATA IS NOT UPDATED DURING FAILOVER.
 * Test Bug#17910835 - SERVER INFORMATION FROM FABRIC NOT REFRESHED WITH SHORTER TTL.
 * 
 * Test that the local cache is refreshed after expired TTL. This test connects to the master of "ha_config1_group" and requires the master to be changed
 * manually during the wait period. The Fabric must also be setup to communicate a TTL of less than 10s to the client.
 */
public void manualTestRefreshFabricStateCache() throws Exception {
    if (!this.isSetForFabricTest) {
        return;
    }

    this.conn = (FabricMySQLConnection) getNewDefaultDataSource().getConnection(this.username, this.password);
    this.conn.setServerGroupName("ha_config1_group");
    this.conn.setReadOnly(false);
    this.conn.setAutoCommit(false);

    Statement stmt = this.conn.createStatement();

    ResultSet rs = stmt.executeQuery("show variables like 'server_uuid'");
    rs.next();
    String firstServerUuid = rs.getString(2);
    rs.close();
    this.conn.commit();

    // sleep for TTL+1 secs
    int seconds = 10;
    System.err.println("Waiting " + seconds + " seconds for new master to be chosen");
    Thread.sleep(TimeUnit.SECONDS.toMillis(1 + seconds));

    // force the LB proxy to pick a new connection
    this.conn.rollback();

    // verify change is seen by client
    rs = stmt.executeQuery("show variables like 'server_uuid'");
    rs.next();
    String secondServerUuid = rs.getString(2);
    rs.close();

    System.err.println("firstServerUuid=" + firstServerUuid + "\nsecondServerUuid=" + secondServerUuid);
    if (firstServerUuid.equals(secondServerUuid)) {
        fail("Server ID should change to reflect new topology");
    }

    this.conn.close();
}
 
开发者ID:bragex,项目名称:the-vigilantes,代码行数:47,代码来源:TestRegressions.java


示例9: testBug82094

import com.mysql.fabric.jdbc.FabricMySQLConnection; //导入依赖的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


示例10: setQueryTables

import com.mysql.fabric.jdbc.FabricMySQLConnection; //导入依赖的package包/类
@Around("@annotation(com.newtranx.util.mysql.fabric.QueryTables)")
public Object setQueryTables(ProceedingJoinPoint pjp) throws Throwable {
	try {
		Method method = AspectJUtils.getMethod(pjp);
		QueryTables qtAnnotation = method.getAnnotation(QueryTables.class);
		FabricMySQLConnection connection = (FabricMySQLConnection) sqlSession.getConnection();
		if ((connection.getQueryTables().isEmpty() && connection.getShardTable() == null) || qtAnnotation.reset()) {
			connection.clearServerSelectionCriteria();
			String[] tables = qtAnnotation.value();
			log.debug("Setting queryTables=" + Arrays.toString(tables));
			log.debug("Thread=" + Thread.currentThread() + ", conn=" + connection);
			if (qtAnnotation.useFirst()) {
				log.debug("Use setShardTable with first query table instead");
				connection.setShardTable(tables[0]);
				log.debug("New shardTable set");
			} else {
				for (String table : tables)
					connection.addQueryTable(table);
				log.debug("New queryTables set");
			}
		} else {
			log.debug("Keep original queryTables");
		}
		log.debug("QueryTables=" + connection.getQueryTables() + ", shardTable=" + connection.getShardTable());
	} catch (Exception e) {
		e.printStackTrace(System.err);
		throw e;
	}
	return pjp.proceed();
}
 
开发者ID:NewTranx,项目名称:newtranx-utils,代码行数:31,代码来源:SpringMybatisSetQueryTablesAspect.java


示例11: setShardKey

import com.mysql.fabric.jdbc.FabricMySQLConnection; //导入依赖的package包/类
@Override
public void setShardKey(String shardKey, boolean force) throws SQLException {
	FabricMySQLConnection connection = (FabricMySQLConnection) sqlSession.getConnection();
	if (StringUtils.isEmpty(connection.getShardKey()) || force) {
		connection.setShardKey(shardKey);
		log.debug("New shardKey set");
		log.debug("ShardKey=" + shardKey);
		log.debug("CurrentServerGroup=" + connection.getCurrentServerGroup());
	} else {
		log.debug("Keep original shardKey");
		log.debug("ShardKey=" + connection.getShardKey());
	}
}
 
开发者ID:NewTranx,项目名称:newtranx-utils,代码行数:14,代码来源:SpringMybatisSetShardKeyUtilImpl.java



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java TScan类代码示例发布时间:2022-05-21
下一篇:
Java BluetoothStateException类代码示例发布时间:2022-05-21
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap