public static SQLException toSQLException(final Exception cause, final DatabaseType databaseType) {
        if (cause instanceof SQLException) {
            return (SQLException) cause;
        }
        if (cause instanceof ShardingSphereSQLException) {
            return ((ShardingSphereSQLException) cause).toSQLException();
        }
        if (cause instanceof SQLDialectException) {
            if (cause instanceof DatabaseProtocolException) {
                return new DatabaseProtocolSQLException(cause.getMessage()).toSQLException();
            }
            Optional<SQLDialectExceptionMapper> dialectExceptionMapper = DatabaseTypedSPILoader.findService(SQLDialectExceptionMapper.class, databaseType);
            if (dialectExceptionMapper.isPresent()) {
                return dialectExceptionMapper.get().convert((SQLDialectException) cause);
            }
        }
        if (cause instanceof ShardingSphereServerException) {
            return new ServerSQLException(cause).toSQLException();
        }
        return new UnknownSQLException(cause).toSQLException();
    }
@Test
    void assertToSQLExceptionWithShardingSphereServerException() {
        ShardingSphereServerException cause = mock(ShardingSphereServerException.class);
        when(cause.getMessage()).thenReturn("No reason");
        SQLException actual = SQLExceptionTransformEngine.toSQLException(cause, databaseType);
        assertThat(actual.getSQLState(), is("HY000"));
        assertThat(actual.getErrorCode(), is(30004));
        assertThat(actual.getMessage(), is("Server exception." + System.lineSeparator() + "More details: " + cause));
    }