Skip to content

Commit f56b868

Browse files
Add | Add support in SQLServerBulkCopy to allow Pooled/XA Connection instances during object creation. (#968)
1 parent 5c202b1 commit f56b868

16 files changed

+595
-338
lines changed

.travis.yml

+4-3
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,9 @@ services:
1010
env:
1111
global:
1212
- mssql_jdbc_logging='true'
13-
# Enabling logging with console / file handler for JUnit Test Framework.
14-
#- mssql_jdbc_logging_handler='console'|'file'
13+
14+
# Enabling logging with console / file handler for JUnit Test Framework.
15+
# - mssql_jdbc_logging_handler='console'|'file'
1516

1617
#Cache the .m2 folder
1718
cache:
@@ -33,7 +34,7 @@ install:
3334

3435
before_script:
3536
- docker pull mcr.microsoft.com/mssql/server:latest
36-
- export SQLPWD=$(</dev/urandom tr -dc 'A-Za-z0-9#!' | head -c 15;)
37+
- export SQLPWD=$(</dev/urandom tr -dc 'A-Za-z0-9!' | head -c 15;)
3738
- export mssql_jdbc_test_connection_properties="jdbc:sqlserver://localhost:1433;databaseName=master;username=sa;password=$SQLPWD"
3839
- docker run -e 'ACCEPT_EULA=Y' -e "SA_PASSWORD=$SQLPWD" -p 1433:1433 -d mcr.microsoft.com/mssql/server:latest
3940

src/main/java/com/microsoft/sqlserver/jdbc/SQLServerBulkCopy.java

+7-4
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@
4747
import java.util.logging.Level;
4848

4949
import javax.sql.RowSet;
50+
import javax.sql.XAConnection;
5051

5152
import microsoft.sql.DateTimeOffset;
5253

@@ -270,13 +271,15 @@ class BulkColumnMetaData {
270271
public SQLServerBulkCopy(Connection connection) throws SQLServerException {
271272
loggerExternal.entering(loggerClassName, "SQLServerBulkCopy", connection);
272273

273-
if (null == connection || !(connection instanceof SQLServerConnection)) {
274+
if (null == connection || !(connection instanceof ISQLServerConnection)) {
274275
SQLServerException.makeFromDriverError(null, null,
275276
SQLServerException.getErrString("R_invalidDestConnection"), null, false);
276277
}
277278

278279
if (connection instanceof SQLServerConnection) {
279280
this.connection = (SQLServerConnection) connection;
281+
} else if (connection instanceof SQLServerConnectionPoolProxy) {
282+
this.connection = ((SQLServerConnectionPoolProxy) connection).getWrappedConnection();
280283
} else {
281284
SQLServerException.makeFromDriverError(null, null,
282285
SQLServerException.getErrString("R_invalidDestConnection"), null, false);
@@ -1962,9 +1965,9 @@ private void writeColumnToTdsWriter(TDSWriter tdsWriter, int bulkPrecision, int
19621965
bulkJdbcType = java.sql.Types.VARBINARY;
19631966
}
19641967
/*
1965-
* if source is encrypted and destination is unencrypted, use destination sql type to send since there is no
1966-
* way of finding if source is encrypted without accessing the resultset, send destination type if source
1967-
* resultset set is of type SQLServer and encryption is enabled
1968+
* if source is encrypted and destination is unencrypted, use destination sql type to send since there is no way
1969+
* of finding if source is encrypted without accessing the resultset, send destination type if source resultset
1970+
* set is of type SQLServer and encryption is enabled
19681971
*/
19691972
else if (null != sourceCryptoMeta) {
19701973
bulkJdbcType = destColumnMetadata.get(destColOrdinal).jdbcType;

src/main/java/com/microsoft/sqlserver/jdbc/SQLServerConnectionPoolProxy.java

+4
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,10 @@ public String toString() {
6565
bIsOpen = true;
6666
}
6767

68+
SQLServerConnection getWrappedConnection() {
69+
return wrappedConnection;
70+
}
71+
6872
void checkClosed() throws SQLServerException {
6973
if (!bIsOpen) {
7074
SQLServerException.makeFromDriverError(null, null, SQLServerException.getErrString("R_connectionIsClosed"),

src/test/java/com/microsoft/sqlserver/jdbc/bulkCopy/BulkCopyAllTypesTest.java

+1-2
Original file line numberDiff line numberDiff line change
@@ -64,8 +64,7 @@ private void testBulkCopyResultSet(boolean setSelectMethod, Integer resultSetTyp
6464
bcOperation.writeToServer(rs);
6565
bcOperation.close();
6666

67-
ComparisonUtil.compareSrcTableAndDestTableIgnoreRowOrder(new DBConnection(connection), tableSrc,
68-
tableDest);
67+
ComparisonUtil.compareSrcTableAndDestTableIgnoreRowOrder(new DBConnection(connection), tableSrc, tableDest);
6968
} finally {
7069
terminateVariation();
7170
}

0 commit comments

Comments
 (0)