本文整理汇总了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();
}
示例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();
}
示例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;
}
示例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();
}
示例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");
}
}
示例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();
}
}
示例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();
}
示例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();
}
示例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();
}
示例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();
}
示例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());
}
}