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

Fixed exception type to SQLFeatureNotSupported #2583

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 2 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
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import java.sql.ResultSet;
import java.sql.SQLClientInfoException;
import java.sql.SQLException;
import java.sql.SQLFeatureNotSupportedException;
import java.sql.SQLPermission;
import java.sql.SQLWarning;
import java.sql.SQLXML;
Expand Down Expand Up @@ -7196,7 +7197,9 @@ public PreparedStatement prepareStatement(String sql, String[] columnNames,
@Override
public void releaseSavepoint(Savepoint savepoint) throws SQLException {
loggerExternal.entering(loggingClassName, "releaseSavepoint", savepoint);
SQLServerException.throwNotSupportedException(this, null);
MessageFormat form = new MessageFormat(SQLServerException.getErrString("R_featureNotSupported"));
Object[] msgArgs = {"releaseSavepoint"};
throw new SQLFeatureNotSupportedException(form.format(msgArgs));
}

final private Savepoint setNamedSavepoint(String sName) throws SQLServerException {
Expand Down
3 changes: 2 additions & 1 deletion src/test/java/com/microsoft/sqlserver/jdbc/TestResource.java
Original file line number Diff line number Diff line change
Expand Up @@ -216,5 +216,6 @@ protected Object[][] getContents() {
{"R_expectedClassDoesNotMatchActualClass",
"Expected column class {0} does not match actual column class {1} for column {2}."},
{"R_loginFailedMI", "Login failed for user '<token-identified principal>'"},
{"R_MInotAvailable", "Managed Identity authentication is not available"},};
{"R_MInotAvailable", "Managed Identity authentication is not available"},
{"R_featureNotSupported", "{0} is not supported."},};
machavan marked this conversation as resolved.
Show resolved Hide resolved
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,16 @@
*/
package com.microsoft.sqlserver.jdbc.unit;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertTrue;

import java.sql.Connection;
import java.sql.SQLException;
import java.sql.SQLFeatureNotSupportedException;
import java.text.MessageFormat;

import com.microsoft.sqlserver.jdbc.TestUtils;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Tag;
import org.junit.jupiter.api.Test;
Expand Down Expand Up @@ -136,4 +137,27 @@ public void testSavePointWithAutoCommit() throws SQLException {
} catch (SQLException e) {}
}
}

/**
* Test releaseSavepoint.
*
* @throws SQLException
*/
@Test
public void testReleaseSavepoint() throws SQLException {
try (Connection connection = getConnection()) {
try {
connection.releaseSavepoint(null);
} catch (SQLException e) {
assertEquals(e.getClass(), SQLFeatureNotSupportedException.class, "Expected exception type " + SQLFeatureNotSupportedException.class.getName() + ", but received " + e.getClass().getName());
machavan marked this conversation as resolved.
Show resolved Hide resolved

MessageFormat form = new MessageFormat(TestResource.getResource("R_featureNotSupported"));
Object[] msgArgs = {"releaseSavepoint"};
String expectedExceptionMsg = form.format(msgArgs);
String receivedExceptionMsg = e.getMessage();
assertEquals(expectedExceptionMsg, receivedExceptionMsg, "Expected exception message " + expectedExceptionMsg + ", but received " + receivedExceptionMsg);;
}
}
}

}
Loading