aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSimon Brandhof <simon.brandhof@sonarsource.com>2014-10-31 07:48:45 +0100
committerSimon Brandhof <simon.brandhof@sonarsource.com>2014-10-31 07:48:45 +0100
commitaf0457f6e364a67f34e79dbc7c2fc711f2710e24 (patch)
tree22b3e493c47fccd5e21b478b02134b2ade25ba03
parent0907a920140eb956ef6de01c1a70ce535801f15a (diff)
downloadsonarqube-af0457f6e364a67f34e79dbc7c2fc711f2710e24.tar.gz
sonarqube-af0457f6e364a67f34e79dbc7c2fc711f2710e24.zip
SONAR-5605 enable mysql client cursor in mybatis
-rw-r--r--sonar-core/src/main/java/org/sonar/core/persistence/MyBatis.java9
-rw-r--r--sonar-core/src/main/java/org/sonar/core/persistence/dialect/AbstractDialect.java5
-rw-r--r--sonar-core/src/main/java/org/sonar/core/persistence/dialect/Dialect.java2
-rw-r--r--sonar-core/src/main/java/org/sonar/core/persistence/dialect/MySql.java5
-rw-r--r--sonar-core/src/main/resources/org/sonar/core/issue/db/IssueMapper.xml3
-rw-r--r--sonar-core/src/test/java/org/sonar/core/persistence/dialect/H2Test.java23
-rw-r--r--sonar-core/src/test/java/org/sonar/core/persistence/dialect/MySqlTest.java5
-rw-r--r--sonar-core/src/test/java/org/sonar/core/persistence/dialect/OracleTest.java23
-rw-r--r--sonar-core/src/test/java/org/sonar/core/persistence/dialect/PostgreSqlTest.java25
9 files changed, 68 insertions, 32 deletions
diff --git a/sonar-core/src/main/java/org/sonar/core/persistence/MyBatis.java b/sonar-core/src/main/java/org/sonar/core/persistence/MyBatis.java
index ad721c7bf0b..2d0c0d97428 100644
--- a/sonar-core/src/main/java/org/sonar/core/persistence/MyBatis.java
+++ b/sonar-core/src/main/java/org/sonar/core/persistence/MyBatis.java
@@ -55,6 +55,7 @@ import org.sonar.core.measure.db.*;
import org.sonar.core.notification.db.NotificationQueueDto;
import org.sonar.core.notification.db.NotificationQueueMapper;
import org.sonar.core.permission.*;
+import org.sonar.core.persistence.dialect.Dialect;
import org.sonar.core.persistence.migration.v44.Migration44Mapper;
import org.sonar.core.persistence.migration.v45.Migration45Mapper;
import org.sonar.core.persistence.migration.v50.Migration50Mapper;
@@ -100,12 +101,14 @@ public class MyBatis implements BatchComponent, ServerComponent {
Configuration conf = new Configuration();
conf.setEnvironment(new Environment("production", createTransactionFactory(), database.getDataSource()));
- conf.setDatabaseId(database.getDialect().getId());
conf.setUseGeneratedKeys(true);
conf.setLazyLoadingEnabled(false);
conf.setJdbcTypeForNull(JdbcType.NULL);
- conf.getVariables().setProperty("_true", database.getDialect().getTrueSqlValue());
- conf.getVariables().setProperty("_false", database.getDialect().getFalseSqlValue());
+ Dialect dialect = database.getDialect();
+ conf.setDatabaseId(dialect.getId());
+ conf.getVariables().setProperty("_true", dialect.getTrueSqlValue());
+ conf.getVariables().setProperty("_false", dialect.getFalseSqlValue());
+ conf.getVariables().setProperty("_scrollFetchSize", String.valueOf(dialect.getScrollDefaultFetchSize()));
loadAlias(conf, "ActiveDashboard", ActiveDashboardDto.class);
loadAlias(conf, "Author", AuthorDto.class);
diff --git a/sonar-core/src/main/java/org/sonar/core/persistence/dialect/AbstractDialect.java b/sonar-core/src/main/java/org/sonar/core/persistence/dialect/AbstractDialect.java
index a490947d80c..0ba44347446 100644
--- a/sonar-core/src/main/java/org/sonar/core/persistence/dialect/AbstractDialect.java
+++ b/sonar-core/src/main/java/org/sonar/core/persistence/dialect/AbstractDialect.java
@@ -77,4 +77,9 @@ abstract class AbstractDialect implements Dialect {
public List<String> getConnectionInitStatements() {
return Collections.emptyList();
}
+
+ @Override
+ public int getScrollDefaultFetchSize() {
+ return 200;
+ }
}
diff --git a/sonar-core/src/main/java/org/sonar/core/persistence/dialect/Dialect.java b/sonar-core/src/main/java/org/sonar/core/persistence/dialect/Dialect.java
index 0effec959de..e0061b20bf9 100644
--- a/sonar-core/src/main/java/org/sonar/core/persistence/dialect/Dialect.java
+++ b/sonar-core/src/main/java/org/sonar/core/persistence/dialect/Dialect.java
@@ -72,4 +72,6 @@ public interface Dialect {
* @since 3.2
*/
String getValidationQuery();
+
+ int getScrollDefaultFetchSize();
}
diff --git a/sonar-core/src/main/java/org/sonar/core/persistence/dialect/MySql.java b/sonar-core/src/main/java/org/sonar/core/persistence/dialect/MySql.java
index 2c6e0c5a135..ec740155b9f 100644
--- a/sonar-core/src/main/java/org/sonar/core/persistence/dialect/MySql.java
+++ b/sonar-core/src/main/java/org/sonar/core/persistence/dialect/MySql.java
@@ -55,4 +55,9 @@ public class MySql extends AbstractDialect {
registerColumnType(Types.BLOB, "blob");
}
}
+
+ @Override
+ public int getScrollDefaultFetchSize() {
+ return Integer.MIN_VALUE;
+ }
}
diff --git a/sonar-core/src/main/resources/org/sonar/core/issue/db/IssueMapper.xml b/sonar-core/src/main/resources/org/sonar/core/issue/db/IssueMapper.xml
index 57fb48e104c..4c751b3e877 100644
--- a/sonar-core/src/main/resources/org/sonar/core/issue/db/IssueMapper.xml
+++ b/sonar-core/src/main/resources/org/sonar/core/issue/db/IssueMapper.xml
@@ -141,7 +141,8 @@
where i.kee=#{kee}
</select>
- <select id="selectAfterDate" resultType="Issue" fetchSize="200" resultSetType="FORWARD_ONLY">
+ <select id="selectAfterDate" resultType="Issue"
+ fetchSize="${_scrollFetchSize}" resultSetType="FORWARD_ONLY">
select
<include refid="issueColumns"/>
from issues i
diff --git a/sonar-core/src/test/java/org/sonar/core/persistence/dialect/H2Test.java b/sonar-core/src/test/java/org/sonar/core/persistence/dialect/H2Test.java
index d717e1c4509..aa5d0df4995 100644
--- a/sonar-core/src/test/java/org/sonar/core/persistence/dialect/H2Test.java
+++ b/sonar-core/src/test/java/org/sonar/core/persistence/dialect/H2Test.java
@@ -25,25 +25,30 @@ import static org.fest.assertions.Assertions.assertThat;
public class H2Test {
- private H2 h2 = new H2();
+ H2 dialect = new H2();
@Test
public void matchesJdbcURL() {
- assertThat(h2.matchesJdbcURL("jdbc:h2:foo")).isTrue();
- assertThat(h2.matchesJdbcURL("jdbc:hsql:foo")).isFalse();
+ assertThat(dialect.matchesJdbcURL("jdbc:h2:foo")).isTrue();
+ assertThat(dialect.matchesJdbcURL("jdbc:hsql:foo")).isFalse();
}
@Test
public void testBooleanSqlValues() {
- assertThat(h2.getTrueSqlValue()).isEqualTo("true");
- assertThat(h2.getFalseSqlValue()).isEqualTo("false");
+ assertThat(dialect.getTrueSqlValue()).isEqualTo("true");
+ assertThat(dialect.getFalseSqlValue()).isEqualTo("false");
}
@Test
public void should_configure() {
- assertThat(h2.getId()).isEqualTo("h2");
- assertThat(h2.getActiveRecordDialectCode()).isEqualTo(".h2.");
- assertThat(h2.getDefaultDriverClassName()).isEqualTo("org.h2.Driver");
- assertThat(h2.getValidationQuery()).isEqualTo("SELECT 1");
+ assertThat(dialect.getId()).isEqualTo("h2");
+ assertThat(dialect.getActiveRecordDialectCode()).isEqualTo(".h2.");
+ assertThat(dialect.getDefaultDriverClassName()).isEqualTo("org.h2.Driver");
+ assertThat(dialect.getValidationQuery()).isEqualTo("SELECT 1");
+ }
+
+ @Test
+ public void testFetchSizeForScrolling() throws Exception {
+ assertThat(dialect.getScrollDefaultFetchSize()).isEqualTo(200);
}
}
diff --git a/sonar-core/src/test/java/org/sonar/core/persistence/dialect/MySqlTest.java b/sonar-core/src/test/java/org/sonar/core/persistence/dialect/MySqlTest.java
index c276889d8af..eb144f1e715 100644
--- a/sonar-core/src/test/java/org/sonar/core/persistence/dialect/MySqlTest.java
+++ b/sonar-core/src/test/java/org/sonar/core/persistence/dialect/MySqlTest.java
@@ -49,4 +49,9 @@ public class MySqlTest {
assertThat(mySql.getDefaultDriverClassName()).isEqualTo("com.mysql.jdbc.Driver");
assertThat(mySql.getValidationQuery()).isEqualTo("SELECT 1");
}
+
+ @Test
+ public void testFetchSizeForScrolling() throws Exception {
+ assertThat(mySql.getScrollDefaultFetchSize()).isEqualTo(Integer.MIN_VALUE);
+ }
}
diff --git a/sonar-core/src/test/java/org/sonar/core/persistence/dialect/OracleTest.java b/sonar-core/src/test/java/org/sonar/core/persistence/dialect/OracleTest.java
index 9d32fabfb57..28d61afa1f8 100644
--- a/sonar-core/src/test/java/org/sonar/core/persistence/dialect/OracleTest.java
+++ b/sonar-core/src/test/java/org/sonar/core/persistence/dialect/OracleTest.java
@@ -25,25 +25,30 @@ import static org.fest.assertions.Assertions.assertThat;
public class OracleTest {
- private Oracle oracle = new Oracle();
+ Oracle dialect = new Oracle();
@Test
public void matchesJdbcURL() {
- assertThat(oracle.matchesJdbcURL("jdbc:oracle:thin:@localhost/XE")).isTrue();
- assertThat(oracle.matchesJdbcURL("jdbc:hsql:foo")).isFalse();
+ assertThat(dialect.matchesJdbcURL("jdbc:oracle:thin:@localhost/XE")).isTrue();
+ assertThat(dialect.matchesJdbcURL("jdbc:hsql:foo")).isFalse();
}
@Test
public void testBooleanSqlValues() {
- assertThat(oracle.getTrueSqlValue()).isEqualTo("1");
- assertThat(oracle.getFalseSqlValue()).isEqualTo("0");
+ assertThat(dialect.getTrueSqlValue()).isEqualTo("1");
+ assertThat(dialect.getFalseSqlValue()).isEqualTo("0");
}
@Test
public void should_configure() {
- assertThat(oracle.getId()).isEqualTo("oracle");
- assertThat(oracle.getActiveRecordDialectCode()).isEqualTo("oracle");
- assertThat(oracle.getDefaultDriverClassName()).isEqualTo("oracle.jdbc.OracleDriver");
- assertThat(oracle.getValidationQuery()).isEqualTo("SELECT 1 FROM DUAL");
+ assertThat(dialect.getId()).isEqualTo("oracle");
+ assertThat(dialect.getActiveRecordDialectCode()).isEqualTo("oracle");
+ assertThat(dialect.getDefaultDriverClassName()).isEqualTo("oracle.jdbc.OracleDriver");
+ assertThat(dialect.getValidationQuery()).isEqualTo("SELECT 1 FROM DUAL");
+ }
+
+ @Test
+ public void testFetchSizeForScrolling() throws Exception {
+ assertThat(dialect.getScrollDefaultFetchSize()).isEqualTo(200);
}
}
diff --git a/sonar-core/src/test/java/org/sonar/core/persistence/dialect/PostgreSqlTest.java b/sonar-core/src/test/java/org/sonar/core/persistence/dialect/PostgreSqlTest.java
index 5504041ac94..5b62d359d9f 100644
--- a/sonar-core/src/test/java/org/sonar/core/persistence/dialect/PostgreSqlTest.java
+++ b/sonar-core/src/test/java/org/sonar/core/persistence/dialect/PostgreSqlTest.java
@@ -25,31 +25,36 @@ import static org.fest.assertions.Assertions.assertThat;
public class PostgreSqlTest {
- private PostgreSql postgreSql = new PostgreSql();
+ PostgreSql dialect = new PostgreSql();
@Test
public void matchesJdbcURL() {
- assertThat(postgreSql.matchesJdbcURL("jdbc:postgresql://localhost/sonar")).isTrue();
- assertThat(postgreSql.matchesJdbcURL("jdbc:hsql:foo")).isFalse();
+ assertThat(dialect.matchesJdbcURL("jdbc:postgresql://localhost/sonar")).isTrue();
+ assertThat(dialect.matchesJdbcURL("jdbc:hsql:foo")).isFalse();
}
@Test
public void should_set_connection_properties() {
- assertThat(postgreSql.getConnectionInitStatements()).isEqualTo(PostgreSql.INIT_STATEMENTS);
+ assertThat(dialect.getConnectionInitStatements()).isEqualTo(PostgreSql.INIT_STATEMENTS);
}
@Test
public void testBooleanSqlValues() {
- assertThat(postgreSql.getTrueSqlValue()).isEqualTo("true");
- assertThat(postgreSql.getFalseSqlValue()).isEqualTo("false");
+ assertThat(dialect.getTrueSqlValue()).isEqualTo("true");
+ assertThat(dialect.getFalseSqlValue()).isEqualTo("false");
}
@Test
public void should_configure() {
- assertThat(postgreSql.getId()).isEqualTo("postgresql");
- assertThat(postgreSql.getActiveRecordDialectCode()).isEqualTo("postgre");
- assertThat(postgreSql.getDefaultDriverClassName()).isEqualTo("org.postgresql.Driver");
- assertThat(postgreSql.getValidationQuery()).isEqualTo("SELECT 1");
+ assertThat(dialect.getId()).isEqualTo("postgresql");
+ assertThat(dialect.getActiveRecordDialectCode()).isEqualTo("postgre");
+ assertThat(dialect.getDefaultDriverClassName()).isEqualTo("org.postgresql.Driver");
+ assertThat(dialect.getValidationQuery()).isEqualTo("SELECT 1");
+ }
+
+ @Test
+ public void testFetchSizeForScrolling() throws Exception {
+ assertThat(dialect.getScrollDefaultFetchSize()).isEqualTo(200);
}
}