diff options
author | Simon Brandhof <simon.brandhof@sonarsource.com> | 2017-01-05 16:51:42 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-01-05 16:51:42 +0100 |
commit | df2dda7678133987ded0d3ab0f29b4cf3139dfec (patch) | |
tree | c6430cca2837c88beb72ca57f70a10919592ac6d /server | |
parent | 0f32d3adc4c4a9f2bfb4a2504b924bd90a05326b (diff) | |
download | sonarqube-df2dda7678133987ded0d3ab0f29b4cf3139dfec.tar.gz sonarqube-df2dda7678133987ded0d3ab0f29b4cf3139dfec.zip |
SONAR-8585 configure NLS_SORT param on Oracle client sessions
Diffstat (limited to 'server')
2 files changed, 11 insertions, 24 deletions
diff --git a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/charset/OracleCharsetHandler.java b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/charset/OracleCharsetHandler.java index 5179d5666b3..9cc6e97416f 100644 --- a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/charset/OracleCharsetHandler.java +++ b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/charset/OracleCharsetHandler.java @@ -49,9 +49,8 @@ class OracleCharsetHandler extends CharsetHandler { private void expectUtf8(Connection connection) throws SQLException { // Oracle does not allow to override character set on tables. Only global charset is verified. String charset = getSqlExecutor().selectSingleString(connection, "select value from nls_database_parameters where parameter='NLS_CHARACTERSET'"); - String sort = getSqlExecutor().selectSingleString(connection, "select value from nls_database_parameters where parameter='NLS_SORT'"); - if (!containsIgnoreCase(charset, UTF8) || !"BINARY".equalsIgnoreCase(sort)) { - throw MessageException.of(format("Oracle must be have UTF8 charset and BINARY sort. NLS_CHARACTERSET is %s and NLS_SORT is %s.", charset, sort)); + if (!containsIgnoreCase(charset, UTF8)) { + throw MessageException.of(format("Oracle NLS_CHARACTERSET does not support UTF8: %s", charset)); } } } diff --git a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/charset/OracleCharsetHandlerTest.java b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/charset/OracleCharsetHandlerTest.java index bc0dea3d432..621cc1ec654 100644 --- a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/charset/OracleCharsetHandlerTest.java +++ b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/charset/OracleCharsetHandlerTest.java @@ -22,7 +22,7 @@ package org.sonar.server.platform.db.migration.charset; import java.sql.Connection; import java.sql.SQLException; import java.util.Collections; -import java.util.List; +import javax.annotation.Nullable; import org.junit.Rule; import org.junit.Test; import org.junit.rules.ExpectedException; @@ -46,7 +46,7 @@ public class OracleCharsetHandlerTest { @Test public void fresh_install_verifies_utf8_charset() throws Exception { - answerSql(singletonList(new String[] {"UTF8"}), singletonList(new String[] {"BINARY"})); + answerCharset("UTF8"); underTest.handle(connection, DatabaseCharsetChecker.State.FRESH_INSTALL); } @@ -60,37 +60,24 @@ public class OracleCharsetHandlerTest { @Test public void fresh_install_supports_al32utf8() throws Exception { - answerSql( - singletonList(new String[] {"AL32UTF8"}), singletonList(new String[] {"BINARY"})); + answerCharset("AL32UTF8"); underTest.handle(connection, DatabaseCharsetChecker.State.FRESH_INSTALL); } @Test public void fresh_install_fails_if_charset_is_not_utf8() throws Exception { - answerSql( - singletonList(new String[] {"LATIN"}), singletonList(new String[] {"BINARY"})); + answerCharset("LATIN"); expectedException.expect(MessageException.class); - expectedException.expectMessage("Oracle must be have UTF8 charset and BINARY sort. NLS_CHARACTERSET is LATIN and NLS_SORT is BINARY."); - - underTest.handle(connection, DatabaseCharsetChecker.State.FRESH_INSTALL); - } - - @Test - public void fresh_install_fails_if_not_case_sensitive() throws Exception { - answerSql( - singletonList(new String[] {"UTF8"}), singletonList(new String[] {"LINGUISTIC"})); - - expectedException.expect(MessageException.class); - expectedException.expectMessage("Oracle must be have UTF8 charset and BINARY sort. NLS_CHARACTERSET is UTF8 and NLS_SORT is LINGUISTIC."); + expectedException.expectMessage("Oracle NLS_CHARACTERSET does not support UTF8: LATIN"); underTest.handle(connection, DatabaseCharsetChecker.State.FRESH_INSTALL); } @Test public void fails_if_can_not_get_charset() throws Exception { - answerSql(Collections.emptyList(), Collections.emptyList()); + answerCharset(null); expectedException.expect(MessageException.class); @@ -103,7 +90,8 @@ public class OracleCharsetHandlerTest { verifyZeroInteractions(sqlExecutor); } - private void answerSql(List<String[]> firstRequest, List<String[]>... otherRequests) throws SQLException { - when(sqlExecutor.select(any(Connection.class), anyString(), any(SqlExecutor.StringsConverter.class))).thenReturn(firstRequest, otherRequests); + private void answerCharset(@Nullable String charset) throws SQLException { + when(sqlExecutor.select(any(Connection.class), anyString(), any(SqlExecutor.StringsConverter.class))) + .thenReturn(charset == null ? Collections.emptyList() : singletonList(new String[] {charset})); } } |