]> source.dussan.org Git - sonarqube.git/commitdiff
Use MyBatis lang="raw" to speed-up xml parsing when possible
authorSimon Brandhof <simon.brandhof@sonarsource.com>
Thu, 12 Jun 2014 22:50:47 +0000 (00:50 +0200)
committerSimon Brandhof <simon.brandhof@sonarsource.com>
Fri, 13 Jun 2014 19:50:48 +0000 (21:50 +0200)
17 files changed:
sonar-core/src/main/java/org/sonar/core/component/db/ComponentMapper.java
sonar-core/src/main/java/org/sonar/core/dashboard/ActiveDashboardMapper.java
sonar-core/src/main/java/org/sonar/core/resource/ResourceDao.java
sonar-core/src/main/java/org/sonar/core/resource/ResourceMapper.java
sonar-core/src/main/resources/org/sonar/core/component/db/ComponentMapper.xml
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/dependency/DependencyMapper.xml
sonar-core/src/main/resources/org/sonar/core/dependency/ResourceSnapshotMapper.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/properties/PropertiesMapper.xml
sonar-core/src/main/resources/org/sonar/core/qualitygate/db/QualityGateConditionMapper.xml
sonar-core/src/main/resources/org/sonar/core/qualitygate/db/QualityGateMapper.xml
sonar-core/src/main/resources/org/sonar/core/resource/ResourceMapper.xml

index b5b781c06bef43c60f8c14dfff5fa23afa401ef3..a95a6b6cf41f423729569cdf5aea2a64d8655c4e 100644 (file)
@@ -28,7 +28,7 @@ public interface ComponentMapper {
 
   ComponentDto selectByKey(String key);
 
-  ComponentDto selectById(Long id);
+  ComponentDto selectById(long id);
 
-  long countById(Long id);
+  long countById(long id);
 }
index fa7e99d27ba0331e17369bcc621d09c6f1e890c3..b4940f7065bbbeb1c1179bc1aff448e8332d9d0e 100644 (file)
 package org.sonar.core.dashboard;
 
 
+import javax.annotation.CheckForNull;
+
 public interface ActiveDashboardMapper {
 
   void insert(ActiveDashboardDto activeDashboardDto);
 
+  @CheckForNull
   Integer selectMaxOrderIndexForNullUser();
 
 }
index e9475d79f480fa65812cee8d95c7a095d06cbb07..6bc48a279b429542e97a7db6904c61be8bac473b 100644 (file)
@@ -209,7 +209,7 @@ public class ResourceDao implements DaoComponent {
   }
 
   @CheckForNull
-  public ResourceDto getRootProjectByComponentId(Long componentId) {
+  public ResourceDto getRootProjectByComponentId(long componentId) {
     SqlSession session = mybatis.openSession(false);
     try {
       return session.getMapper(ResourceMapper.class).selectRootProjectByComponentId(componentId);
index 7c899784eb95005dc6a77fa7549d5edecdbc892d..f40caa1a42649666e545ec2a78b02e4b6445cfd4 100644 (file)
@@ -64,7 +64,7 @@ public interface ResourceMapper {
   /**
    * @since 3.6
    */
-  ResourceDto selectRootProjectByComponentId(@Param("componentId") Long componentId);
+  ResourceDto selectRootProjectByComponentId(@Param("componentId") long componentId);
 
   /**
    * @since 3.6
index a604fea396b2f658dfad01c03e42de5d42ef45ee..59bc16ecfbcfe0a363abe9cf14cf3de3040e5049 100644 (file)
     SELECT <include refid="componentColumns"/>
     FROM projects p
     INNER JOIN snapshots s on s.project_id=p.id and s.islast=${_true}
-    <where>
-      AND p.enabled=${_true}
-      AND p.kee=#{key}
-    </where>
+    WHERE p.enabled=${_true} AND p.kee=#{key}
   </select>
 
-  <select id="selectById" parameterType="Long" resultType="Component">
+  <select id="selectById" parameterType="long" resultType="Component">
     SELECT <include refid="componentColumns"/>
     FROM projects p
     INNER JOIN snapshots s on s.project_id=p.id and s.islast=${_true}
-    <where>
-      AND p.enabled=${_true}
-      AND p.id=#{id}
-    </where>
+    WHERE p.enabled=${_true} AND p.id=#{id}
   </select>
 
-  <select id="countById" parameterType="Long" resultType="long">
+  <select id="countById" parameterType="long" resultType="long">
     SELECT count(p.id)
     FROM projects p
-    <where>
-      AND p.enabled=${_true}
-      AND p.id=#{id}
-    </where>
+    WHERE p.enabled=${_true} AND p.id=#{id}
   </select>
 
 </mapper>
index c62f80dafd6fa8c94d4263318ec0bd2a1d38fce3..013ee97161eff7c735dabea6e8b9fcefef7c1463 100644 (file)
@@ -3,12 +3,12 @@
 
 <mapper namespace="org.sonar.core.dashboard.ActiveDashboardMapper">
 
-  <insert id="insert" parameterType="ActiveDashboard" keyColumn="id" useGeneratedKeys="true" keyProperty ="id">
+  <insert id="insert" parameterType="ActiveDashboard" keyColumn="id" useGeneratedKeys="true" keyProperty ="id" lang="raw">
     INSERT INTO active_dashboards (dashboard_id, user_id, order_index)
     VALUES (#{dashboardId}, #{userId}, #{orderIndex})
   </insert>
 
-  <select id="selectMaxOrderIndexForNullUser" resultType="Integer">
+  <select id="selectMaxOrderIndexForNullUser" resultType="Integer" lang="raw">
     SELECT MAX(order_index)
     FROM active_dashboards
     WHERE user_id IS NULL
index deb4989bd6f81fd1d44c8520aba2569b90c57aa4..e9f4803c394ee184aef7548b93adc570b8f976e2 100644 (file)
@@ -3,12 +3,12 @@
 
 <mapper namespace="org.sonar.core.dashboard.DashboardMapper">
 
-  <select id="selectGlobalDashboard" parameterType="string" resultType="Dashboard">
+  <select id="selectGlobalDashboard" parameterType="string" resultType="Dashboard" lang="raw">
     select id, user_id as "userId", name, description, column_layout as "columnLayout", shared, is_global, created_at as "createdAt", updated_at as "updatedAt"
     from dashboards WHERE name=#{id} and user_id is null
   </select>
 
-  <insert id="insert" parameterType="Dashboard" keyColumn="id" useGeneratedKeys="true" keyProperty="id">
+  <insert id="insert" parameterType="Dashboard" keyColumn="id" useGeneratedKeys="true" keyProperty="id" lang="raw">
     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})
index 07f2a323880a7be7b091a8688e005e4d71acdf87..71bc01cf4517883d4db181e85cf8e18c6360ee64 100644 (file)
@@ -3,7 +3,7 @@
 
 <mapper namespace="org.sonar.core.dashboard.WidgetMapper">
 
-  <insert id="insert" parameterType="Widget" keyColumn="id" useGeneratedKeys="true" keyProperty ="id">
+  <insert id="insert" parameterType="Widget" keyColumn="id" useGeneratedKeys="true" keyProperty="id" lang="raw">
     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})
index deb555dea0e55b0f25929f1daf8d2c2d3a8613e6..5ab44a79e625eea7d80f0e680fd38294ef1f4f27 100644 (file)
@@ -3,7 +3,7 @@
 
 <mapper namespace="org.sonar.core.dashboard.WidgetPropertyMapper">
 
-  <insert id="insert" parameterType="WidgetProperty" keyColumn="id" useGeneratedKeys="true" keyProperty="id">
+  <insert id="insert" parameterType="WidgetProperty" keyColumn="id" useGeneratedKeys="true" keyProperty="id" lang="raw">
     INSERT INTO widget_properties (widget_id, kee, text_value)
     VALUES (#{widgetId}, #{key}, #{value})
   </insert>
index b12dbb37535eca149e33cc43394e1284a11ca0dd..1ea976a0ea5f233b1d22e91bdb3886b53f1e8af1 100644 (file)
@@ -3,7 +3,7 @@
 
 <mapper namespace="org.sonar.core.dependency.DependencyMapper">
 
-  <select id="selectAll" resultType="dependency">
+  <select id="selectAll" resultType="dependency" lang="raw">
     SELECT id, from_snapshot_id as fromSnapshotId, to_snapshot_id as toSnapshotId, dep_usage as "usage" FROM dependencies
   </select>
 
index 7fdb3e7f36c17ec61e7b4ebc653cf019a949c422..5377b4f9d20e9e30d058d49f92f146cd8b84c1a3 100644 (file)
@@ -3,7 +3,7 @@
 
 <mapper namespace="org.sonar.core.dependency.ResourceSnapshotMapper">
 
-  <select id="selectAll" resultType="ResourceSnapshot">
+  <select id="selectAll" resultType="ResourceSnapshot" lang="raw">
     SELECT id, project_id as projectId, version FROM snapshots
   </select>
 
index 5a97b8247566b445ab9bed269a1a980666e0c310..a2810919e0be7061ca9f20c3575c1be07e171eaa 100644 (file)
@@ -17,7 +17,7 @@
     </if>
   </select>
 
-  <insert id="batchInsert" parameterType="DuplicationUnit" useGeneratedKeys="false">
+  <insert id="batchInsert" parameterType="DuplicationUnit" useGeneratedKeys="false" lang="raw">
     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>
index c7416c87a63153c2e4dc4d8e6a480d35143382fc..d77105ac70251e0743879a2c230249ac26b3be0b 100644 (file)
@@ -3,13 +3,13 @@
 
 <mapper namespace="org.sonar.core.graph.jdbc.GraphDtoMapper">
 
-  <select id="selectBySnapshot" parameterType="map" resultType="Graph">
+  <select id="selectBySnapshot" parameterType="map" resultType="Graph" lang="raw">
     SELECT id, resource_id as resourceId, snapshot_id as snapshotId, format, version, perspective, root_vertex_id as rootVertexId, data
     FROM graphs
     WHERE snapshot_id = #{sid} AND perspective = #{perspective}
   </select>
 
-  <select id="selectByComponent" parameterType="map" resultType="Graph">
+  <select id="selectByComponent" parameterType="map" resultType="Graph" lang="raw">
     SELECT g.id, g.resource_id as resourceId, g.snapshot_id as snapshotId, g.format, g.version, g.perspective, g.root_vertex_id as rootVertexId, g.data
     FROM graphs g, snapshots s
     WHERE g.perspective = #{perspective} AND g.snapshot_id=s.id AND s.islast=${_true} and s.project_id=(
@@ -17,7 +17,7 @@
     )
   </select>
 
-  <insert id="insert" parameterType="Graph" useGeneratedKeys="false">
+  <insert id="insert" parameterType="Graph" useGeneratedKeys="false" lang="raw">
     insert into graphs
     (resource_id, snapshot_id, format, version, perspective, root_vertex_id, data, created_at, updated_at)
     values (
index 30f14b0667214114539710c39e60eebcc33982e9..8e1f1645409b9b17343cf4dc18dcc2c94e69c1fd 100644 (file)
     )
   </select>
 
-  <select id="selectGlobalProperties" resultType="Property">
+  <select id="selectGlobalProperties" resultType="Property" lang="raw">
     select p.id as id, p.prop_key as "key", p.text_value as value, p.resource_id as resourceId, p.user_id as userId
     from properties p
     where p.resource_id is null and p.user_id is null
   </select>
 
-  <select id="selectProjectProperties" parameterType="String" resultType="Property">
+  <select id="selectProjectProperties" parameterType="String" resultType="Property" lang="raw">
     select p.id as id, p.prop_key as "key", p.text_value as value, p.resource_id as resourceId, p.user_id as userId
     from properties p, projects r
     where p.resource_id=r.id and p.user_id is null and r.kee=#{id}
     </where>
   </select>
 
-  <update id="update" parameterType="Property">
+  <update id="update" parameterType="Property" lang="raw">
     update properties set text_value = #{value} where id = #{id}
   </update>
 
-  <insert id="insert" parameterType="Property" useGeneratedKeys="false">
+  <insert id="insert" parameterType="Property" useGeneratedKeys="false" lang="raw">
     INSERT INTO properties (prop_key, resource_id, user_id, text_value)
     VALUES (#{key}, #{resourceId}, #{userId}, #{value})
   </insert>
 
-  <delete id="deleteProjectProperty" parameterType="map">
+  <delete id="deleteProjectProperty" parameterType="map" lang="raw">
     delete from properties where prop_key=#{key} and resource_id=#{rId} and user_id is null
   </delete>
 
-  <delete id="deleteProjectProperties" parameterType="map">
+  <delete id="deleteProjectProperties" parameterType="map" lang="raw">
     DELETE FROM properties
-    <where>
-      AND prop_key=#{key}
+    WHERE
+      prop_key=#{key}
       AND text_value LIKE #{value}
       AND resource_id IS NOT NULL
       AND user_id IS NULL
-    </where>
   </delete>
 
-  <delete id="deleteGlobalProperty" parameterType="string">
+  <delete id="deleteGlobalProperty" parameterType="string" lang="raw">
     delete from properties where prop_key=#{id} and resource_id is null and user_id is null
   </delete>
 
-  <delete id="deleteGlobalProperties">
+  <delete id="deleteGlobalProperties" lang="raw">
     delete from properties where resource_id is null and user_id is null
   </delete>
 
-  <delete id="deleteAllProperties" parameterType="string">
+  <delete id="deleteAllProperties" parameterType="string" lang="raw">
     delete from properties where prop_key=#{id}
   </delete>
 
-  <update id="renamePropertyKey" parameterType="map">
+  <update id="renamePropertyKey" parameterType="map" lang="raw">
     update properties set prop_key=#{newKey} where prop_key=#{oldKey}
   </update>
 
-  <update id="updateProperties" parameterType="map">
+  <update id="updateProperties" parameterType="map" lang="raw">
     update properties set text_value=#{newValue} where text_value LIKE #{oldValue} and prop_key=#{key}
   </update>
 
index 65200e4bedfb5aa5d1ac6f2b0dfafa1ecf4dd0b2..600d7ac593e3ec82a1b46c3d523b35727d773e39 100644 (file)
@@ -3,7 +3,7 @@
 
 <mapper namespace="org.sonar.core.qualitygate.db.QualityGateConditionMapper">
 
-  <insert id="insert" parameterType="QualityGateCondition" keyColumn="id" useGeneratedKeys="true" keyProperty="id">
+  <insert id="insert" parameterType="QualityGateCondition" keyColumn="id" useGeneratedKeys="true" keyProperty="id" lang="raw">
     insert into quality_gate_conditions (qgate_id, metric_id, operator, value_error, value_warning, period, created_at, updated_at)
     values (#{qualityGateId}, #{metricId}, #{operator}, #{errorThreshold}, #{warningThreshold}, #{period}, #{createdAt}, #{updatedAt})
   </insert>
     select <include refid="conditionColumns"/> from quality_gate_conditions where id=#{id}
   </select>
 
-  <update id="delete" parameterType="long">
+  <update id="delete" parameterType="long" lang="raw">
     delete from quality_gate_conditions where id=#{id}
   </update>
 
-  <update id="update" parameterType="QualityGateCondition">
+  <update id="update" parameterType="QualityGateCondition" lang="raw">
     update quality_gate_conditions set
     metric_id=#{metricId},
     operator=#{operator},
@@ -37,7 +37,7 @@
     where id=#{id}
   </update>
 
-  <delete id="deleteConditionsWithInvalidMetrics">
+  <delete id="deleteConditionsWithInvalidMetrics" lang="raw">
     delete from quality_gate_conditions
     where metric_id not in (select id from metrics where enabled=${_true})
   </delete>
index 710d76fb0dd22849c4ba0bf7d1694f14a962d78b..84644a0a6e0af4542461280842908b049a2bdb50 100644 (file)
@@ -3,7 +3,7 @@
 
 <mapper namespace="org.sonar.core.qualitygate.db.QualityGateMapper">
 
-  <insert id="insert" parameterType="QualityGate" keyColumn="id" useGeneratedKeys="true" keyProperty="id">
+  <insert id="insert" parameterType="QualityGate" keyColumn="id" useGeneratedKeys="true" keyProperty="id" lang="raw">
     insert into quality_gates (name, created_at, updated_at)
     values (#{name}, #{createdAt}, #{updatedAt})
   </insert>
     where id=#{id}
   </select>
 
-  <update id="delete" parameterType="long">
+  <update id="delete" parameterType="long" lang="raw">
     delete from quality_gates where id=#{id}
   </update>
 
-  <update id="update" parameterType="QualityGate">
+  <update id="update" parameterType="QualityGate" lang="raw">
     update quality_gates set
     name=#{name},
     updated_at=#{updatedAt}
index 0cba47b148cd85a463ce852a347848b75c98e6b9..9dc93cb829579b0ce8be1c783c65b0d16deba90a 100644 (file)
     </where>
   </select>
 
-  <select id="selectRootProjectByComponentId" parameterType="long" resultMap="resourceResultMap">
+  <select id="selectRootProjectByComponentId" parameterType="long" resultMap="resourceResultMap" lang="raw">
     select rootProject.*
     from snapshots s
     inner join projects rootProject on rootProject.id=s.root_project_id
-    <where>
-      and s.project_id=#{componentId}
+    where
+      s.project_id=#{componentId}
       and s.islast=${_true}
-    </where>
   </select>
 
   <select id="selectComponentsByIds" parameterType="long" resultType="Component">
     </where>
   </select>
 
-  <select id="selectProvisionedProject" parameterType="string" resultMap="resourceResultMap">
+  <select id="selectProvisionedProject" parameterType="string" resultMap="resourceResultMap" lang="raw">
     select p.* from projects p
     left join snapshots s on s.project_id=p.id
-    <where>
-      and s.id is null
+    where s.id is null
       and p.kee = #{key}
       and p.copy_resource_id is null
-    </where>
   </select>
 
   <select id="selectAuthorizedChildrenComponentIds" parameterType="map" resultType="int">
     </where>
   </sql>
 
-  <insert id="insert" parameterType="Resource" keyColumn="id" useGeneratedKeys="true" keyProperty="id">
+  <insert id="insert" parameterType="Resource" keyColumn="id" useGeneratedKeys="true" keyProperty="id" lang="raw">
     insert into projects
     (name, long_name, description, scope, qualifier, kee, deprecated_kee, path, language, root_id, copy_resource_id, person_id, enabled, created_at)
     values (
     )
   </insert>
 
-  <update id="update" parameterType="Resource">
+  <update id="update" parameterType="Resource" lang="raw">
     update projects set name=#{name}, long_name=#{longName}, description=#{description},
     scope=#{scope}, qualifier=#{qualifier}, kee=#{key}, deprecated_kee=#{deprecatedKey}, path=#{path},
     language=#{language}, root_id=#{rootId}, copy_resource_id=#{copyResourceId},