<dependency>
<groupId>postgresql</groupId>
<artifactId>postgresql</artifactId>
- <!-- do not upgrade to version 9.0-801.jdbc4, not compatible with Java 5 -->
- <version>9.0-801.jdbc3</version>
+ <!-- do not upgrade to version 9.1-901.jdbc4, not compatible with Java 5 -->
+ <version>9.1-901.jdbc3</version>
</dependency>
<dependency>
<groupId>net.sourceforge.jtds</groupId>
private void initDatasource() throws Exception {// NOSONAR this exception is thrown by BasicDataSourceFactory
// but it's correctly caught by start()
-
LOG.info("Create JDBC datasource to url " + properties.getProperty(DatabaseProperties.PROP_URL, DEFAULT_URL));
datasource = (BasicDataSource) BasicDataSourceFactory.createDataSource(extractCommonsDbcpProperties(properties));
-
- String initStatement = dialect.getConnectionInitStatement(getSchema());
- if (StringUtils.isNotBlank(initStatement)) {
- datasource.setConnectionInitSqls(Arrays.asList(initStatement));
- }
-
+ datasource.setConnectionInitSqls(dialect.getConnectionInitStatements(getSchema()));
datasource.setValidationQuery(dialect.getValidationQuery());
}
*/
package org.sonar.core.persistence.dialect;
+import java.util.Collections;
+import java.util.List;
+
/**
* @since 3.2
*/
public final String getValidationQuery() {
return validationQuery;
}
+
+ public List<String> getConnectionInitStatements(String schema) {
+ return Collections.emptyList();
+ }
}
*/
package org.sonar.core.persistence.dialect;
+import java.util.List;
+
/**
* @since 1.12
*/
*/
String getDefaultDriverClassName();
- String getConnectionInitStatement(String schema);
+ List<String> getConnectionInitStatements(String schema);
/**
* @since 2.14
return StringUtils.startsWithIgnoreCase(jdbcConnectionURL, "jdbc:h2:");
}
- public String getConnectionInitStatement(String schema) {
- return null;
- }
}
}
}
}
-
- public String getConnectionInitStatement(String schema) {
- return null;
- }
}
registerColumnType(Types.BLOB, "blob");
}
}
-
- public String getConnectionInitStatement(String schema) {
- return null;
- }
}
*/
package org.sonar.core.persistence.dialect;
+import com.google.common.collect.Lists;
import org.apache.commons.lang.StringUtils;
import org.hibernate.dialect.Oracle10gDialect;
import org.sonar.api.database.DatabaseProperties;
import java.sql.Types;
+import java.util.List;
/**
* @since 1.12
}
}
- public String getConnectionInitStatement(String schema) {
+ @Override
+ public List<String> getConnectionInitStatements(String schema) {
+ List<String> statements = Lists.newArrayList();
if (StringUtils.isNotBlank(schema)) {
- return "ALTER SESSION SET CURRENT_SCHEMA = \"" + schema + "\"";
+ statements.add("ALTER SESSION SET CURRENT_SCHEMA = \"" + schema + "\"");
}
- return null;
+ return statements;
}
}
*/
package org.sonar.core.persistence.dialect;
+import com.google.common.collect.Lists;
import org.apache.commons.lang.StringUtils;
import org.hibernate.dialect.PostgreSQLDialect;
import java.sql.Types;
+import java.util.List;
/**
* @since 1.12
}
}
- public String getConnectionInitStatement(String schema) {
+ @Override
+ public List<String> getConnectionInitStatements(String schema) {
+ List<String> statements = Lists.newArrayList("SET standard_conforming_strings=on", "SET backslash_quote=off");
if (StringUtils.isNotBlank(schema)) {
- return "SET SEARCH_PATH TO " + schema;
+ statements.add("SET SEARCH_PATH TO " + schema);
}
- return null;
+ return statements;
}
}
import org.junit.Test;
+import java.util.List;
+
import static org.fest.assertions.Assertions.assertThat;
public class OracleTest {
*/
@Test
public void shouldChangeOracleSchema() {
- String initStatement = oracle.getConnectionInitStatement("my_schema");
+ List<String> initStatements = oracle.getConnectionInitStatements("my_schema");
- assertThat(initStatement).isEqualTo("ALTER SESSION SET CURRENT_SCHEMA = \"my_schema\"");
+ assertThat(initStatements).containsExactly("ALTER SESSION SET CURRENT_SCHEMA = \"my_schema\"");
}
@Test
public void shouldNotChangeOracleSchemaByDefault() {
- assertThat(oracle.getConnectionInitStatement(null)).isNull();
+ assertThat(oracle.getConnectionInitStatements(null)).isEmpty();
}
@Test
*/
package org.sonar.core.persistence.dialect;
-import org.hamcrest.core.Is;
+import org.fest.assertions.Condition;
import org.junit.Test;
+import java.util.List;
+
import static org.fest.assertions.Assertions.assertThat;
-import static org.junit.Assert.assertThat;
public class PostgreSqlTest {
@Test
public void should_avoid_conflict_with_other_schemas() {
- String initStatement = postgreSql.getConnectionInitStatement("my_schema");
+ List<String> initStatements = postgreSql.getConnectionInitStatements("my_schema");
- assertThat(initStatement, Is.is("SET SEARCH_PATH TO my_schema"));
+ assertThat(initStatements).contains("SET SEARCH_PATH TO my_schema");
}
@Test
public void shouldNotChangePostgreSearchPathByDefault() {
- assertThat(postgreSql.getConnectionInitStatement(null)).isNull();
+ for (String statement : postgreSql.getConnectionInitStatements(null)) {
+ assertThat(statement).doesNotMatch("SET SEARCH_PATH .*");
+ }
}
@Test
end
end
+ #sonar
+ # standard_conforming_strings is forced to true in JDBC connection pool (see org.sonar.core.persistence.dialect.PostgreSql)
+ # so double backslashing must be removed
+ def quote_string(s)
+ s.gsub(/'/, "''") # ' (for ruby-mode)
+ end
+ #/sonar
+
+
def escape_bytea(s)
if s
result = ''