patterntesting.exception.sql.SqlExceptionHelper Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of patterntesting-exception Show documentation
Show all versions of patterntesting-exception Show documentation
PatternTesting Exception (patterntesting-exception) is a framework round
about exceptions. It wraps some common exception (like IOException) to
provide some more information as the original exception (e.g. the
filename with the absolute pathname).
On the other it allows you to provoke exceptions for better testing.
The newest version!
package patterntesting.exception.sql;
import java.sql.SQLException;
/**
* The class SqlExceptionHelper extends the SQL exception message
* with the error-causing SQL command.
*
* @author Christian Heise
*
*/
public class SqlExceptionHelper {
/** Only utility class, no constructor necessary */
private SqlExceptionHelper() { };
/**
* If the default SQLException does not contains the SQL
* command it will be appended to the original exception
* message.
* @param originalException the original SQLException
* @param sqlCommand the SQL command with failed to execute
* @return a SQLException with the error-causing SQL command
*/
public static SQLException getBetterSqlException(
final SQLException originalException,
final String sqlCommand) {
String message = originalException.getMessage();
if (!message.toLowerCase().contains(sqlCommand.toLowerCase())) {
StringBuffer buf = new StringBuffer(message);
buf.append(" (SQL command: ");
buf.append(sqlCommand);
buf.append(" )");
message = buf.toString();
}
return new SQLException(message);
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy