conf.setEnvironment(new Environment("production", createTransactionFactory(), database.getDataSource()));
conf.setUseGeneratedKeys(true);
conf.setLazyLoadingEnabled(false);
+ conf.getVariables().setProperty("_true", database.getDialect().getTrueSqlValue());
+ conf.getVariables().setProperty("_false", database.getDialect().getFalseSqlValue());
loadAlias(conf, "ActiveDashboard", ActiveDashboardDto.class);
loadAlias(conf, "Dashboard", DashboardDto.class);
}
}
+ public String getTrueSqlValue() {
+ return "true";
+ }
+
+ public String getFalseSqlValue() {
+ return "false";
+ }
}
String getDefaultDriverClassName();
String getConnectionInitStatement(String schema);
+
+ /**
+ * @since 2.14
+ */
+ String getTrueSqlValue();
+
+ /**
+ * @since 2.14
+ */
+ String getFalseSqlValue();
}
public String getConnectionInitStatement(String schema) {
return null;
}
+
+ public String getTrueSqlValue() {
+ return "1";
+ }
+
+ public String getFalseSqlValue() {
+ return "0";
+ }
}
public String getConnectionInitStatement(String schema) {
return null;
}
+
+ public String getTrueSqlValue() {
+ return "true";
+ }
+
+ public String getFalseSqlValue() {
+ return "false";
+ }
}
}
return null;
}
+
+ public String getTrueSqlValue() {
+ return "1";
+ }
+
+ public String getFalseSqlValue() {
+ return "0";
+ }
}
}
return null;
}
+
+ public String getTrueSqlValue() {
+ return "true";
+ }
+
+ public String getFalseSqlValue() {
+ return "false";
+ }
}
package org.sonar.core.resource;
final class ResourceIndexerQuery {
- // Workaround to inject booleans into mybatis mappers. It avoids declaring mappers
- // dedicated to Oracle and SQLServer
- public final boolean _true = true; //NOSONAR
-
private Integer rootProjectId = null;
private String[] scopes = null;
private String[] qualifiers = null;
+++ /dev/null
-<?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.core.duplication.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="batchInsert" parameterType="DuplicationUnit" useGeneratedKeys="false">
- 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>
+++ /dev/null
-<?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.core.duplication.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="batchInsert" parameterType="DuplicationUnit" useGeneratedKeys="false">
- 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>
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 = TRUE
+ AND snapshot.islast = ${_true}
AND snapshot.project_id = res.id
<if test="last_project_snapshot_id != null">
AND to_blocks.project_snapshot_id != #{last_project_snapshot_id}
select p.name as "name", p.id as "id", p.scope as "scope", p.qualifier as "qualifier", s.root_project_id as "rootId"
from projects p, snapshots s
<where>
- p.enabled=#{_true}
+ p.enabled=${_true}
and p.copy_resource_id is null
and p.id=s.project_id
- and s.islast=#{_true}
+ and s.islast=${_true}
<if test="scopes != null">
and p.scope in
<foreach item="scope" index="index" collection="scopes" open="(" separator="," close=")">#{scope}</foreach>
<select id="selectRootProjectIds" parameterType="map" resultType="int">
select distinct root_project_id
from snapshots
- where islast=#{_true}
+ where islast=${_true}
and scope='PRJ'
and qualifier in ('TRK', 'VW', 'SVW')
</select>
-
-
-
<select id="selectMasterIndexByResourceId" parameterType="int" resultType="ResourceIndex">
select kee as "key", resource_id as "resourceId"
from resource_index
public class MySqlTest {
+ private MySql mySql = new MySql();
+
@Test
public void matchesJdbcURL() {
- assertThat(new MySql().matchesJdbcURL("jdbc:mysql://localhost:3306/sonar?useUnicode=true&characterEncoding=utf8"), is(true));
- assertThat(new MySql().matchesJdbcURL("JDBC:MYSQL://localhost:3306/sonar?useUnicode=true&characterEncoding=utf8"), is(true));
+ assertThat(mySql.matchesJdbcURL("jdbc:mysql://localhost:3306/sonar?useUnicode=true&characterEncoding=utf8"), is(true));
+ assertThat(mySql.matchesJdbcURL("JDBC:MYSQL://localhost:3306/sonar?useUnicode=true&characterEncoding=utf8"), is(true));
- assertThat(new MySql().matchesJdbcURL("jdbc:hsql:foo"), is(false));
- assertThat(new MySql().matchesJdbcURL("jdbc:oracle:foo"), is(false));
+ assertThat(mySql.matchesJdbcURL("jdbc:hsql:foo"), is(false));
+ assertThat(mySql.matchesJdbcURL("jdbc:oracle:foo"), is(false));
}
+ @Test
+ public void testBooleanSqlValues() {
+ assertThat(mySql.getTrueSqlValue(), is("true"));
+ assertThat(mySql.getFalseSqlValue(), is("false"));
+ }
}
+