Minor cleanup.

pull/180/head
Brett Wooldridge 10 years ago
parent f3f689e2dc
commit 28662ee045

@ -314,18 +314,18 @@ public final class HikariPool implements HikariPoolMBean, IBagStateListener
final int maxPoolSize = configuration.getMaximumPoolSize();
final int minIdle = configuration.getMinimumIdle();
while (!isShutdown && totalConnections.get() < maxPoolSize && (minIdle == 0 || getIdleConnections() < minIdle)) {
if (!addConnection()) {
if (addConnection()) {
if (minIdle == 0) {
break; // This break is here so we only add one connection when there is no min. idle
}
}
else {
if (minIdle == 0 && getThreadsAwaitingConnection() == 0) {
break;
}
quietlySleep(sleepBackoff);
sleepBackoff = Math.min(connectionTimeout / 2, (long) ((double) sleepBackoff * 1.5));
continue;
}
if (minIdle == 0) {
break; // This break is here so we only add one connection when there is no min. idle
}
}
}

@ -231,22 +231,21 @@ public final class PoolUtilities
*/
public static boolean isJdbc40Compliant(final Connection connection) throws SQLException
{
if (jdbc40checked) {
return IS_JDBC40;
}
try {
connection.isValid(5); // This will throw AbstractMethodError or SQLException in the case of a non-JDBC 41 compliant driver
IS_JDBC40 = true;
}
catch (AbstractMethodError e) {
IS_JDBC40 = false;
}
catch (SQLFeatureNotSupportedException e) {
IS_JDBC40 = false;
if (!jdbc40checked) {
jdbc40checked = true;
try {
connection.isValid(5); // This will throw AbstractMethodError or SQLException in the case of a non-JDBC 41 compliant driver
IS_JDBC40 = true;
}
catch (SQLFeatureNotSupportedException e) {
IS_JDBC40 = false;
}
catch (AbstractMethodError e) {
IS_JDBC40 = false;
}
}
jdbc40checked = true;
return IS_JDBC40;
}
@ -259,22 +258,21 @@ public final class PoolUtilities
*/
public static boolean isJdbc41Compliant(final Connection connection) throws SQLException
{
if (jdbc41checked) {
return IS_JDBC41;
}
if (!jdbc41checked) {
jdbc41checked = true;
try {
connection.getNetworkTimeout(); // This will throw AbstractMethodError or SQLException in the case of a non-JDBC 41 compliant driver
IS_JDBC41 = true;
}
catch (AbstractMethodError e) {
IS_JDBC41 = false;
}
catch (SQLFeatureNotSupportedException e) {
IS_JDBC41 = false;
try {
connection.getNetworkTimeout(); // This will throw AbstractMethodError or SQLException in the case of a non-JDBC 41 compliant driver
IS_JDBC41 = true;
}
catch (AbstractMethodError e) {
IS_JDBC41 = false;
}
catch (SQLFeatureNotSupportedException e) {
IS_JDBC41 = false;
}
}
jdbc41checked = true;
return IS_JDBC41;
}
@ -313,19 +311,18 @@ public final class PoolUtilities
*/
public static int setNetworkTimeout(final Executor executor, final Connection connection, final long timeoutMs, final boolean isUseNetworkTimeout) throws SQLException
{
if (!isUseNetworkTimeout) {
return 0;
if (isUseNetworkTimeout) {
try {
final int networkTimeout = connection.getNetworkTimeout();
connection.setNetworkTimeout(executor, (int) timeoutMs);
return networkTimeout;
}
catch (SQLFeatureNotSupportedException e) {
IS_JDBC41 = false;
}
}
try {
final int networkTimeout = connection.getNetworkTimeout();
connection.setNetworkTimeout(executor, (int) timeoutMs);
return networkTimeout;
}
catch (SQLFeatureNotSupportedException e) {
IS_JDBC41 = false;
return 0;
}
return 0;
}
/**

@ -308,18 +308,18 @@ public final class HikariPool implements HikariPoolMBean, IBagStateListener
final int maxPoolSize = configuration.getMaximumPoolSize();
final int minIdle = configuration.getMinimumIdle();
while (!isShutdown && totalConnections.get() < maxPoolSize && (minIdle == 0 || getIdleConnections() < minIdle)) {
if (!addConnection()) {
if (addConnection()) {
if (minIdle == 0) {
break; // This break is here so we only add one connection when there is no min. idle
}
}
else {
if (minIdle == 0 && getThreadsAwaitingConnection() == 0) {
break;
}
quietlySleep(sleepBackoff);
sleepBackoff = Math.min(connectionTimeout / 2, (long) ((double) sleepBackoff * 1.5));
continue;
}
if (minIdle == 0) {
break; // This break is here so we only add one connection when there is no min. idle
}
}
});

@ -213,19 +213,18 @@ public final class PoolUtilities
*/
public static boolean isJdbc40Compliant(final Connection connection) throws SQLException
{
if (jdbc40checked) {
return IS_JDBC40;
}
try {
connection.isValid(5); // This will throw AbstractMethodError or SQLException in the case of a non-JDBC 41 compliant driver
IS_JDBC40 = true;
}
catch (AbstractMethodError | SQLFeatureNotSupportedException e) {
IS_JDBC40 = false;
if (!jdbc40checked) {
jdbc40checked = true;
try {
connection.isValid(5); // This will throw AbstractMethodError or SQLException in the case of a non-JDBC 41 compliant driver
IS_JDBC40 = true;
}
catch (AbstractMethodError | SQLFeatureNotSupportedException e) {
IS_JDBC40 = false;
}
}
jdbc40checked = true;
return IS_JDBC40;
}
@ -238,19 +237,18 @@ public final class PoolUtilities
*/
public static boolean isJdbc41Compliant(final Connection connection) throws SQLException
{
if (jdbc41checked) {
return IS_JDBC41;
}
if (!jdbc41checked) {
jdbc41checked = true;
try {
connection.getNetworkTimeout(); // This will throw AbstractMethodError or SQLException in the case of a non-JDBC 41 compliant driver
IS_JDBC41 = true;
}
catch (AbstractMethodError | SQLFeatureNotSupportedException e) {
IS_JDBC41 = false;
try {
connection.getNetworkTimeout(); // This will throw AbstractMethodError or SQLException in the case of a non-JDBC 41 compliant driver
IS_JDBC41 = true;
}
catch (AbstractMethodError | SQLFeatureNotSupportedException e) {
IS_JDBC41 = false;
}
}
jdbc41checked = true;
return IS_JDBC41;
}
@ -286,19 +284,18 @@ public final class PoolUtilities
*/
public static int setNetworkTimeout(final Executor executor, final Connection connection, final long timeoutMs, final boolean isUseNetworkTimeout) throws SQLException
{
if (!isUseNetworkTimeout) {
return 0;
if (isUseNetworkTimeout) {
try {
final int networkTimeout = connection.getNetworkTimeout();
connection.setNetworkTimeout(executor, (int) timeoutMs);
return networkTimeout;
}
catch (SQLFeatureNotSupportedException e) {
IS_JDBC41 = false;
}
}
try {
final int networkTimeout = connection.getNetworkTimeout();
connection.setNetworkTimeout(executor, (int) timeoutMs);
return networkTimeout;
}
catch (SQLFeatureNotSupportedException e) {
IS_JDBC41 = false;
return 0;
}
return 0;
}
/**

Loading…
Cancel
Save