diff --git a/pom.xml b/pom.xml
index fe4c4ccb7e..11bbd127e1 100644
--- a/pom.xml
+++ b/pom.xml
@@ -251,8 +251,15 @@
3.8.0
+ **/com/microsoft/sqlserver/jdbc/ISQLServerConnection43.java
+ **/com/microsoft/sqlserver/jdbc/SQLServerConnection43.java
**/com/microsoft/sqlserver/jdbc/SQLServerJdbc43.java
+
+ **/com/microsoft/sqlserver/jdbc/connection/ConnectionWrapper43Test.java
+ **/com/microsoft/sqlserver/jdbc/connection/RequestBoundaryMethodsTest.java
+ **/com/microsoft/sqlserver/jdbc/JDBC43Test.java
+
1.8
diff --git a/src/main/java/com/microsoft/sqlserver/jdbc/SQLServerConnection.java b/src/main/java/com/microsoft/sqlserver/jdbc/SQLServerConnection.java
index da4731e7ae..e7194af6b8 100644
--- a/src/main/java/com/microsoft/sqlserver/jdbc/SQLServerConnection.java
+++ b/src/main/java/com/microsoft/sqlserver/jdbc/SQLServerConnection.java
@@ -1216,21 +1216,6 @@ final SQLCollation getDatabaseCollation() {
.getLogger("com.microsoft.sqlserver.jdbc.Connection");
private static String loggingClassName = "com.microsoft.sqlserver.jdbc.SQLServerConnection:";
- /** Client process ID sent during login */
- private static int pid = 0;
-
- static {
- long pidLong = 0;
- try {
- pidLong = ProcessHandle.current().pid();
- } catch (NoClassDefFoundError e) { // ProcessHandle is Java 9+
- if (loggerExternal.isLoggable(Level.FINER) && Util.isActivityTraceOn()) {
- loggerExternal.finer(loggingClassName + " NoClassDefFoundError for ProcessHandle. ProcessId will be 0.");
- }
- }
- pid = (pidLong > Integer.MAX_VALUE) ? 0 : (int)pidLong;
- }
-
/**
* There are three ways to get a failover partner connection string, from the failover map, the connecting server
* returned the following variable only stores the serverReturned failver information.
@@ -5379,7 +5364,7 @@ final boolean complete(LogonCommand logonCommand, TDSReader tdsReader) throws SQ
tdsWriter.writeInt(tdsVersion);
tdsWriter.writeInt(requestedPacketSize);
tdsWriter.writeBytes(interfaceLibVersionBytes); // writeBytes() is little endian
- tdsWriter.writeInt(pid); // Client process ID
+ tdsWriter.writeInt(DriverJDBCVersion.getProcessId()); // Client process ID
tdsWriter.writeInt(0); // Primary server connection ID
tdsWriter.writeByte((byte) (// OptionFlags1:
diff --git a/src/main/java/com/microsoft/sqlserver/jdbc/SQLServerDataSource.java b/src/main/java/com/microsoft/sqlserver/jdbc/SQLServerDataSource.java
index 26d96805f8..67297f7492 100644
--- a/src/main/java/com/microsoft/sqlserver/jdbc/SQLServerDataSource.java
+++ b/src/main/java/com/microsoft/sqlserver/jdbc/SQLServerDataSource.java
@@ -1313,11 +1313,7 @@ SQLServerConnection getConnectionInternal(String username, String password,
if (dsLogger.isLoggable(Level.FINER))
dsLogger.finer(toString() + " Begin create new connection.");
SQLServerConnection result = null;
- if (Util.use43Wrapper()) {
- result = new SQLServerConnection43(toString());
- } else {
- result = new SQLServerConnection(toString());
- }
+ result = DriverJDBCVersion.getSQLServerConnection(toString());
result.connect(mergedProps, pooledConnection);
if (dsLogger.isLoggable(Level.FINER))
dsLogger.finer(toString() + " End create new connection " + result.toString());
diff --git a/src/main/java/com/microsoft/sqlserver/jdbc/SQLServerDriver.java b/src/main/java/com/microsoft/sqlserver/jdbc/SQLServerDriver.java
index 34879c77df..4848e657ef 100644
--- a/src/main/java/com/microsoft/sqlserver/jdbc/SQLServerDriver.java
+++ b/src/main/java/com/microsoft/sqlserver/jdbc/SQLServerDriver.java
@@ -911,11 +911,7 @@ public java.sql.Connection connect(String Url, Properties suppliedProperties) th
// Merge connectProperties (from URL) and supplied properties from user.
Properties connectProperties = parseAndMergeProperties(Url, suppliedProperties);
if (connectProperties != null) {
- if (Util.use43Wrapper()) {
- result = new SQLServerConnection43(toString());
- } else {
- result = new SQLServerConnection(toString());
- }
+ result = DriverJDBCVersion.getSQLServerConnection(toString());
result.connect(connectProperties, null);
}
loggerExternal.exiting(getClassNameLogging(), "connect", result);
diff --git a/src/main/java/com/microsoft/sqlserver/jdbc/SQLServerJdbc42.java b/src/main/java/com/microsoft/sqlserver/jdbc/SQLServerJdbc42.java
index c37a16729f..aad3903775 100644
--- a/src/main/java/com/microsoft/sqlserver/jdbc/SQLServerJdbc42.java
+++ b/src/main/java/com/microsoft/sqlserver/jdbc/SQLServerJdbc42.java
@@ -31,4 +31,15 @@ static final void throwBatchUpdateException(SQLServerException lastError,
throw new BatchUpdateException(lastError.getMessage(), lastError.getSQLState(), lastError.getErrorCode(), updateCounts,
new Throwable(lastError.getMessage()));
}
+
+ static SQLServerConnection getSQLServerConnection(String parentInfo) throws SQLServerException {
+ return new SQLServerConnection(parentInfo);
+ }
+
+ /** Client process ID sent during login */
+ private static int pid = 0;
+
+ static int getProcessId() {
+ return pid;
+ }
}
\ No newline at end of file
diff --git a/src/main/java/com/microsoft/sqlserver/jdbc/SQLServerJdbc43.java b/src/main/java/com/microsoft/sqlserver/jdbc/SQLServerJdbc43.java
index 9279df2ab2..645e672936 100644
--- a/src/main/java/com/microsoft/sqlserver/jdbc/SQLServerJdbc43.java
+++ b/src/main/java/com/microsoft/sqlserver/jdbc/SQLServerJdbc43.java
@@ -29,4 +29,26 @@ static final void throwBatchUpdateException(SQLServerException lastError,
throw new BatchUpdateException(lastError.getMessage(), lastError.getSQLState(), lastError.getErrorCode(),
updateCounts, new Throwable(lastError.getMessage()));
}
+
+ private static double jvmVersion = Double.parseDouble(Util.SYSTEM_SPEC_VERSION);
+
+ static SQLServerConnection getSQLServerConnection(String parentInfo) throws SQLServerException {
+ return jvmVersion >= 9 ? new SQLServerConnection43(parentInfo) : new SQLServerConnection(parentInfo);
+ }
+
+ /** Client process ID sent during login */
+ private static int pid = 0;
+
+ static {
+ long pidLong = 0;
+ try {
+ pidLong = ProcessHandle.current().pid();
+ } catch (NoClassDefFoundError e) { // ProcessHandle is Java 9+
+ }
+ pid = (pidLong > Integer.MAX_VALUE) ? 0 : (int) pidLong;
+ }
+
+ static int getProcessId() {
+ return pid;
+ }
}
diff --git a/src/main/java/com/microsoft/sqlserver/jdbc/SQLServerXAConnection.java b/src/main/java/com/microsoft/sqlserver/jdbc/SQLServerXAConnection.java
index 01268e335f..5f356fc642 100644
--- a/src/main/java/com/microsoft/sqlserver/jdbc/SQLServerXAConnection.java
+++ b/src/main/java/com/microsoft/sqlserver/jdbc/SQLServerXAConnection.java
@@ -90,11 +90,7 @@ public final class SQLServerXAConnection extends SQLServerPooledConnection imple
if (xaLogger.isLoggable(Level.FINER))
xaLogger.finer("Creating an internal control connection for" + toString());
physicalControlConnection = null;
- if (Util.use43Wrapper()) {
- physicalControlConnection = new SQLServerConnection43(toString());
- } else {
- physicalControlConnection = new SQLServerConnection(toString());
- }
+ physicalControlConnection = DriverJDBCVersion.getSQLServerConnection(toString());
physicalControlConnection.connect(controlConnectionProperties, null);
if (xaLogger.isLoggable(Level.FINER))
xaLogger.finer("Created an internal control connection" + physicalControlConnection.toString() + " for "
diff --git a/src/main/java/com/microsoft/sqlserver/jdbc/Util.java b/src/main/java/com/microsoft/sqlserver/jdbc/Util.java
index 5182fc2a41..9c97bd1b9f 100644
--- a/src/main/java/com/microsoft/sqlserver/jdbc/Util.java
+++ b/src/main/java/com/microsoft/sqlserver/jdbc/Util.java
@@ -967,27 +967,6 @@ static synchronized boolean checkIfNeedNewAccessToken(SQLServerConnection connec
return false;
}
- static final boolean use43Wrapper;
-
- static {
- boolean supportJDBC43 = true;
- try {
- DriverJDBCVersion.checkSupportsJDBC43();
- } catch (UnsupportedOperationException e) {
- supportJDBC43 = false;
- }
-
- double jvmVersion = Double.parseDouble(Util.SYSTEM_SPEC_VERSION);
-
- use43Wrapper = supportJDBC43 && (9 <= jvmVersion);
- }
-
- // if driver is for JDBC 43 and jvm version is 9 or higher, then always return as SQLServerConnection43,
- // otherwise return SQLServerConnection
- static boolean use43Wrapper() {
- return use43Wrapper;
- }
-
@SuppressWarnings("unchecked")
static T newInstance(Class> returnType, String className, String constructorArg,
Object[] msgArgs) throws InstantiationException, IllegalAccessException, IllegalArgumentException, InvocationTargetException, NoSuchMethodException, SecurityException, ClassNotFoundException {
diff --git a/src/test/java/com/microsoft/sqlserver/jdbc/connection/ClientProcessIdTest.java b/src/test/java/com/microsoft/sqlserver/jdbc/connection/ClientProcessIdTest.java
index 1428ab9903..f646947821 100644
--- a/src/test/java/com/microsoft/sqlserver/jdbc/connection/ClientProcessIdTest.java
+++ b/src/test/java/com/microsoft/sqlserver/jdbc/connection/ClientProcessIdTest.java
@@ -42,6 +42,7 @@ public class ClientProcessIdTest extends AbstractTest {
@Test
@Tag(Constants.xAzureSQLDW)
+ @Tag(Constants.xJDBC42)
public void testClientProcessId() throws SQLException {
SQLServerDataSource ds = new SQLServerDataSource();
ds.setURL(connectionString);
@@ -50,7 +51,7 @@ public void testClientProcessId() throws SQLException {
try (Connection con = ds.getConnection(); Statement stmt = con.createStatement()) {
try (ResultSet rs = stmt.executeQuery(sqlSelect)) {
if (rs.next()) {
- assertEquals(rs.getInt(1), pid);
+ assertEquals(pid, rs.getInt(1));
} else {
assertTrue(false, "Expected row of data was not found.");
}