Skip to content

Commit 426e5ae

Browse files
authored
Adding Delayed Durability to commit API(#1310)
1 parent 3b4f0a2 commit 426e5ae

File tree

1 file changed

+20
-1
lines changed

1 file changed

+20
-1
lines changed

src/main/java/com/microsoft/sqlserver/jdbc/SQLServerConnection.java

+20-1
Original file line numberDiff line numberDiff line change
@@ -3351,14 +3351,33 @@ final byte[] getTransactionDescriptor() {
33513351

33523352
@Override
33533353
public void commit() throws SQLServerException {
3354+
commit(false);
3355+
}
3356+
3357+
/**
3358+
* Makes all changes made since the previous
3359+
* commit/rollback permanent and releases any database locks
3360+
* currently held by this <code>Connection</code> object.
3361+
* This method should be
3362+
* used only when auto-commit mode has been disabled.
3363+
*
3364+
* @param delayedDurability flag to indicate whether the commit will occur with delayed durability on.
3365+
* @throws SQLServerException Exception if a database access error occurs,
3366+
*/
3367+
public void commit(boolean delayedDurability) throws SQLServerException {
33543368
loggerExternal.entering(loggingClassName, "commit");
33553369
if (loggerExternal.isLoggable(Level.FINER) && Util.isActivityTraceOn()) {
33563370
loggerExternal.finer(toString() + " ActivityId: " + ActivityCorrelator.getNext().toString());
33573371
}
33583372

33593373
checkClosed();
33603374
if (!databaseAutoCommitMode)
3361-
connectionCommand("IF @@TRANCOUNT > 0 COMMIT TRAN", "Connection.commit");
3375+
{
3376+
if (!delayedDurability)
3377+
connectionCommand("IF @@TRANCOUNT > 0 COMMIT TRAN", "Connection.commit");
3378+
else
3379+
connectionCommand("IF @@TRANCOUNT > 0 COMMIT TRAN WITH ( DELAYED_DURABILITY = ON )", "Connection.commit");
3380+
}
33623381
loggerExternal.exiting(loggingClassName, "commit");
33633382
}
33643383

0 commit comments

Comments
 (0)