|
4 | 4 | */ |
5 | 5 | package com.microsoft.sqlserver.jdbc.unit.statement; |
6 | 6 |
|
| 7 | +import static org.junit.Assert.assertNotNull; |
7 | 8 | import static org.junit.jupiter.api.Assertions.assertArrayEquals; |
8 | 9 | import static org.junit.jupiter.api.Assertions.assertTrue; |
9 | 10 | import static org.junit.jupiter.api.Assertions.assertEquals; |
@@ -109,6 +110,36 @@ public void testBatchUpdateCountTrueOnFirstPstmtSpPrepare() throws Exception { |
109 | 110 | testBatchUpdateCountWith(5, 4, true, "prepare", expectedUpdateCount); |
110 | 111 | } |
111 | 112 |
|
| 113 | + @Test |
| 114 | + public void testSqlServerBulkCopyCachingPstmtLevel() throws Exception { |
| 115 | + Calendar gmtCal = Calendar.getInstance(TimeZone.getTimeZone("GMT")); |
| 116 | + long ms = 1578743412000L; |
| 117 | + |
| 118 | + try (Connection con = DriverManager.getConnection( |
| 119 | + connectionString + ";useBulkCopyForBatchInsert=true;sendTemporalDataTypesAsStringForBulkCopy=false;"); |
| 120 | + Statement stmt = con.createStatement(); |
| 121 | + PreparedStatement pstmt = con.prepareStatement("INSERT INTO " + timestampTable1 + " VALUES(?)")) { |
| 122 | + |
| 123 | + TestUtils.dropTableIfExists(timestampTable1, stmt); |
| 124 | + String createSql = "CREATE TABLE " + timestampTable1 + " (c1 DATETIME2(3))"; |
| 125 | + stmt.execute(createSql); |
| 126 | + |
| 127 | + Field cachedBulkCopyOperationField = pstmt.getClass().getDeclaredField("bcOperation"); |
| 128 | + cachedBulkCopyOperationField.setAccessible(true); |
| 129 | + Object cachedBulkCopyOperation = cachedBulkCopyOperationField.get(pstmt); |
| 130 | + assertEquals(null, cachedBulkCopyOperation, "SqlServerBulkCopy object should not be cached yet."); |
| 131 | + |
| 132 | + Timestamp timestamp = new Timestamp(ms); |
| 133 | + |
| 134 | + pstmt.setTimestamp(1, timestamp, gmtCal); |
| 135 | + pstmt.addBatch(); |
| 136 | + pstmt.executeBatch(); |
| 137 | + |
| 138 | + cachedBulkCopyOperation = cachedBulkCopyOperationField.get(pstmt); |
| 139 | + assertNotNull("SqlServerBulkCopy object should be cached.", cachedBulkCopyOperation); |
| 140 | + } |
| 141 | + } |
| 142 | + |
112 | 143 | @Test |
113 | 144 | public void testValidTimezoneForTimestampBatchInsertWithBulkCopy() throws Exception { |
114 | 145 | Calendar gmtCal = Calendar.getInstance(TimeZone.getTimeZone("GMT")); |
|
0 commit comments