]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-4178 Add triggers on Oracle to emulate identity column
authorJulien HENRY <julien.henry@sonarsource.com>
Mon, 17 Jun 2013 16:38:51 +0000 (18:38 +0200)
committerJulien HENRY <julien.henry@sonarsource.com>
Wed, 19 Jun 2013 15:38:34 +0000 (17:38 +0200)
24 files changed:
sonar-core/src/main/java/org/sonar/core/persistence/DatabaseVersion.java
sonar-core/src/main/resources/org/sonar/core/dashboard/ActiveDashboardMapper.xml
sonar-core/src/main/resources/org/sonar/core/dashboard/DashboardMapper.xml
sonar-core/src/main/resources/org/sonar/core/dashboard/WidgetMapper.xml
sonar-core/src/main/resources/org/sonar/core/dashboard/WidgetPropertyMapper.xml
sonar-core/src/main/resources/org/sonar/core/duplication/DuplicationMapper.xml
sonar-core/src/main/resources/org/sonar/core/graph/jdbc/GraphDtoMapper.xml
sonar-core/src/main/resources/org/sonar/core/issue/db/ActionPlanMapper.xml
sonar-core/src/main/resources/org/sonar/core/issue/db/IssueChangeMapper.xml
sonar-core/src/main/resources/org/sonar/core/issue/db/IssueFilterFavouriteMapper.xml
sonar-core/src/main/resources/org/sonar/core/issue/db/IssueFilterMapper.xml
sonar-core/src/main/resources/org/sonar/core/issue/db/IssueMapper.xml
sonar-core/src/main/resources/org/sonar/core/measure/MeasureFilterMapper.xml
sonar-core/src/main/resources/org/sonar/core/persistence/SemaphoreMapper.xml
sonar-core/src/main/resources/org/sonar/core/persistence/rows-h2.sql
sonar-core/src/main/resources/org/sonar/core/properties/PropertiesMapper.xml
sonar-core/src/main/resources/org/sonar/core/resource/ResourceIndexerMapper.xml
sonar-core/src/main/resources/org/sonar/core/resource/ResourceMapper.xml
sonar-core/src/main/resources/org/sonar/core/source/jdbc/SnapshotDataMapper.xml
sonar-core/src/main/resources/org/sonar/core/template/LoadedTemplateMapper.xml
sonar-core/src/main/resources/org/sonar/core/user/AuthorMapper.xml
sonar-core/src/main/resources/org/sonar/core/user/RoleMapper.xml
sonar-plugin-api/src/main/resources/org/sonar/api/database/model/MeasureMapper.xml
sonar-server/src/main/webapp/WEB-INF/db/migrate/412_add_oracle_id_triggers.rb [new file with mode: 0644]

index f060ae68e5985d4b1986d5dfc35b1c7d211812e6..85fb8a3f1ad77dc9b64ab1f147fb142c08f04584 100644 (file)
@@ -32,7 +32,7 @@ import java.util.List;
  */
 public class DatabaseVersion implements BatchComponent, ServerComponent {
 
-  public static final int LAST_VERSION = 411;
+  public static final int LAST_VERSION = 412;
 
   public static enum Status {
     UP_TO_DATE, REQUIRES_UPGRADE, REQUIRES_DOWNGRADE, FRESH_INSTALL
index 18085d74dade45b4dbfcd1298505bb0d8c473fe8..c62f80dafd6fa8c94d4263318ec0bd2a1d38fce3 100644 (file)
@@ -3,20 +3,11 @@
 
 <mapper namespace="org.sonar.core.dashboard.ActiveDashboardMapper">
 
-  <insert id="insert" parameterType="ActiveDashboard" useGeneratedKeys="true" keyProperty ="id">
+  <insert id="insert" parameterType="ActiveDashboard" keyColumn="id" useGeneratedKeys="true" keyProperty ="id">
     INSERT INTO active_dashboards (dashboard_id, user_id, order_index)
     VALUES (#{dashboardId}, #{userId}, #{orderIndex})
   </insert>
 
-  <!-- Oracle -->
-  <insert id="insert" databaseId="oracle" parameterType="ActiveDashboard" keyColumn="id" useGeneratedKeys="true" keyProperty ="id">
-    <selectKey order="BEFORE" resultType="Long" keyProperty="id" >
-        select active_dashboards_seq.NEXTVAL from DUAL
-    </selectKey>
-    INSERT INTO active_dashboards (id, dashboard_id, user_id, order_index)
-    VALUES (#{id}, #{dashboardId}, #{userId}, #{orderIndex})
-  </insert>
-
   <select id="selectMaxOrderIndexForNullUser" resultType="Integer">
     SELECT MAX(order_index)
     FROM active_dashboards
index b7ab9140f9f5b13b71d17ff8b55230916b3b2497..deb4989bd6f81fd1d44c8520aba2569b90c57aa4 100644 (file)
@@ -8,20 +8,10 @@
     from dashboards WHERE name=#{id} and user_id is null
   </select>
 
-  <insert id="insert" parameterType="Dashboard" useGeneratedKeys="true" keyProperty="id">
+  <insert id="insert" parameterType="Dashboard" keyColumn="id" useGeneratedKeys="true" keyProperty="id">
     INSERT INTO dashboards (user_id, name, description, column_layout, shared, is_global, created_at, updated_at)
     VALUES (#{userId}, #{name}, #{description},
     #{columnLayout}, #{shared}, #{global}, #{createdAt}, #{updatedAt})
   </insert>
 
-  <!-- Oracle -->
-  <insert id="insert" databaseId="oracle" parameterType="Dashboard" keyColumn="id" useGeneratedKeys="true" keyProperty="id">
-    <selectKey order="BEFORE" resultType="Long" keyProperty="id">
-      select dashboards_seq.NEXTVAL from DUAL
-    </selectKey>
-    INSERT INTO dashboards (id, user_id, name, description, column_layout, shared, is_global, created_at, updated_at)
-    VALUES (#{id}, #{userId}, #{name}, #{description},
-    #{columnLayout}, #{shared}, #{global}, #{createdAt}, #{updatedAt})
-  </insert>
-
 </mapper>
index ee2b13ed999297228c59c8f23530045e6cc43880..07f2a323880a7be7b091a8688e005e4d71acdf87 100644 (file)
@@ -3,20 +3,10 @@
 
 <mapper namespace="org.sonar.core.dashboard.WidgetMapper">
 
-  <insert id="insert" parameterType="Widget" useGeneratedKeys="true" keyProperty ="id">
+  <insert id="insert" parameterType="Widget" keyColumn="id" useGeneratedKeys="true" keyProperty ="id">
     INSERT INTO widgets (dashboard_id, widget_key, name, description, column_index, row_index, configured, created_at, updated_at, resource_id)
     VALUES (#{dashboardId}, #{key}, #{name}, #{description}, #{columnIndex}, 
             #{rowIndex}, #{configured}, #{createdAt}, #{updatedAt}, #{resourceId})
   </insert>
 
-  <!-- Oracle -->
-  <insert id="insert" databaseId="oracle" parameterType="Widget" keyColumn="id" useGeneratedKeys="true" keyProperty ="id">
-    <selectKey order="BEFORE" resultType="Long" keyProperty="id" >
-        select widgets_seq.NEXTVAL from DUAL
-    </selectKey>
-    INSERT INTO widgets (id, dashboard_id, widget_key, name, description, column_index, row_index, configured, created_at, updated_at, resource_id)
-    VALUES (#{id}, #{dashboardId}, #{key}, #{name}, #{description}, #{columnIndex}, 
-            #{rowIndex}, #{configured}, #{createdAt}, #{updatedAt}, #{resourceId})
-  </insert>
-
 </mapper>
index ed3cb3e960c8b7c25b94f2dfd14ffa7321a6f82a..deb555dea0e55b0f25929f1daf8d2c2d3a8613e6 100644 (file)
@@ -3,15 +3,9 @@
 
 <mapper namespace="org.sonar.core.dashboard.WidgetPropertyMapper">
 
-  <insert id="insert" parameterType="WidgetProperty" useGeneratedKeys="true" keyProperty="id">
+  <insert id="insert" parameterType="WidgetProperty" keyColumn="id" useGeneratedKeys="true" keyProperty="id">
     INSERT INTO widget_properties (widget_id, kee, text_value)
     VALUES (#{widgetId}, #{key}, #{value})
   </insert>
 
-  <!-- Oracle -->
-  <insert id="insert" databaseId="oracle" parameterType="WidgetProperty" keyColumn="id" useGeneratedKeys="false" keyProperty="id">
-    INSERT INTO widget_properties (id, widget_id, kee, text_value)
-    VALUES (widget_properties_seq.NEXTVAL, #{widgetId}, #{key}, #{value})
-  </insert>
-
 </mapper>
index 4b87e975d429e6edf8927cc56535f8bec546159b..5a97b8247566b445ab9bed269a1a980666e0c310 100644 (file)
     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>
-
-  <!-- Oracle -->
-  <insert id="batchInsert" databaseId="oracle" parameterType="DuplicationUnit" useGeneratedKeys="false">
-    <selectKey order="BEFORE" resultType="Long" keyProperty="id">
-      select duplications_index_seq.NEXTVAL from DUAL
-    </selectKey>
-      INSERT INTO duplications_index (id, snapshot_id, project_snapshot_id, hash, index_in_file, start_line, end_line)
-      VALUES (#{id}, #{snapshotId}, #{projectSnapshotId}, #{hash}, #{indexInFile}, #{startLine}, #{endLine})
-    </insert>
 </mapper>
index ee684f90ddf6f5cd6922ef37b2848622da009849..c7416c87a63153c2e4dc4d8e6a480d35143382fc 100644 (file)
     #{data}, CURRENT_TIMESTAMP, CURRENT_TIMESTAMP)
   </insert>
 
-  <!-- Oracle -->
-  <insert id="insert" databaseId="oracle" parameterType="Graph" useGeneratedKeys="false" keyProperty="id">
-    <selectKey order="BEFORE" resultType="Long" keyProperty="id">
-      select graphs_seq.NEXTVAL from DUAL
-    </selectKey>
-    insert into graphs
-    (id, resource_id, snapshot_id, format, version, perspective, root_vertex_id, data, created_at, updated_at)
-    values (
-    #{id}, #{resourceId}, #{snapshotId}, #{format}, #{version}, #{perspective}, #{rootVertexId},
-    #{data}, CURRENT_TIMESTAMP, CURRENT_TIMESTAMP)
-  </insert>
 </mapper>
 
index 663284e21ac89f8bcbfd7c0bcfe14e751b2139d0..764141ca66bfc2b9787e24946ddfc20803a9c509 100644 (file)
     p.kee as projectKey
   </sql>
 
-  <insert id="insert" parameterType="ActionPlanIssue" useGeneratedKeys="true" keyProperty="id">
+  <insert id="insert" parameterType="ActionPlanIssue" keyColumn="id" useGeneratedKeys="true" keyProperty="id">
     INSERT INTO action_plans (kee, name, description, user_login, project_id, status, deadline, created_at, updated_at)
     VALUES (#{kee}, #{name}, #{description}, #{userLogin}, #{projectId}, #{status}, #{deadLine}, #{createdAt}, #{updatedAt})
   </insert>
 
-  <!-- Oracle -->
-  <insert id="insert" databaseId="oracle" parameterType="ActionPlanIssue" keyColumn="id" useGeneratedKeys="true" keyProperty="id">
-    <selectKey order="BEFORE" resultType="Long" keyProperty="id">
-      select issues_seq.NEXTVAL from DUAL
-    </selectKey>
-    INSERT INTO action_plans (id, kee, name, description, user_login, project_id, status, deadline, created_at, updated_at)
-    VALUES (#{id}, #{kee}, #{name}, #{description}, #{userLogin}, #{projectId}, #{status}, #{deadLine}, #{createdAt}, #{updatedAt})
-  </insert>
-
   <update id="update" parameterType="ActionPlanIssue">
     update action_plans set
     name=#{name},
index d9d778458a0b9bd2eeee0cff57683ad1b88e4da3..f09b9e4794e3d0f16b1957f27ec5ca9501a673e4 100644 (file)
     VALUES (#{kee}, #{issueKey}, #{userLogin}, #{changeType}, #{changeData}, #{createdAt}, #{updatedAt})
   </insert>
 
-  <!-- Oracle -->
-  <insert id="insert" databaseId="oracle" parameterType="IssueChange" keyColumn="id" useGeneratedKeys="false"
-          keyProperty="id">
-    <selectKey order="BEFORE" resultType="Long" keyProperty="id">
-      select issue_changes_seq.NEXTVAL from DUAL
-    </selectKey>
-    INSERT INTO issue_changes (id, kee, issue_key, user_login, change_type, change_data, created_at, updated_at)
-    VALUES (#{id}, #{kee}, #{issueKey}, #{userLogin}, #{changeType}, #{changeData}, #{createdAt}, #{updatedAt})
-  </insert>
-
   <delete id="delete" parameterType="string">
     delete from issue_changes where kee=#{id}
   </delete>
index 80c36ec8c09f7fadfad83ff69bb2f10c75cb9728..f8aaa53f94511d61d8b764e1f2227a68b95474b9 100644 (file)
     </where>
   </select>
 
-  <insert id="insert" parameterType="issueFilterFavourite" useGeneratedKeys="true" keyProperty="id">
+  <insert id="insert" parameterType="issueFilterFavourite" keyColumn="id" useGeneratedKeys="true" keyProperty="id">
     INSERT INTO issue_filter_favourites (user_login, issue_filter_id, created_at)
     VALUES (#{userLogin}, #{issueFilterId}, current_timestamp)
   </insert>
 
-  <!-- Oracle -->
-  <insert id="insert" databaseId="oracle" parameterType="issueFilterFavourite" keyColumn="id" useGeneratedKeys="true" keyProperty="id">
-    <selectKey order="BEFORE" resultType="Long" keyProperty="id">
-      select issue_filter_favourites_seq.NEXTVAL from DUAL
-    </selectKey>
-    INSERT INTO issue_filter_favourites (id, user_login, issue_filter_id, created_at)
-    VALUES (#{id},#{userLogin}, #{issueFilterId}, current_timestamp)
-  </insert>
-
   <delete id="delete" parameterType="int">
     delete from issue_filter_favourites where id=#{id}
   </delete>
index a85abad3bbed50b96a1497c71be778743d9489f1..3e908084468cf8e7f92f11304339416da1af5d83 100644 (file)
     </where>
   </select>
 
-  <insert id="insert" parameterType="IssueFilter" useGeneratedKeys="true" keyProperty="id">
+  <insert id="insert" parameterType="IssueFilter" keyColumn="id" useGeneratedKeys="true" keyProperty="id">
     INSERT INTO issue_filters (name, user_login, shared, description, data, created_at, updated_at)
     VALUES (#{name}, #{userLogin}, #{shared}, #{description}, #{data}, #{createdAt}, #{updatedAt})
   </insert>
 
-  <!-- Oracle -->
-  <insert id="insert" databaseId="oracle" parameterType="IssueFilter" keyColumn="id" useGeneratedKeys="true" keyProperty="id">
-    <selectKey order="BEFORE" resultType="Long" keyProperty="id">
-      select issue_filters_seq.NEXTVAL from DUAL
-    </selectKey>
-    INSERT INTO issue_filters (id, name, user_login, shared, description, data, created_at, updated_at)
-    VALUES (#{id}, #{name}, #{userLogin}, #{shared}, #{description}, #{data}, #{createdAt}, #{updatedAt})
-  </insert>
-
   <update id="update" parameterType="IssueFilter">
     update issue_filters set
     name=#{name},
index 06fa350595e16ec29269cdf0ae5d2cdf131ba2bc..505f9ce267e76eaccbe70a96d375cfa45c65057f 100644 (file)
     #{issueUpdateDate}, #{issueCloseDate}, #{createdAt}, #{updatedAt})
   </insert>
 
-  <!-- Oracle -->
-  <insert id="insert" databaseId="oracle" parameterType="Issue" keyColumn="id" useGeneratedKeys="false"
-          keyProperty="id">
-    <selectKey order="BEFORE" resultType="Long" keyProperty="id">
-      select issues_seq.NEXTVAL from DUAL
-    </selectKey>
-    INSERT INTO issues (id, kee, component_id, root_component_id, rule_id, action_plan_key, severity, manual_severity,
-    message, line, effort_to_fix, status,
-    resolution, checksum, reporter, assignee, author_login, issue_attributes, issue_creation_date, issue_update_date,
-    issue_close_date, created_at, updated_at)
-    VALUES (#{id}, #{kee}, #{componentId}, #{rootComponentId}, #{ruleId}, #{actionPlanKey}, #{severity}, #{manualSeverity},
-    #{message}, #{line}, #{effortToFix}, #{status},
-    #{resolution}, #{checksum}, #{reporter}, #{assignee}, #{authorLogin}, #{issueAttributes}, #{issueCreationDate},
-    #{issueUpdateDate}, #{issueCloseDate}, #{createdAt}, #{updatedAt})
-  </insert>
-
   <!--
     IMPORTANT - invariant columns can't be updated. See IssueDto#toDtoForUpdate()
   -->
index 713fc15f2e4af89add2eb4da2de8b1a0a5e487d0..425b8cc07bdfe98e0da2eb261f3feeb8cd63c5bb 100644 (file)
@@ -8,18 +8,9 @@
     from measure_filters WHERE user_id is null and name=#{id}
   </select>
 
-  <insert id="insert" parameterType="MeasureFilter" useGeneratedKeys="true" keyProperty="id">
+  <insert id="insert" parameterType="MeasureFilter" keyColumn="id" useGeneratedKeys="true" keyProperty="id">
     INSERT INTO measure_filters (name, user_id, shared, description, data, created_at, updated_at)
     VALUES (#{name}, #{userId}, #{shared}, #{description}, #{data}, #{createdAt}, #{updatedAt})
   </insert>
 
-  <!-- Oracle -->
-  <insert id="insert" databaseId="oracle" parameterType="MeasureFilter" keyColumn="id" useGeneratedKeys="true" keyProperty="id">
-    <selectKey order="BEFORE" resultType="Long" keyProperty="id">
-      select measure_filters_seq.NEXTVAL from DUAL
-    </selectKey>
-    INSERT INTO measure_filters (id, name, user_id, shared, description, data, created_at, updated_at)
-    VALUES (#{id}, #{name}, #{userId}, #{shared}, #{description}, #{data}, #{createdAt}, #{updatedAt})
-  </insert>
-
 </mapper>
index 4b9fbb134f41650d435c297d6e134887cb61c9b7..81ed974e32fb200f4e1cdc9465d95633dc3248af 100644 (file)
@@ -8,14 +8,6 @@
     VALUES (#{name}, #{checksum}, current_timestamp, current_timestamp, #{lockedAt})
   </insert>
 
-  <insert id="initialize" databaseId="oracle" parameterType="map" useGeneratedKeys="false">
-    <selectKey order="BEFORE" resultType="Long" keyProperty="id">
-      select semaphores_seq.NEXTVAL from DUAL
-    </selectKey>
-    INSERT INTO semaphores (id, name, checksum, created_at, updated_at, locked_at)
-    VALUES (#{id}, #{name}, #{checksum}, current_timestamp, current_timestamp, #{lockedAt})
-  </insert>
-
   <select id="now" resultType="Date">
     select current_timestamp
   </select>
index 47f7780a0f87b4423de2be505e6c798f650d5e59..1d75faef1a79d2bfeece4e26bfe6f47bf4c602fb 100644 (file)
@@ -171,6 +171,7 @@ INSERT INTO SCHEMA_MIGRATIONS(VERSION) VALUES ('404');
 INSERT INTO SCHEMA_MIGRATIONS(VERSION) VALUES ('405');
 INSERT INTO SCHEMA_MIGRATIONS(VERSION) VALUES ('410');
 INSERT INTO SCHEMA_MIGRATIONS(VERSION) VALUES ('411');
+INSERT INTO SCHEMA_MIGRATIONS(VERSION) VALUES ('412');
 
 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;
index be5da6887f289288afb244f6d496b6416a3018de..d12932595abea10d132f4ee3e2316b7ab509074c 100644 (file)
     VALUES (#{key}, #{resourceId}, #{userId}, #{value})
   </insert>
 
-  <!-- Oracle -->
-  <insert id="insert" databaseId="oracle" parameterType="Property" useGeneratedKeys="false">
-    <selectKey order="BEFORE" resultType="Long" keyProperty="id">
-      select properties_seq.NEXTVAL from DUAL
-    </selectKey>
-    INSERT INTO properties (id, prop_key, resource_id, user_id, text_value)
-    VALUES (#{id}, #{key}, #{resourceId}, #{userId}, #{value})
-  </insert>
-
   <delete id="deleteGlobalProperty" parameterType="string">
     delete from properties where prop_key=#{id} and resource_id is null and user_id is null
   </delete>
index 51fdfe17d1a6feb2ff40e7892c9654e4a456881d..91c494daa4aa9488348cd7b46c7048d6ddddbc8c 100644 (file)
     #{resourceId}, #{rootProjectId}, #{qualifier})
   </insert>
 
-  <!-- Oracle -->
-  <insert id="insert" databaseId="oracle" parameterType="ResourceIndex" useGeneratedKeys="false">
-    <selectKey order="BEFORE" resultType="Long" keyProperty="id">
-      select resource_index_seq.NEXTVAL from DUAL
-    </selectKey>
-    insert into resource_index (id, kee, position, name_size, resource_id, root_project_id, qualifier)
-    values (#{id}, #{key}, #{position}, #{nameSize},
-    #{resourceId}, #{rootProjectId}, #{qualifier})
-  </insert>
-
 </mapper>
 
index 394c9d56b734aa43c270801a3e69ae03d9b03d7c..3a19fe43730b0f69de6b6e14c79c3ec4b1de98a4 100644 (file)
     </where>
   </sql>
 
-  <insert id="insert" parameterType="Resource" useGeneratedKeys="true" keyProperty="id">
+  <insert id="insert" parameterType="Resource" keyColumn="id" useGeneratedKeys="true" keyProperty="id">
     insert into projects
     (name, long_name, description, scope, qualifier, kee, language, root_id, copy_resource_id, person_id, enabled, created_at)
     values (
     )
   </insert>
 
-  <!-- Oracle -->
-  <insert id="insert" databaseId="oracle" parameterType="Resource" useGeneratedKeys="true" keyProperty="id">
-    <selectKey order="BEFORE" resultType="Long" keyProperty="id">
-      select projects_seq.NEXTVAL from DUAL
-    </selectKey>
-    insert into projects
-    (id, name, long_name, description, scope, qualifier, kee, language, root_id, copy_resource_id, person_id, enabled, created_at)
-    values (
-    #{id}, #{name}, #{longName}, #{description}, #{scope}, #{qualifier},
-    #{key}, #{language}, #{rootId}, #{copyResourceId},
-    #{personId}, #{enabled}, #{createdAt}
-    )
-  </insert>
-
   <update id="update" parameterType="Resource">
     update projects set name=#{name}, long_name=#{longName}, description=#{description},
     scope=#{scope}, qualifier=#{qualifier}, kee=#{key},
index 6d92b6fb87801c4ed02c3e7a025cedb27fb190ed..f6474ea516c017c36cd663a1728abccfd53130d4 100644 (file)
     values (
     #{resourceId}, #{snapshotId}, #{data}, #{dataType}, CURRENT_TIMESTAMP, CURRENT_TIMESTAMP)
   </insert>
-
-    <!-- Oracle -->
-    <insert id="insert" databaseId="oracle" parameterType="SnapshotData" useGeneratedKeys="false" keyProperty="id">
-        <selectKey order="BEFORE" resultType="Long" keyProperty="id">
-            select snapshot_data_seq.NEXTVAL from DUAL
-        </selectKey>
-        insert into snapshot_data
-        (id, resource_id, snapshot_id, snapshot_data, data_type, created_at, updated_at)
-        values (
-        #{id}, #{resourceId}, #{snapshotId}, #{data}, #{dataType}, CURRENT_TIMESTAMP, CURRENT_TIMESTAMP)
-    </insert>
 </mapper>
 
index 5b6862e541b1c8605ba48558de5569f1f8949b87..e946a81ba991a2c2269fda4353c97db3ac8f54b8 100644 (file)
     WHERE kee = #{key} AND template_type = #{type}
   </select>
 
-  <insert id="insert" parameterType="LoadedTemplate" useGeneratedKeys="true" keyProperty="id">
+  <insert id="insert" parameterType="LoadedTemplate" keyColumn="id" useGeneratedKeys="true" keyProperty="id">
     INSERT INTO loaded_templates (kee, template_type)
     VALUES (#{key}, #{type})
   </insert>
 
-  <!-- Oracle -->
-  <insert id="insert" databaseId="oracle" parameterType="LoadedTemplate" keyColumn="id" useGeneratedKeys="true" keyProperty="id">
-    <selectKey order="BEFORE" resultType="Long" keyProperty="id">
-      select loaded_templates_seq.NEXTVAL from DUAL
-    </selectKey>
-    INSERT INTO loaded_templates (id, kee, template_type)
-    VALUES (#{id}, #{key}, #{type})
-  </insert>
-
 </mapper>
index 4071f72247bd6055af4da1209fa24b9ac82ed3f8..fbb92585f1080cd602e63415ccb34c9b341de2a2 100644 (file)
     FROM authors WHERE person_id=#{id}
   </select>
 
-  <insert id="insert" parameterType="Author" useGeneratedKeys="true" keyProperty="id">
+  <insert id="insert" parameterType="Author" keyColumn="id" useGeneratedKeys="true" keyProperty="id">
     INSERT INTO authors (person_id, login, created_at, updated_at)
     VALUES (#{personId}, #{login},
     #{createdAt}, #{updatedAt})
   </insert>
 
-  <!-- Oracle -->
-  <insert id="insert" databaseId="oracle" parameterType="Author" useGeneratedKeys="true" keyProperty="id">
-    <selectKey order="BEFORE" resultType="Long" keyProperty="id">
-      select authors_seq.NEXTVAL from DUAL
-    </selectKey>
-    INSERT INTO authors (id, person_id, login, created_at, updated_at)
-    VALUES (#{id}, #{personId}, #{login},
-    #{createdAt}, #{updatedAt})
-  </insert>
-
 </mapper>
index bbef4611eedc835f9a76f4ca75d62e7cfa7473e9..d230d2899a8d5719bb523d1553b41d9d17a5e0aa 100644 (file)
@@ -3,34 +3,16 @@
 
 <mapper namespace="org.sonar.core.user.RoleMapper">
 
-  <insert id="insertGroupRole" parameterType="GroupRole" useGeneratedKeys="true" keyProperty="id">
+  <insert id="insertGroupRole" parameterType="GroupRole" keyColumn="id" useGeneratedKeys="true" keyProperty="id">
     INSERT INTO group_roles (group_id, resource_id, role)
     VALUES (#{groupId}, #{resourceId}, #{role})
   </insert>
 
-  <!-- Oracle -->
-  <insert id="insertGroupRole" databaseId="oracle" parameterType="GroupRole" useGeneratedKeys="true" keyProperty="id">
-    <selectKey order="BEFORE" resultType="Long" keyProperty="id">
-      select group_roles_seq.NEXTVAL from DUAL
-    </selectKey>
-    INSERT INTO group_roles (id, group_id, resource_id, role)
-    VALUES (#{id}, #{groupId}, #{resourceId}, #{role})
-  </insert>
-
-  <insert id="insertUserRole" parameterType="UserRole" useGeneratedKeys="true" keyProperty="id">
+  <insert id="insertUserRole" parameterType="UserRole" keyColumn="id" useGeneratedKeys="true" keyProperty="id">
     INSERT INTO user_roles (user_id, resource_id, role)
     VALUES (#{userId}, #{resourceId}, #{role})
   </insert>
 
-  <!-- Oracle -->
-  <insert id="insertUserRole" databaseId="oracle" parameterType="UserRole" useGeneratedKeys="true" keyProperty="id">
-    <selectKey order="BEFORE" resultType="Long" keyProperty="id">
-      select user_roles_seq.NEXTVAL from DUAL
-    </selectKey>
-    INSERT INTO user_roles (id, user_id, resource_id, role)
-    VALUES (#{id}, #{userId}, #{resourceId}, #{role})
-  </insert>
-
   <delete id="deleteGroupRole" parameterType="map">
     delete from group_roles where resource_id=#{resourceId} and role=#{role}
     <choose>
index bbc0ba808ea20fa874866fdb203b78a3d466ce3d..1ae3c8f845d61c3a16a0b6c7eaf56af99d0f3f36 100644 (file)
@@ -3,7 +3,7 @@
 
 <mapper namespace="org.sonar.api.database.model.MeasureMapper">
 
-  <insert id="insert" parameterType="MeasureModel" useGeneratedKeys="true" keyProperty="id">
+  <insert id="insert" parameterType="MeasureModel" keyColumn="id" useGeneratedKeys="true" keyProperty="id">
     INSERT INTO project_measures (
       value, metric_id, snapshot_id, rule_id, text_value, tendency, measure_date,
       project_id, alert_status, alert_text, url, description, rule_priority, characteristic_id, variation_value_1,
@@ -16,7 +16,7 @@
     )
   </insert>
 
-  <insert id="insertData" parameterType="MeasureData" useGeneratedKeys="true" keyProperty="id">
+  <insert id="insertData" parameterType="MeasureData" keyColumn="id" useGeneratedKeys="true" keyProperty="id">
     INSERT INTO measure_data (measure_id, snapshot_id, data)
     VALUES (#{measure.id}, #{measure.snapshotId}, #{data})
   </insert>
     WHERE id = #{id}
   </update>
 
-  <!-- ORACLE -->
-  <insert id="insert" databaseId="oracle" parameterType="MeasureModel" keyColumn="id" useGeneratedKeys="true" keyProperty="id">
-    INSERT INTO project_measures (
-      id,
-      value, metric_id, snapshot_id, rule_id, text_value, tendency, measure_date,
-      project_id, alert_status, alert_text, url, description, rule_priority, characteristic_id, variation_value_1,
-      variation_value_2, variation_value_3, variation_value_4, variation_value_5, person_id)
-    VALUES (
-      project_measures_seq.NEXTVAL,
-      #{value}, #{metricId}, #{snapshotId}, #{ruleId}, #{textValue}, #{tendency},
-      #{measureDate}, #{projectId}, #{alertStatus}, #{alertText},
-      #{url}, #{description}, #{rulePriority.ordinal}, #{characteristic.id}, #{variationValue1},
-      #{variationValue2}, #{variationValue3}, #{variationValue4}, #{variationValue5}, #{personId}
-    )
-  </insert>
-
-  <insert id="insertData" databaseId="oracle" parameterType="MeasureData" keyColumn="id" useGeneratedKeys="true" keyProperty="id">
-    INSERT INTO measure_data (id, measure_id, snapshot_id, data)
-    VALUES (measure_data_seq.NEXTVAL, #{measure.id}, #{measure.snapshotId}, #{data})
-  </insert>
-
 </mapper>
diff --git a/sonar-server/src/main/webapp/WEB-INF/db/migrate/412_add_oracle_id_triggers.rb b/sonar-server/src/main/webapp/WEB-INF/db/migrate/412_add_oracle_id_triggers.rb
new file mode 100644 (file)
index 0000000..f0e53e9
--- /dev/null
@@ -0,0 +1,113 @@
+#
+# Sonar, entreprise quality control tool.
+# Copyright (C) 2008-2013 SonarSource
+# mailto:contact AT sonarsource DOT com
+#
+# SonarQube is free software; you can redistribute it and/or
+# modify it under the terms of the GNU Lesser General Public
+# License as published by the Free Software Foundation; either
+# version 3 of the License, or (at your option) any later version.
+#
+# SonarQube is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+# Lesser General Public License for more details.
+#
+# You should have received a copy of the GNU Lesser General Public License
+# along with this program; if not, write to the Free Software Foundation,
+# Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+#
+
+#
+# Sonar 3.6
+# SONAR-3340
+class AddOracleIdTriggers < ActiveRecord::Migration
+
+
+  def self.up
+    case dialect()
+    when "oracle"
+      upgrade_oracle()
+    else
+      # Do nothing
+    end
+  end
+
+  private
+
+  def self.upgrade_oracle
+    create_id_trigger('action_plans')
+    create_id_trigger('active_dashboards')
+    create_id_trigger('active_rule_changes')
+    create_id_trigger('active_rule_notes')
+    create_id_trigger('active_rule_param_changes')
+    create_id_trigger('active_rule_parameters')
+    create_id_trigger('active_rules')
+    create_id_trigger('alerts')
+    create_id_trigger('authors')
+    create_id_trigger('characteristic_properties')
+    create_id_trigger('characteristics')
+    create_id_trigger('dashboards')
+    create_id_trigger('dependencies')
+    create_id_trigger('duplications_index')
+    create_id_trigger('events')
+    create_id_trigger('graphs')
+    create_id_trigger('group_roles')
+    create_id_trigger('groups')
+    create_id_trigger('groups_users')
+    create_id_trigger('issue_changes')
+    create_id_trigger('issue_filter_favourites')
+    create_id_trigger('issue_filters')
+    create_id_trigger('issues')
+    create_id_trigger('loaded_templates')
+    create_id_trigger('manual_measures')
+    create_id_trigger('measure_data')
+    create_id_trigger('measure_filter_favourites')
+    create_id_trigger('measure_filters')
+    create_id_trigger('metrics')
+    create_id_trigger('notifications')
+    create_id_trigger('project_links')
+    create_id_trigger('project_measures')
+    create_id_trigger('projects')
+    create_id_trigger('properties')
+    create_id_trigger('quality_models')
+    create_id_trigger('resource_index')
+    create_id_trigger('rule_notes')
+    create_id_trigger('rules')
+    create_id_trigger('rules_parameters')
+    create_id_trigger('rules_profiles')
+    create_id_trigger('semaphores')
+    create_id_trigger('snapshot_data')
+    create_id_trigger('snapshot_sources')
+    create_id_trigger('snapshots')
+    create_id_trigger('user_roles')
+    create_id_trigger('users')
+    create_id_trigger('widget_properties')
+    create_id_trigger('widgets')
+  end
+  
+  def self.create_id_trigger(table)
+      execute_ddl('create trigger for table ' + table, 
+      
+      %{CREATE OR REPLACE TRIGGER #{table}_id_trg
+          BEFORE INSERT ON #{table} 
+          FOR EACH ROW
+        BEGIN
+           IF :new.id IS null THEN
+             SELECT #{table}_seq.nextval INTO :new.id FROM dual;
+           END IF;
+        END;})
+  end
+
+  def self.execute_ddl(message, ddl)
+    begin
+      say_with_time(message) do
+        ActiveRecord::Base.connection.execute(ddl)
+      end
+    rescue
+      # already executed
+    end
+  end
+
+end
+