本文整理匯總了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();
}
}
}