Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added a missing unlock in getDestinationMetadata() #2484

Merged
merged 10 commits into from
Aug 20, 2024
Original file line number Diff line number Diff line change
Expand Up @@ -1742,10 +1742,9 @@ private void getDestinationMetadata() throws SQLServerException {
if (null == destColumnMetadata || destColumnMetadata.isEmpty()) {
if (connection.getcacheBulkCopyMetadata()) {
DESTINATION_COL_METADATA_LOCK.lock();
destColumnMetadata = BULK_COPY_OPERATION_CACHE.get(key);

if (null == destColumnMetadata || destColumnMetadata.isEmpty()) {
try {
try {
destColumnMetadata = BULK_COPY_OPERATION_CACHE.get(key);
if (null == destColumnMetadata || destColumnMetadata.isEmpty()) {
setDestinationColumnMetadata(escapedDestinationTableName);

// We are caching the following metadata about the table:
Expand All @@ -1759,9 +1758,9 @@ private void getDestinationMetadata() throws SQLServerException {
// scenario, we can't detect this without making an additional metadata query, which would
// defeat the purpose of caching.
BULK_COPY_OPERATION_CACHE.put(key, destColumnMetadata);
} finally {
DESTINATION_COL_METADATA_LOCK.unlock();
}
} finally {
DESTINATION_COL_METADATA_LOCK.unlock();
}

if (loggerExternal.isLoggable(Level.FINER)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
import static org.junit.Assert.assertNotNull;
import static org.junit.Assume.assumeTrue;
import static org.junit.jupiter.api.Assertions.assertArrayEquals;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.junit.jupiter.api.Assertions.fail;

import java.lang.reflect.Field;
Expand All @@ -27,8 +27,12 @@
import java.util.Calendar;
import java.util.HashMap;
import java.util.TimeZone;
import java.util.Timer;
import java.util.TimerTask;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

import com.microsoft.sqlserver.jdbc.SQLServerPreparedStatement;
import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Tag;
Expand All @@ -39,6 +43,7 @@

import com.microsoft.sqlserver.jdbc.RandomUtil;
import com.microsoft.sqlserver.jdbc.SQLServerConnection;
import com.microsoft.sqlserver.jdbc.SQLServerPreparedStatement;
import com.microsoft.sqlserver.jdbc.SQLServerStatement;
import com.microsoft.sqlserver.jdbc.TestResource;
import com.microsoft.sqlserver.jdbc.TestUtils;
Expand Down Expand Up @@ -147,8 +152,8 @@ public void testSqlServerBulkCopyCachingConnectionLevel() throws Exception {
Calendar gmtCal = Calendar.getInstance(TimeZone.getTimeZone("GMT"));
long ms = 1578743412000L;

try (SQLServerConnection con = (SQLServerConnection) DriverManager.getConnection(
connectionString + ";useBulkCopyForBatchInsert=true;cacheBulkCopyMetadata=true;sendTemporalDataTypesAsStringForBulkCopy=false;");
try (SQLServerConnection con = (SQLServerConnection) DriverManager.getConnection(connectionString
+ ";useBulkCopyForBatchInsert=true;cacheBulkCopyMetadata=true;sendTemporalDataTypesAsStringForBulkCopy=false;");
Statement stmt = con.createStatement()) {

// Needs to be on a JDK version greater than 8
Expand Down Expand Up @@ -206,6 +211,7 @@ public void testSqlServerBulkCopyCachingConnectionLevel() throws Exception {
}
}


@Test
public void testValidTimezoneForTimestampBatchInsertWithBulkCopy() throws Exception {
Calendar gmtCal = Calendar.getInstance(TimeZone.getTimeZone("GMT"));
Expand Down
Loading