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

Incident#567732673 - Add provision to set SQLServerBulkCopy options in PreparedStatement #2555

Open
wants to merge 13 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
135 changes: 135 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,139 @@ 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.
*
* @param bulkCopyOptionDefaultsBatchSize
* integer value for bulkCopyOptionDefaultsBatchSize.
*/
void setBulkCopyOptionDefaultsBatchSize(int bulkCopyOptionDefaultsBatchSize);

/**
* Returns the default batch size for bulk copy operations.
*
* @return integer value for bulkCopyOptionDefaultsBatchSize.
*/
int getBulkCopyOptionDefaultsBatchSize();

/**
* Specifies the default timeout for bulk copy operations.
*
* @param bulkCopyOptionDefaultsTimeout
* integer value for bulkCopyOptionDefaultsTimeout.
*/
void setBulkCopyOptionDefaultsTimeout(int bulkCopyOptionDefaultsTimeout);

/**
* Returns the default timeout for bulk copy operations.
*
* @return integer value for bulkCopyOptionDefaultsTimeout.
*/
int getBulkCopyOptionDefaultsTimeout();

/**
* Specifies the default check constraints option for bulk copy operations.
*
* @param bulkCopyOptionDefaultsCheckConstraints
* boolean value for bulkCopyOptionDefaultsCheckConstraints.
*/
void setBulkCopyOptionDefaultsCheckConstraints(boolean bulkCopyOptionDefaultsCheckConstraints);

/**
* Returns the default check constraints option for bulk copy operations.
*
* @return boolean value for bulkCopyOptionDefaultsCheckConstraints.
*/
boolean getBulkCopyOptionDefaultsCheckConstraints();

/**
* Specifies the default fire triggers option for bulk copy operations.
*
* @param bulkCopyOptionDefaultsFireTriggers
* boolean value for bulkCopyOptionDefaultsFireTriggers.
*/
void setBulkCopyOptionDefaultsFireTriggers(boolean bulkCopyOptionDefaultsFireTriggers);

/**
* Returns the default fire triggers option for bulk copy operations.
*
* @return boolean value for bulkCopyOptionDefaultsFireTriggers.
*/
boolean getBulkCopyOptionDefaultsFireTriggers();

/**
* Specifies the default keep identity option for bulk copy operations.
*
* @param bulkCopyOptionDefaultsKeepIdentity
* boolean value for bulkCopyOptionDefaultsKeepIdentity.
*/
void setBulkCopyOptionDefaultsKeepIdentity(boolean bulkCopyOptionDefaultsKeepIdentity);

/**
* Returns the default keep identity option for bulk copy operations.
*
* @return boolean value for bulkCopyOptionDefaultsKeepIdentity.
*/
boolean getBulkCopyOptionDefaultsKeepIdentity();

/**
* Specifies the default keep nulls option for bulk copy operations.
*
* @param bulkCopyOptionDefaultsKeepNulls
* boolean value for bulkCopyOptionDefaultsKeepNulls.
*/
void setBulkCopyOptionDefaultsKeepNulls(boolean bulkCopyOptionDefaultsKeepNulls);

/**
* Returns the default keep nulls option for bulk copy operations.
*
* @return boolean value for bulkCopyOptionDefaultsKeepNulls.
*/
boolean getBulkCopyOptionDefaultsKeepNulls();

/**
* Specifies the default table lock option for bulk copy operations.
*
* @param bulkCopyOptionDefaultsTableLock
* boolean value for bulkCopyOptionDefaultsTableLock.
*/
void setBulkCopyOptionDefaultsTableLock(boolean bulkCopyOptionDefaultsTableLock);

/**
* Returns the default table lock option for bulk copy operations.
*
* @return boolean value for bulkCopyOptionDefaultsTableLock.
*/
boolean getBulkCopyOptionDefaultsTableLock();

/**
* Specifies the default use internal transaction option for bulk copy operations.
*
* @param bulkCopyOptionDefaultsUseInternalTransaction
* boolean value for bulkCopyOptionDefaultsUseInternalTransaction.
*/
void setBulkCopyOptionDefaultsUseInternalTransaction(boolean bulkCopyOptionDefaultsUseInternalTransaction);

/**
* Returns the default use internal transaction option for bulk copy operations.
*
* @return boolean value for bulkCopyOptionDefaultsUseInternalTransaction.
*/
boolean getBulkCopyOptionDefaultsUseInternalTransaction();

/**
* Specifies the default allow encrypted value modifications option for bulk copy operations.
*
* @param bulkCopyOptionDefaultsAllowEncryptedValueModifications
* boolean value for bulkCopyOptionDefaultsAllowEncryptedValueModifications.
*/
void setBulkCopyOptionDefaultsAllowEncryptedValueModifications(boolean bulkCopyOptionDefaultsAllowEncryptedValueModifications);

/**
* Returns the default allow encrypted value modifications option for bulk copy operations.
*
* @return boolean value for bulkCopyOptionDefaultsAllowEncryptedValueModifications.
*/
boolean getBulkCopyOptionDefaultsAllowEncryptedValueModifications();
}
135 changes: 135 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,141 @@ public interface ISQLServerDataSource extends javax.sql.CommonDataSource {
*/
void setUseBulkCopyForBatchInsert(boolean useBulkCopyForBatchInsert);

/**
* Sets the default batch size for Bulk Copy operations.
*
* @param bulkCopyOptionDefaultsBatchSize
* the default batch size for Bulk Copy operations.
*/
void setBulkCopyOptionDefaultsBatchSize(int bulkCopyOptionDefaultsBatchSize);

/**
* Returns the default batch size for Bulk Copy operations.
*
* @return the default batch size for Bulk Copy operations.
*/
int getBulkCopyOptionDefaultsBatchSize();

/**
* Sets the default timeout for Bulk Copy operations.
*
* @param bulkCopyOptionDefaultsTimeout
* the default timeout for Bulk Copy operations.
*/
void setBulkCopyOptionDefaultsTimeout(int bulkCopyOptionDefaultsTimeout);

/**
* Returns the default timeout for Bulk Copy operations.
*
* @return the default timeout for Bulk Copy operations.
*/
int getBulkCopyOptionDefaultsTimeout();

/**
* Sets whether to check constraints during Bulk Copy operations.
*
* @param bulkCopyOptionDefaultsCheckConstraints
* indicates whether to check constraints during Bulk Copy operations.
*/
void setBulkCopyOptionDefaultsCheckConstraints(boolean bulkCopyOptionDefaultsCheckConstraints);

/**
* Returns whether to check constraints during Bulk Copy operations.
*
* @return whether to check constraints during Bulk Copy operations.
*/
boolean getBulkCopyOptionDefaultsCheckConstraints();

/**
* Sets whether to fire triggers during Bulk Copy operations.
*
* @param bulkCopyOptionDefaultsFireTriggers
* indicates whether to fire triggers during Bulk Copy operations.
*/
void setBulkCopyOptionDefaultsFireTriggers(boolean bulkCopyOptionDefaultsFireTriggers);

/**
* Returns whether to fire triggers during Bulk Copy operations.
*
* @return whether to fire triggers during Bulk Copy operations.
*/
boolean getBulkCopyOptionDefaultsFireTriggers();

/**
* Sets whether to keep identity values during Bulk Copy operations.
*
* @param bulkCopyOptionDefaultsKeepIdentity
* indicates whether to keep identity values during Bulk Copy operations.
*/
void setBulkCopyOptionDefaultsKeepIdentity(boolean bulkCopyOptionDefaultsKeepIdentity);

/**
* Returns whether to keep identity values during Bulk Copy operations.
*
* @return whether to keep identity values during Bulk Copy operations.
*/
boolean getBulkCopyOptionDefaultsKeepIdentity();

/**
* Sets whether to keep null values during Bulk Copy operations.
*
* @param bulkCopyOptionDefaultsKeepNulls
* indicates whether to keep null values during Bulk Copy operations.
*/
void setBulkCopyOptionDefaultsKeepNulls(boolean bulkCopyOptionDefaultsKeepNulls);

/**
* Returns whether to keep null values during Bulk Copy operations.
*
* @return whether to keep null values during Bulk Copy operations.
*/
boolean getBulkCopyOptionDefaultsKeepNulls();

/**
* Sets whether to use table lock during Bulk Copy operations.
*
* @param bulkCopyOptionDefaultsTableLock
* indicates whether to use table lock during Bulk Copy operations.
*/
void setBulkCopyOptionDefaultsTableLock(boolean bulkCopyOptionDefaultsTableLock);

/**
* Returns whether to use table lock during Bulk Copy operations.
*
* @return whether to use table lock during Bulk Copy operations.
*/
boolean getBulkCopyOptionDefaultsTableLock();

/**
* Sets whether to use internal transaction during Bulk Copy operations.
*
* @param bulkCopyOptionDefaultsUseInternalTransaction
* indicates whether to use internal transaction during Bulk Copy operations.
*/
void setBulkCopyOptionDefaultsUseInternalTransaction(boolean bulkCopyOptionDefaultsUseInternalTransaction);

/**
* Returns whether to use internal transaction during Bulk Copy operations.
*
* @return whether to use internal transaction during Bulk Copy operations.
*/
boolean getBulkCopyOptionDefaultsUseInternalTransaction();

/**
* Sets whether to allow encrypted value modifications during Bulk Copy operations.
*
* @param bulkCopyOptionDefaultsAllowEncryptedValueModifications
* indicates whether to allow encrypted value modifications during Bulk Copy operations.
*/
void setBulkCopyOptionDefaultsAllowEncryptedValueModifications(boolean bulkCopyOptionDefaultsAllowEncryptedValueModifications);

/**
* Returns whether to allow encrypted value modifications during Bulk Copy operations.
*
* @return whether to allow encrypted value modifications during Bulk Copy operations.
*/
boolean getBulkCopyOptionDefaultsAllowEncryptedValueModifications();

/**
* 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,22 @@ public SQLServerBulkCopyOptions() {
useInternalTransaction = false;
allowEncryptedValueModifications = false;
}

/**
* Constructs a SQLServerBulkCopySettings class using defaults from given connection
*/
SQLServerBulkCopyOptions(SQLServerConnection conn) {
batchSize = conn.getBulkCopyOptionDefaultsBatchSize();
bulkCopyTimeout = conn.getBulkCopyOptionDefaultsTimeout();
checkConstraints = conn.getBulkCopyOptionDefaultsCheckConstraints();
fireTriggers = conn.getBulkCopyOptionDefaultsFireTriggers();
keepIdentity = conn.getBulkCopyOptionDefaultsKeepIdentity();
keepNulls = conn.getBulkCopyOptionDefaultsKeepNulls();
tableLock = conn.getBulkCopyOptionDefaultsTableLock();
useInternalTransaction = conn.getBulkCopyOptionDefaultsUseInternalTransaction();
allowEncryptedValueModifications = conn.getBulkCopyOptionDefaultsAllowEncryptedValueModifications();
}


/**
* 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
Loading