Skip to content

Commit

Permalink
Incident#567732673 - Add provision to set SQLServerBulkCopy options i…
Browse files Browse the repository at this point in the history
…n PreparedStatement (#2555)

* Add provision to set SQLServerBulkCopy options in PreparedStatement

* Reanmed test

* Renamed bcCopyOptions to bcOptions

* Fixed indentation

* Fail the test that enables consraint checking when exception is not
thrown

* Added connection string options for all the available bulk copy options

* Added test case for bulkCopyOptionDefaultsBatchSize, bulkCopyOptionDefaultsKeepIdentity and bulkCopyOptionDefaultsTableLock

* Added test case for bulkCopty options in Prepared Statement

* Updated failures in test case

* Added test case testBulkCopyOptionDefaultsTimeoutLowerValue

* Added test case for bulkCopyOptionDefaultsAllowEncryptedValueModifications

* Fixed failures

* Added test scenario for bulkCopyOptionDefaultsAllowEncryptedValueModifications

* Improved messages.

* Remove the setBulkCopyOptions method from PreparedStatement

-Since the change has added connection string options for setting
various bulk copy options, this non-standard API is not needed.

* Fixed indent issue.

* Update name for bulk copy batchSize option

* Update name for bulk copy timeout option

* Update name for bulk copy check constraints option

* Update name for bulk copy fireTrigger, keepIdentity, keepNulls, tableLock, internalTrnsaction, encrptedValue  options

* Remove timeout option as configured already in bulk copy option

* Updated value of bulkCopyForBatchInsertTimeout to 60s

* Removed timeout and internal transaction option

* removed local changes

---------

Co-authored-by: muskan124947 <[email protected]>
Co-authored-by: Divang Sharma <[email protected]>
  • Loading branch information
3 people authored Jan 24, 2025
1 parent 2a3d372 commit 5b2cd71
Show file tree
Hide file tree
Showing 11 changed files with 1,533 additions and 49 deletions.
105 changes: 105 additions & 0 deletions src/main/java/com/microsoft/sqlserver/jdbc/ISQLServerConnection.java
Original file line number Diff line number Diff line change
Expand Up @@ -547,4 +547,109 @@ CallableStatement prepareCall(String sql, int nType, int nConcur, int nHold,
* @return cacheBulkCopyMetadata boolean value
*/
boolean getcacheBulkCopyMetadata();

/**
* Specifies the default batch size for bulk copy operations created from batch insert operations.
*
* @param bulkCopyForBatchInsertBatchSize
* integer value for bulkCopyForBatchInsertBatchSize.
*/
void setBulkCopyForBatchInsertBatchSize(int bulkCopyForBatchInsertBatchSize);

/**
* Returns the default batch size for bulk copy operations created from batch insert operations.
*
* @return integer value for bulkCopyForBatchInsertBatchSize.
*/
int getBulkCopyForBatchInsertBatchSize();

/**
* Specifies the default check constraints for bulk copy operations created from batch insert operations.
*
* @param bulkCopyForBatchInsertCheckConstraints
* boolean value for bulkCopyForBatchInsertCheckConstraints.
*/
void setBulkCopyForBatchInsertCheckConstraints(boolean bulkCopyForBatchInsertCheckConstraints);

/**
* Returns the default check constraints for bulk copy operations created from batch insert operations.
*
* @return boolean value for bulkCopyForBatchInsertCheckConstraints.
*/
boolean getBulkCopyForBatchInsertCheckConstraints();

/**
* Specifies the default fire triggers for bulk copy operations created from batch insert operations.
*
* @param bulkCopyForBatchInsertFireTriggers
* boolean value for bulkCopyForBatchInsertFireTriggers.
*/
void setBulkCopyForBatchInsertFireTriggers(boolean bulkCopyForBatchInsertFireTriggers);

/**
* Returns the default fire triggers for bulk copy operations created from batch insert operations.
*
* @return boolean value for bulkCopyForBatchInsertFireTriggers.
*/
boolean getBulkCopyForBatchInsertFireTriggers();

/**
* Specifies the default keep identity for bulk copy operations created from batch insert operations.
*
* @param bulkCopyForBatchInsertKeepIdentity
* boolean value for bulkCopyForBatchInsertKeepIdentity.
*/
void setBulkCopyForBatchInsertKeepIdentity(boolean bulkCopyForBatchInsertKeepIdentity);

/**
* Returns the default keep identity for bulk copy operations created from batch insert operations.
*
* @return boolean value for bulkCopyForBatchInsertKeepIdentity.
*/
boolean getBulkCopyForBatchInsertKeepIdentity();

/**
* Specifies the default keep nulls for bulk copy operations created from batch insert operations.
*
* @param bulkCopyForBatchInsertKeepNulls
* boolean value for bulkCopyForBatchInsertKeepNulls.
*/
void setBulkCopyForBatchInsertKeepNulls(boolean bulkCopyForBatchInsertKeepNulls);

/**
* Returns the default keep nulls for bulk copy operations created from batch insert operations.
*
* @return boolean value for bulkCopyForBatchInsertKeepNulls.
*/
boolean getBulkCopyForBatchInsertKeepNulls();

/**
* Specifies the default table lock for bulk copy operations created from batch insert operations.
*
* @param bulkCopyForBatchInsertTableLock
* boolean value for bulkCopyForBatchInsertTableLock.
*/
void setBulkCopyForBatchInsertTableLock(boolean bulkCopyForBatchInsertTableLock);

/**
* Returns the default table lock for bulk copy operations created from batch insert operations.
*
* @return boolean value for bulkCopyForBatchInsertTableLock.
*/
boolean getBulkCopyForBatchInsertTableLock();

/**
* Specifies the default allow encrypted value modifications for bulk copy operations created from batch insert operations.
*
* @param bulkCopyForBatchInsertAllowEncryptedValueModifications
* boolean value for bulkCopyForBatchInsertAllowEncryptedValueModifications.
*/
void setBulkCopyForBatchInsertAllowEncryptedValueModifications(boolean bulkCopyForBatchInsertAllowEncryptedValueModifications);

/**
* Returns the default allow encrypted value modifications for bulk copy operations created from batch insert operations.
*
* @return boolean value for bulkCopyForBatchInsertAllowEncryptedValueModifications.
*/
boolean getBulkCopyForBatchInsertAllowEncryptedValueModifications();
}
105 changes: 105 additions & 0 deletions src/main/java/com/microsoft/sqlserver/jdbc/ISQLServerDataSource.java
Original file line number Diff line number Diff line change
Expand Up @@ -980,6 +980,111 @@ public interface ISQLServerDataSource extends javax.sql.CommonDataSource {
*/
void setUseBulkCopyForBatchInsert(boolean useBulkCopyForBatchInsert);

/**
* Sets the default batch size for bulk copy operations created from batch insert operations.
*
* @param bulkCopyForBatchInsertBatchSize
* the default batch size for bulk copy operations created from batch insert operations.
*/
void setBulkCopyForBatchInsertBatchSize(int bulkCopyForBatchInsertBatchSize);

/**
* Returns the default batch size for bulk copy operations created from batch insert operations.
*
* @return the default batch size for bulk copy operations created from batch insert operations.
*/
int getBulkCopyForBatchInsertBatchSize();

/**
* Sets whether to check constraints during bulk copy operations created from batch insert operations.
*
* @param bulkCopyForBatchInsertCheckConstraints
* indicates whether to check constraints during bulk copy operations created from batch insert operations.
*/
void setBulkCopyForBatchInsertCheckConstraints(boolean bulkCopyForBatchInsertCheckConstraints);

/**
* Returns whether to check constraints during bulk copy operations created from batch insert operations.
*
* @return whether to check constraints during bulk copy operations created from batch insert operations.
*/
boolean getBulkCopyForBatchInsertCheckConstraints();

/**
* Sets whether to fire triggers during bulk copy operations created from batch insert operations.
*
* @param bulkCopyForBatchInsertFireTriggers
* indicates whether to fire triggers during bulk copy operations created from batch insert operations.
*/
void setBulkCopyForBatchInsertFireTriggers(boolean bulkCopyForBatchInsertFireTriggers);

/**
* Returns whether to fire triggers during bulk copy operations created from batch insert operations.
*
* @return whether to fire triggers during bulk copy operations created from batch insert operations.
*/
boolean getBulkCopyForBatchInsertFireTriggers();

/**
* Sets whether to keep identity values during bulk copy operations created from batch insert operations.
*
* @param bulkCopyForBatchInsertKeepIdentity
* indicates whether to keep identity values during bulk copy operations created from batch insert operations.
*/
void setBulkCopyForBatchInsertKeepIdentity(boolean bulkCopyForBatchInsertKeepIdentity);

/**
* Returns whether to keep identity values during bulk copy operations created from batch insert operations.
*
* @return whether to keep identity values during bulk copy operations created from batch insert operations.
*/
boolean getBulkCopyForBatchInsertKeepIdentity();

/**
* Sets whether to keep null values during bulk copy operations created from batch insert operations.
*
* @param bulkCopyForBatchInsertKeepNulls
* indicates whether to keep null values during bulk copy operations created from batch insert operations.
*/
void setBulkCopyForBatchInsertKeepNulls(boolean bulkCopyForBatchInsertKeepNulls);

/**
* Returns whether to keep null values during bulk copy operations created from batch insert operations.
*
* @return whether to keep null values during bulk copy operations created from batch insert operations.
*/
boolean getBulkCopyForBatchInsertKeepNulls();

/**
* Sets whether to use table lock during bulk copy operations created from batch insert operations.
*
* @param bulkCopyForBatchInsertTableLock
* indicates whether to use table lock during bulk copy operations created from batch insert operations.
*/
void setBulkCopyForBatchInsertTableLock(boolean bulkCopyForBatchInsertTableLock);

/**
* Returns whether to use table lock during bulk copy operations created from batch insert operations.
*
* @return whether to use table lock during bulk copy operations created from batch insert operations.
*/
boolean getBulkCopyForBatchInsertTableLock();

/**
* Sets whether to allow encrypted value modifications during bulk copy operations created from batch insert operations.
*
* @param bulkCopyForBatchInsertAllowEncryptedValueModifications
* indicates whether to allow encrypted value modifications during bulk copy operations created from batch insert operations.
*/
void setBulkCopyForBatchInsertAllowEncryptedValueModifications(boolean bulkCopyForBatchInsertAllowEncryptedValueModifications);

/**
* Returns whether to allow encrypted value modifications during bulk copy operations created from batch insert operations.
*
* @return whether to allow encrypted value modifications during bulk copy operations created from batch insert operations.
*/
boolean getBulkCopyForBatchInsertAllowEncryptedValueModifications();

/**
* Sets the client id to be used to retrieve the access token for a user-assigned Managed Identity.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,20 @@ public SQLServerBulkCopyOptions() {
useInternalTransaction = false;
allowEncryptedValueModifications = false;
}

/**
* Constructs a SQLServerBulkCopySettings class using defaults from given connection
*/
SQLServerBulkCopyOptions(SQLServerConnection conn) {
batchSize = conn.getBulkCopyForBatchInsertBatchSize();
checkConstraints = conn.getBulkCopyForBatchInsertCheckConstraints();
fireTriggers = conn.getBulkCopyForBatchInsertFireTriggers();
keepIdentity = conn.getBulkCopyForBatchInsertKeepIdentity();
keepNulls = conn.getBulkCopyForBatchInsertKeepNulls();
tableLock = conn.getBulkCopyForBatchInsertTableLock();
allowEncryptedValueModifications = conn.getBulkCopyForBatchInsertAllowEncryptedValueModifications();
}


/**
* Returns the number of rows in each batch. At the end of each batch, the rows in the batch are sent to the server.
Expand Down
Loading

0 comments on commit 5b2cd71

Please sign in to comment.