Skip to content

Commit

Permalink
Additonal PR reviews
Browse files Browse the repository at this point in the history
  • Loading branch information
tkyc committed Jul 5, 2024
1 parent 6b49454 commit e625a69
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1740,14 +1740,24 @@ private void getDestinationMetadata() throws SQLServerException {
}

if (null == destColumnMetadata || destColumnMetadata.isEmpty()) {

if (connection.getEnableBulkCopyCache()) {
DESTINATION_COL_METADATA_LOCK.lock();
destColumnMetadata = BULK_COPY_OPERATION_CACHE.get(key);

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

// We are caching the following metadata about the table:
// 1. collation_name
// 2. is_computed
// 3. encryption_type
//
// Using this caching method, 'enableBulkCopyCache', may have unintended consequences if the
// table changes somehow between inserts. For example, if the collation_name changes, the
// driver will not be aware of this and the inserted data will likely be corrupted. In such
// 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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -161,8 +161,9 @@ public void testSqlServerBulkCopyCachingConnectionLevel() throws Exception {
stmt.execute(createSqlTable1);
stmt.execute(createSqlTable2);

// Calling getSuperClass() because SQLServerConnection is the parent
Field bulkcopyMetadataCacheField = con.getClass().getSuperclass().getDeclaredField("BULK_COPY_OPERATION_CACHE");
Field bulkcopyMetadataCacheField = TestUtils.getJVMVersion() > 8 ?
con.getClass().getSuperclass().getDeclaredField("BULK_COPY_OPERATION_CACHE") :
con.getClass().getDeclaredField("BULK_COPY_OPERATION_CACHE");
bulkcopyMetadataCacheField.setAccessible(true);
Object bulkcopyCache = bulkcopyMetadataCacheField.get(con);

Expand Down

0 comments on commit e625a69

Please sign in to comment.