本文整理汇总了Java中java.sql.Connection.hashCode方法的典型用法代码示例。如果您正苦于以下问题:Java Connection.hashCode方法的具体用法?Java Connection.hashCode怎么用?Java Connection.hashCode使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类java.sql.Connection
的用法示例。
在下文中一共展示了Connection.hashCode方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testBug63284
import java.sql.Connection; //导入方法依赖的package包/类
public void testBug63284() throws Exception {
Properties props = new Driver().parseURL(BaseTestCase.dbUrl, null);
props.setProperty("autoReconnect", "true");
props.setProperty("socketFactory", "testsuite.UnreliableSocketFactory");
Properties urlProps = new NonRegisteringDriver().parseURL(BaseTestCase.dbUrl, null);
String host = urlProps.getProperty(NonRegisteringDriver.HOST_PROPERTY_KEY);
String port = urlProps.getProperty(NonRegisteringDriver.PORT_PROPERTY_KEY);
props.remove(NonRegisteringDriver.HOST_PROPERTY_KEY);
props.remove(NonRegisteringDriver.NUM_HOSTS_PROPERTY_KEY);
props.remove(NonRegisteringDriver.HOST_PROPERTY_KEY + ".1");
props.remove(NonRegisteringDriver.PORT_PROPERTY_KEY + ".1");
props.setProperty("queriesBeforeRetryMaster", "50");
props.setProperty("maxReconnects", "1");
UnreliableSocketFactory.mapHost("master", host);
UnreliableSocketFactory.mapHost("slave", host);
Connection failoverConnection1 = null;
Connection failoverConnection2 = null;
try {
failoverConnection1 = getConnectionWithProps("jdbc:mysql://master:" + port + ",slave:" + port + "/", props);
failoverConnection2 = getConnectionWithProps("jdbc:mysql://master:" + port + ",slave:" + port + "/", props);
assertTrue(((com.mysql.jdbc.Connection) failoverConnection1).isMasterConnection());
// Two different Connection objects should not equal each other:
assertFalse(failoverConnection1.equals(failoverConnection2));
int hc = failoverConnection1.hashCode();
UnreliableSocketFactory.downHost("master");
for (int i = 0; i < 3; i++) {
try {
failoverConnection1.createStatement().execute("SELECT 1");
} catch (SQLException e) {
// do nothing, expect SQLException when failing over initially goal here is to ensure valid connection against a slave
}
}
// ensure we're now connected to the slave
assertFalse(((com.mysql.jdbc.Connection) failoverConnection1).isMasterConnection());
// ensure that hashCode() result is persistent across failover events when proxy state changes
assertEquals(hc, failoverConnection1.hashCode());
} finally {
if (failoverConnection1 != null) {
failoverConnection1.close();
}
if (failoverConnection2 != null) {
failoverConnection2.close();
}
}
}