Permalink
Browse files

SONAR-2956 Support Boolean type with Derby

- Change DDL to use BOOLEAN instead of SMALLINT
- Modify Hibernate dialect
- Modify activerecord-jdbc-adapter
  (ideas were taken from arjdbc/postgresql/adapter.rb)
- Use Derby for unit tests instead of HSQL and fix incorrect tests
  • Loading branch information...
Godin committed Oct 28, 2011
1 parent 862ef49 commit 6e9ec5e893b586d1e7e92d00c30d5a2111ef5e05
Showing with 219 additions and 118 deletions.
  1. +13 −8 ...r-dbcleaner-plugin/src/test/java/org/sonar/plugins/dbcleaner/period/DefaultPeriodCleanerTest.java
  2. +2 −1 ...-dbcleaner-plugin/src/test/java/org/sonar/plugins/dbcleaner/purges/PurgeDeletedResourcesTest.java
  3. +5 −5 ...est/resources/org/sonar/batch/phases/UpdateStatusJobTest/shouldNotEnableSnapshotWhenNotLatest.xml
  4. +7 −0 sonar-core/src/main/java/org/sonar/jpa/dialect/Derby.java
  5. +0 −1 sonar-core/src/main/java/org/sonar/jpa/session/MemoryDatabaseConnector.java
  6. +0 −24 sonar-core/src/main/resources/org/sonar/persistence/model/DuplicationMapper-derby.xml
  7. +15 −15 sonar-core/src/main/resources/org/sonar/persistence/rows-derby.sql
  8. +13 −13 sonar-core/src/main/resources/org/sonar/persistence/schema-derby.ddl
  9. +0 −3 sonar-core/src/test/java/org/sonar/jpa/entity/SchemaMigrationTest.java
  10. +56 −17 sonar-core/src/test/java/org/sonar/jpa/test/AbstractDbUnitTestCase.java
  11. +63 −16 sonar-core/src/test/java/org/sonar/persistence/InMemoryDatabase.java
  12. +34 −4 ...r/src/main/webapp/WEB-INF/vendor/gems/activerecord-jdbc-adapter-1.1.3/lib/arjdbc/derby/adapter.rb
  13. +2 −2 sonar-server/src/test/java/org/sonar/server/configuration/ProfilesManagerTest.java
  14. +3 −3 ...st/resources/org/sonar/server/startup/RegisterRulesTest/disableDeprecatedActiveRuleParameters.xml
  15. +1 −1 ...er/src/test/resources/org/sonar/server/startup/RegisterRulesTest/disableDeprecatedActiveRules.xml
  16. +1 −1 ...r-server/src/test/resources/org/sonar/server/startup/RegisterRulesTest/disableDeprecatedRules.xml
  17. +1 −1 sonar-server/src/test/resources/org/sonar/server/startup/RegisterRulesTest/shared.xml
  18. +1 −1 sonar-server/src/test/resources/org/sonar/server/startup/RegisterRulesTest/updadeRuleFields.xml
  19. +2 −2 sonar-server/src/test/resources/org/sonar/server/startup/RegisterRulesTest/updateRuleParameters.xml
@@ -32,16 +32,14 @@
DefaultPeriodCleaner cleaner;
+ Project project;
+ Periods periods;
+
@Before
public void init() {
cleaner = new DefaultPeriodCleaner(getSession());
- }
-
- @Test
- public void integrationTests() {
- setupData("dbContent");
- Project project = new Project("myproject");
+ project = new Project("myproject");
project.setConfiguration(new PropertiesConfiguration());
GregorianCalendar calendar = new GregorianCalendar(2010, 10, 1);
@@ -50,12 +48,19 @@ public void integrationTests() {
Date dateToStartKeepingOneSnapshotByMonth = calendar.getTime();
calendar.set(2010, 2, 1);
Date dateToStartDeletingAllSnapshots = calendar.getTime();
- Periods periods = new Periods(dateToStartKeepingOneSnapshotByWeek, dateToStartKeepingOneSnapshotByMonth, dateToStartDeletingAllSnapshots);
+ periods = new Periods(dateToStartKeepingOneSnapshotByWeek, dateToStartKeepingOneSnapshotByMonth, dateToStartDeletingAllSnapshots);
+ }
+ @Test
+ public void integrationTests() {
+ setupData("dbContent");
cleaner.purge(project, 1010, periods);
checkTables("dbContent", "snapshots");
+ }
- //After a first run, no more snapshot should be deleted
+ @Test
+ public void test() {
+ // After a first run, no more snapshot should be deleted
setupData("dbContent-result");
cleaner.purge(project, 1010, periods);
checkTables("dbContent");
@@ -32,7 +32,8 @@ public void purgeDeletedResources() throws SQLException {
setupData("sharedFixture", "purgeDeletedResources");
final Connection c = getConnection().getConnection();
- c.prepareStatement("SET REFERENTIAL_INTEGRITY FALSE; ").execute();
+ // TODO Godin: next line was here with HSQL
+ //c.prepareStatement("SET REFERENTIAL_INTEGRITY FALSE; ").execute();
c.prepareStatement("delete from projects where id=3").executeUpdate();
c.commit();
@@ -30,28 +30,28 @@
<!-- the snapshot to process : before last snapshot -->
<snapshots period1_mode="[null]" period1_param="[null]" period1_date="[null]" period2_mode="[null]" period2_param="[null]" period2_date="[null]" period3_mode="[null]" period3_param="[null]" period3_date="[null]" period4_mode="[null]" period4_param="[null]" period4_date="[null]" period5_mode="[null]" period5_param="[null]" period5_date="[null]" depth="[null]" id="6" scope="PRJ" qualifier="TRK" created_at="2005-10-01 00:00:00.00" version="[null]"
project_id="1"
- parent_snapshot_id="[null]" root_project_id="[null]" root_snapshot_id="[null]" status="[null]"
+ parent_snapshot_id="[null]" root_project_id="[null]" root_snapshot_id="[null]" status="U"
islast="false"
path="[null]"/>
<snapshots period1_mode="[null]" period1_param="[null]" period1_date="[null]" period2_mode="[null]" period2_param="[null]" period2_date="[null]" period3_mode="[null]" period3_param="[null]" period3_date="[null]" period4_mode="[null]" period4_param="[null]" period4_date="[null]" period5_mode="[null]" period5_param="[null]" period5_date="[null]" depth="[null]" id="7" scope="PRJ" qualifier="TRK" created_at="2005-10-01 00:00:00.00" version="[null]"
project_id="2"
- parent_snapshot_id="6" root_project_id="[null]" root_snapshot_id="6" status="[null]" islast="false"
+ parent_snapshot_id="6" root_project_id="[null]" root_snapshot_id="6" status="U" islast="false"
path="[null]"/>
<snapshots period1_mode="[null]" period1_param="[null]" period1_date="[null]" period2_mode="[null]" period2_param="[null]" period2_date="[null]" period3_mode="[null]" period3_param="[null]" period3_date="[null]" period4_mode="[null]" period4_param="[null]" period4_date="[null]" period5_mode="[null]" period5_param="[null]" period5_date="[null]" depth="[null]" id="8" scope="DIR" qualifier="PAC" created_at="2005-10-01 00:00:00.00" version="[null]"
project_id="3"
- parent_snapshot_id="7" root_project_id="[null]" root_snapshot_id="6" status="[null]" islast="false"
+ parent_snapshot_id="7" root_project_id="[null]" root_snapshot_id="6" status="U" islast="false"
path="[null]"/>
<snapshots period1_mode="[null]" period1_param="[null]" period1_date="[null]" period2_mode="[null]" period2_param="[null]" period2_date="[null]" period3_mode="[null]" period3_param="[null]" period3_date="[null]" period4_mode="[null]" period4_param="[null]" period4_date="[null]" period5_mode="[null]" period5_param="[null]" period5_date="[null]" depth="[null]" id="9" scope="FIL" qualifier="CLA" created_at="2005-10-01 00:00:00.00" version="[null]"
project_id="4"
- parent_snapshot_id="8" root_project_id="[null]" root_snapshot_id="6" status="[null]" islast="false"
+ parent_snapshot_id="8" root_project_id="[null]" root_snapshot_id="6" status="U" islast="false"
path="[null]"/>
<snapshots period1_mode="[null]" period1_param="[null]" period1_date="[null]" period2_mode="[null]" period2_param="[null]" period2_date="[null]" period3_mode="[null]" period3_param="[null]" period3_date="[null]" period4_mode="[null]" period4_param="[null]" period4_date="[null]" period5_mode="[null]" period5_param="[null]" period5_date="[null]" depth="[null]" id="10" scope="FIL" qualifier="CLA" created_at="2005-10-01 00:00:00.00" version="[null]"
project_id="5"
- parent_snapshot_id="9" root_project_id="[null]" root_snapshot_id="6" status="[null]" islast="false"
+ parent_snapshot_id="9" root_project_id="[null]" root_snapshot_id="6" status="U" islast="false"
path="[null]"/>
@@ -60,6 +60,13 @@ public DerbyWithDecimalDialect() {
// Not possible to do alter column types in Derby
registerColumnType(Types.BIGINT, "integer");
+
+ registerColumnType(Types.BIT, "boolean");
+ }
+
+ @Override
+ public String toBooleanValueString(boolean bool) {
+ return bool ? "true" : "false";
}
/**
@@ -23,7 +23,6 @@
import org.sonar.persistence.Database;
import javax.persistence.EntityManager;
-import java.sql.Connection;
public class MemoryDatabaseConnector extends DefaultDatabaseConnector {
private int version;
@@ -1,24 +0,0 @@
-<?xml version="1.0" encoding="UTF-8" ?>
-<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
-
-<mapper namespace="org.sonar.persistence.model.DuplicationMapper">
-
- <select id="selectCandidates" parameterType="map" resultType="DuplicationUnit">
- SELECT DISTINCT to_blocks.hash hash, res.kee resourceKey, to_blocks.index_in_file indexInFile, to_blocks.start_line startLine, to_blocks.end_line endLine
- FROM duplications_index to_blocks, duplications_index from_blocks, snapshots snapshot, projects res
- WHERE from_blocks.snapshot_id = #{resource_snapshot_id}
- AND to_blocks.hash = from_blocks.hash
- AND to_blocks.snapshot_id = snapshot.id
- AND snapshot.islast = 1
- AND snapshot.project_id = res.id
- <if test="last_project_snapshot_id != null">
- AND to_blocks.project_snapshot_id != #{last_project_snapshot_id}
- </if>
- </select>
-
- <insert id="insert" parameterType="DuplicationUnit" keyColumn="id" useGeneratedKeys="true">
- INSERT INTO duplications_index (snapshot_id, project_snapshot_id, hash, index_in_file, start_line, end_line)
- VALUES (#{snapshotId}, #{projectSnapshotId}, #{hash}, #{indexInFile}, #{startLine}, #{endLine})
- </insert>
-
-</mapper>
@@ -15,7 +15,7 @@ INSERT INTO CRITERIA(ID, FILTER_ID, FAMILY, KEE, OPERATOR, VALUE, TEXT_VALUE, VA
INSERT INTO CRITERIA(ID, FILTER_ID, FAMILY, KEE, OPERATOR, VALUE, TEXT_VALUE, VARIATION) VALUES (3, 3, 'qualifier', null, '=', null, 'VW,SVW,TRK,BRC,DIR,PAC,FIL,CLA,UTS,LIB', null);
ALTER TABLE CRITERIA ALTER COLUMN ID RESTART WITH 4;
-INSERT INTO DASHBOARDS(ID, USER_ID, NAME, DESCRIPTION, COLUMN_LAYOUT, SHARED, CREATED_AT, UPDATED_AT) VALUES (1, null, 'Dashboard', 'Default dashboard', '50%-50%', 1, '2011-09-26 22:27:55.0', '2011-09-26 22:27:55.0');
+INSERT INTO DASHBOARDS(ID, USER_ID, NAME, DESCRIPTION, COLUMN_LAYOUT, SHARED, CREATED_AT, UPDATED_AT) VALUES (1, null, 'Dashboard', 'Default dashboard', '50%-50%', true, '2011-09-26 22:27:55.0', '2011-09-26 22:27:55.0');
ALTER TABLE DASHBOARDS ALTER COLUMN ID RESTART WITH 2;
INSERT INTO FILTER_COLUMNS(ID, FILTER_ID, FAMILY, KEE, SORT_DIRECTION, ORDER_INDEX, VARIATION) VALUES (1, 1, 'metric', 'alert_status', null, 1, null);
@@ -35,9 +35,9 @@ INSERT INTO FILTER_COLUMNS(ID, FILTER_ID, FAMILY, KEE, SORT_DIRECTION, ORDER_IND
INSERT INTO FILTER_COLUMNS(ID, FILTER_ID, FAMILY, KEE, SORT_DIRECTION, ORDER_INDEX, VARIATION) VALUES (15, 3, 'date', null, null, 5, null);
ALTER TABLE FILTER_COLUMNS ALTER COLUMN ID RESTART WITH 16;
-INSERT INTO FILTERS(ID, NAME, USER_ID, SHARED, FAVOURITES, RESOURCE_ID, DEFAULT_VIEW, PAGE_SIZE, PERIOD_INDEX) VALUES (1, 'Projects', null, 1, 0, null, 'list', null, null);
-INSERT INTO FILTERS(ID, NAME, USER_ID, SHARED, FAVOURITES, RESOURCE_ID, DEFAULT_VIEW, PAGE_SIZE, PERIOD_INDEX) VALUES (2, 'Treemap', null, 1, 0, null, 'treemap', null, null);
-INSERT INTO FILTERS(ID, NAME, USER_ID, SHARED, FAVOURITES, RESOURCE_ID, DEFAULT_VIEW, PAGE_SIZE, PERIOD_INDEX) VALUES (3, 'My favourites', null, 1, 1, null, 'list', null, null);
+INSERT INTO FILTERS(ID, NAME, USER_ID, SHARED, FAVOURITES, RESOURCE_ID, DEFAULT_VIEW, PAGE_SIZE, PERIOD_INDEX) VALUES (1, 'Projects', null, true, false, null, 'list', null, null);
+INSERT INTO FILTERS(ID, NAME, USER_ID, SHARED, FAVOURITES, RESOURCE_ID, DEFAULT_VIEW, PAGE_SIZE, PERIOD_INDEX) VALUES (2, 'Treemap', null, true, false, null, 'treemap', null, null);
+INSERT INTO FILTERS(ID, NAME, USER_ID, SHARED, FAVOURITES, RESOURCE_ID, DEFAULT_VIEW, PAGE_SIZE, PERIOD_INDEX) VALUES (3, 'My favourites', null, true, true, null, 'list', null, null);
ALTER TABLE FILTERS ALTER COLUMN ID RESTART WITH 4;
INSERT INTO GROUP_ROLES(ID, GROUP_ID, RESOURCE_ID, ROLE) VALUES (1, 1, null, 'admin');
@@ -167,15 +167,15 @@ INSERT INTO SCHEMA_MIGRATIONS(VERSION) VALUES ('221');
INSERT INTO USERS(ID, LOGIN, NAME, EMAIL, CRYPTED_PASSWORD, SALT, CREATED_AT, UPDATED_AT, REMEMBER_TOKEN, REMEMBER_TOKEN_EXPIRES_AT) VALUES (1, 'admin', 'Administrator', '', 'a373a0e667abb2604c1fd571eb4ad47fe8cc0878', '48bc4b0d93179b5103fd3885ea9119498e9d161b', '2011-09-26 22:27:48.0', '2011-09-26 22:27:48.0', null, null);
ALTER TABLE USERS ALTER COLUMN ID RESTART WITH 2;
-INSERT INTO WIDGETS(ID, DASHBOARD_ID, WIDGET_KEY, NAME, DESCRIPTION, COLUMN_INDEX, ROW_INDEX, CONFIGURED, CREATED_AT, UPDATED_AT) VALUES (1, 1, 'size', 'Size metrics', null, 1, 1, 1, '2011-09-26 22:27:55.0', '2011-09-26 22:27:55.0');
-INSERT INTO WIDGETS(ID, DASHBOARD_ID, WIDGET_KEY, NAME, DESCRIPTION, COLUMN_INDEX, ROW_INDEX, CONFIGURED, CREATED_AT, UPDATED_AT) VALUES (2, 1, 'comments_duplications', 'Comments duplications', null, 1, 2, 1, '2011-09-26 22:27:55.0', '2011-09-26 22:27:55.0');
-INSERT INTO WIDGETS(ID, DASHBOARD_ID, WIDGET_KEY, NAME, DESCRIPTION, COLUMN_INDEX, ROW_INDEX, CONFIGURED, CREATED_AT, UPDATED_AT) VALUES (3, 1, 'complexity', 'Complexity', null, 1, 3, 1, '2011-09-26 22:27:55.0', '2011-09-26 22:27:55.0');
-INSERT INTO WIDGETS(ID, DASHBOARD_ID, WIDGET_KEY, NAME, DESCRIPTION, COLUMN_INDEX, ROW_INDEX, CONFIGURED, CREATED_AT, UPDATED_AT) VALUES (4, 1, 'code_coverage', 'Code coverage', null, 1, 4, 1, '2011-09-26 22:27:55.0', '2011-09-26 22:27:55.0');
-INSERT INTO WIDGETS(ID, DASHBOARD_ID, WIDGET_KEY, NAME, DESCRIPTION, COLUMN_INDEX, ROW_INDEX, CONFIGURED, CREATED_AT, UPDATED_AT) VALUES (5, 1, 'events', 'Events', null, 1, 5, 1, '2011-09-26 22:27:56.0', '2011-09-26 22:27:56.0');
-INSERT INTO WIDGETS(ID, DASHBOARD_ID, WIDGET_KEY, NAME, DESCRIPTION, COLUMN_INDEX, ROW_INDEX, CONFIGURED, CREATED_AT, UPDATED_AT) VALUES (6, 1, 'description', 'Description', null, 1, 6, 1, '2011-09-26 22:27:56.0', '2011-09-26 22:27:56.0');
-INSERT INTO WIDGETS(ID, DASHBOARD_ID, WIDGET_KEY, NAME, DESCRIPTION, COLUMN_INDEX, ROW_INDEX, CONFIGURED, CREATED_AT, UPDATED_AT) VALUES (7, 1, 'rules', 'Rules', null, 2, 1, 1, '2011-09-26 22:27:56.0', '2011-09-26 22:27:56.0');
-INSERT INTO WIDGETS(ID, DASHBOARD_ID, WIDGET_KEY, NAME, DESCRIPTION, COLUMN_INDEX, ROW_INDEX, CONFIGURED, CREATED_AT, UPDATED_AT) VALUES (8, 1, 'alerts', 'Alerts', null, 2, 2, 1, '2011-09-26 22:27:56.0', '2011-09-26 22:27:56.0');
-INSERT INTO WIDGETS(ID, DASHBOARD_ID, WIDGET_KEY, NAME, DESCRIPTION, COLUMN_INDEX, ROW_INDEX, CONFIGURED, CREATED_AT, UPDATED_AT) VALUES (9, 1, 'file_design', 'File design', null, 2, 3, 1, '2011-09-26 22:27:56.0', '2011-09-26 22:27:56.0');
-INSERT INTO WIDGETS(ID, DASHBOARD_ID, WIDGET_KEY, NAME, DESCRIPTION, COLUMN_INDEX, ROW_INDEX, CONFIGURED, CREATED_AT, UPDATED_AT) VALUES (10, 1, 'package_design', 'Package design', null, 2, 4, 1, '2011-09-26 22:27:56.0', '2011-09-26 22:27:56.0');
-INSERT INTO WIDGETS(ID, DASHBOARD_ID, WIDGET_KEY, NAME, DESCRIPTION, COLUMN_INDEX, ROW_INDEX, CONFIGURED, CREATED_AT, UPDATED_AT) VALUES (11, 1, 'ckjm', 'CKJM', null, 2, 5, 1, '2011-09-26 22:27:56.0', '2011-09-26 22:27:56.0');
+INSERT INTO WIDGETS(ID, DASHBOARD_ID, WIDGET_KEY, NAME, DESCRIPTION, COLUMN_INDEX, ROW_INDEX, CONFIGURED, CREATED_AT, UPDATED_AT) VALUES (1, 1, 'size', 'Size metrics', null, 1, 1, true, '2011-09-26 22:27:55.0', '2011-09-26 22:27:55.0');
+INSERT INTO WIDGETS(ID, DASHBOARD_ID, WIDGET_KEY, NAME, DESCRIPTION, COLUMN_INDEX, ROW_INDEX, CONFIGURED, CREATED_AT, UPDATED_AT) VALUES (2, 1, 'comments_duplications', 'Comments duplications', null, 1, 2, true, '2011-09-26 22:27:55.0', '2011-09-26 22:27:55.0');
+INSERT INTO WIDGETS(ID, DASHBOARD_ID, WIDGET_KEY, NAME, DESCRIPTION, COLUMN_INDEX, ROW_INDEX, CONFIGURED, CREATED_AT, UPDATED_AT) VALUES (3, 1, 'complexity', 'Complexity', null, 1, 3, true, '2011-09-26 22:27:55.0', '2011-09-26 22:27:55.0');
+INSERT INTO WIDGETS(ID, DASHBOARD_ID, WIDGET_KEY, NAME, DESCRIPTION, COLUMN_INDEX, ROW_INDEX, CONFIGURED, CREATED_AT, UPDATED_AT) VALUES (4, 1, 'code_coverage', 'Code coverage', null, 1, 4, true, '2011-09-26 22:27:55.0', '2011-09-26 22:27:55.0');
+INSERT INTO WIDGETS(ID, DASHBOARD_ID, WIDGET_KEY, NAME, DESCRIPTION, COLUMN_INDEX, ROW_INDEX, CONFIGURED, CREATED_AT, UPDATED_AT) VALUES (5, 1, 'events', 'Events', null, 1, 5, true, '2011-09-26 22:27:56.0', '2011-09-26 22:27:56.0');
+INSERT INTO WIDGETS(ID, DASHBOARD_ID, WIDGET_KEY, NAME, DESCRIPTION, COLUMN_INDEX, ROW_INDEX, CONFIGURED, CREATED_AT, UPDATED_AT) VALUES (6, 1, 'description', 'Description', null, 1, 6, true, '2011-09-26 22:27:56.0', '2011-09-26 22:27:56.0');
+INSERT INTO WIDGETS(ID, DASHBOARD_ID, WIDGET_KEY, NAME, DESCRIPTION, COLUMN_INDEX, ROW_INDEX, CONFIGURED, CREATED_AT, UPDATED_AT) VALUES (7, 1, 'rules', 'Rules', null, 2, 1, true, '2011-09-26 22:27:56.0', '2011-09-26 22:27:56.0');
+INSERT INTO WIDGETS(ID, DASHBOARD_ID, WIDGET_KEY, NAME, DESCRIPTION, COLUMN_INDEX, ROW_INDEX, CONFIGURED, CREATED_AT, UPDATED_AT) VALUES (8, 1, 'alerts', 'Alerts', null, 2, 2, true, '2011-09-26 22:27:56.0', '2011-09-26 22:27:56.0');
+INSERT INTO WIDGETS(ID, DASHBOARD_ID, WIDGET_KEY, NAME, DESCRIPTION, COLUMN_INDEX, ROW_INDEX, CONFIGURED, CREATED_AT, UPDATED_AT) VALUES (9, 1, 'file_design', 'File design', null, 2, 3, true, '2011-09-26 22:27:56.0', '2011-09-26 22:27:56.0');
+INSERT INTO WIDGETS(ID, DASHBOARD_ID, WIDGET_KEY, NAME, DESCRIPTION, COLUMN_INDEX, ROW_INDEX, CONFIGURED, CREATED_AT, UPDATED_AT) VALUES (10, 1, 'package_design', 'Package design', null, 2, 4, true, '2011-09-26 22:27:56.0', '2011-09-26 22:27:56.0');
+INSERT INTO WIDGETS(ID, DASHBOARD_ID, WIDGET_KEY, NAME, DESCRIPTION, COLUMN_INDEX, ROW_INDEX, CONFIGURED, CREATED_AT, UPDATED_AT) VALUES (11, 1, 'ckjm', 'CKJM', null, 2, 5, true, '2011-09-26 22:27:56.0', '2011-09-26 22:27:56.0');
ALTER TABLE WIDGETS ALTER COLUMN ID RESTART WITH 12;
Oops, something went wrong.

0 comments on commit 6e9ec5e

Please sign in to comment.