diff options
author | David Gageot <david@gageot.net> | 2012-07-11 18:37:50 +0200 |
---|---|---|
committer | David Gageot <david@gageot.net> | 2012-07-11 18:48:25 +0200 |
commit | aceadd9dd9a7b835ce67c505013f090f06ebe642 (patch) | |
tree | e19ca1e1f2f77c441e86ac13c9a09611fdf3777a /sonar-core | |
parent | 0522cfc57374f68f4e49916005641402a84f13c1 (diff) | |
download | sonarqube-aceadd9dd9a7b835ce67c505013f090f06ebe642.tar.gz sonarqube-aceadd9dd9a7b835ce67c505013f090f06ebe642.zip |
SONAR-3645 Forgot to merge an Oracle mapper and to remove dead code
Diffstat (limited to 'sonar-core')
-rw-r--r-- | sonar-core/src/main/java/org/sonar/core/persistence/MyBatis.java | 77 | ||||
-rw-r--r-- | sonar-core/src/main/resources/org/sonar/core/properties/PropertiesMapper.xml | 9 |
2 files changed, 57 insertions, 29 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 65c2d425ba3..4b0e85edf99 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 @@ -20,12 +20,15 @@ package org.sonar.core.persistence; import ch.qos.logback.classic.Level; -import org.apache.commons.io.IOUtils; -import org.apache.commons.lang.StringUtils; +import com.google.common.io.Closeables; import org.apache.ibatis.builder.xml.XMLMapperBuilder; import org.apache.ibatis.logging.LogFactory; import org.apache.ibatis.mapping.Environment; -import org.apache.ibatis.session.*; +import org.apache.ibatis.session.Configuration; +import org.apache.ibatis.session.ExecutorType; +import org.apache.ibatis.session.SqlSession; +import org.apache.ibatis.session.SqlSessionFactory; +import org.apache.ibatis.session.SqlSessionFactoryBuilder; import org.apache.ibatis.transaction.jdbc.JdbcTransactionFactory; import org.apache.ibatis.type.JdbcType; import org.slf4j.LoggerFactory; @@ -35,20 +38,37 @@ import org.sonar.api.config.Settings; import org.sonar.api.database.model.MeasureMapper; import org.sonar.api.database.model.MeasureModel; import org.sonar.core.config.Logback; -import org.sonar.core.dashboard.*; +import org.sonar.core.dashboard.ActiveDashboardDto; +import org.sonar.core.dashboard.ActiveDashboardMapper; +import org.sonar.core.dashboard.DashboardDto; +import org.sonar.core.dashboard.DashboardMapper; +import org.sonar.core.dashboard.WidgetDto; +import org.sonar.core.dashboard.WidgetMapper; +import org.sonar.core.dashboard.WidgetPropertyDto; +import org.sonar.core.dashboard.WidgetPropertyMapper; import org.sonar.core.dependency.DependencyDto; import org.sonar.core.dependency.DependencyMapper; import org.sonar.core.dependency.ResourceSnapshotDto; import org.sonar.core.dependency.ResourceSnapshotMapper; import org.sonar.core.duplication.DuplicationMapper; import org.sonar.core.duplication.DuplicationUnitDto; -import org.sonar.core.filter.*; +import org.sonar.core.filter.CriterionDto; +import org.sonar.core.filter.CriterionMapper; +import org.sonar.core.filter.FilterColumnDto; +import org.sonar.core.filter.FilterColumnMapper; +import org.sonar.core.filter.FilterDto; +import org.sonar.core.filter.FilterMapper; import org.sonar.core.properties.PropertiesMapper; import org.sonar.core.properties.PropertyDto; import org.sonar.core.purge.PurgeMapper; import org.sonar.core.purge.PurgeVendorMapper; import org.sonar.core.purge.PurgeableSnapshotDto; -import org.sonar.core.resource.*; +import org.sonar.core.resource.ResourceDto; +import org.sonar.core.resource.ResourceIndexDto; +import org.sonar.core.resource.ResourceIndexerMapper; +import org.sonar.core.resource.ResourceKeyUpdaterMapper; +import org.sonar.core.resource.ResourceMapper; +import org.sonar.core.resource.SnapshotDto; import org.sonar.core.review.ReviewCommentDto; import org.sonar.core.review.ReviewCommentMapper; import org.sonar.core.review.ReviewDto; @@ -57,7 +77,14 @@ import org.sonar.core.rule.RuleDto; import org.sonar.core.rule.RuleMapper; import org.sonar.core.template.LoadedTemplateDto; import org.sonar.core.template.LoadedTemplateMapper; -import org.sonar.core.user.*; +import org.sonar.core.user.AuthorDto; +import org.sonar.core.user.AuthorMapper; +import org.sonar.core.user.GroupDto; +import org.sonar.core.user.GroupRoleDto; +import org.sonar.core.user.RoleMapper; +import org.sonar.core.user.UserDto; +import org.sonar.core.user.UserMapper; +import org.sonar.core.user.UserRoleDto; import java.io.InputStream; @@ -76,14 +103,15 @@ public class MyBatis implements BatchComponent, ServerComponent { public MyBatis start() { LogFactory.useSlf4jLogging(); + 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()); - conf.setDatabaseId(database.getDialect().getId()); loadAlias(conf, "ActiveDashboard", ActiveDashboardDto.class); loadAlias(conf, "Author", AuthorDto.class); @@ -112,13 +140,14 @@ public class MyBatis implements BatchComponent, ServerComponent { loadAlias(conf, "WidgetProperty", WidgetPropertyDto.class); loadAlias(conf, "MeasureModel", MeasureModel.class); - Class[] mappers = {ActiveDashboardMapper.class, AuthorMapper.class, FilterMapper.class, CriterionMapper.class, FilterColumnMapper.class, DashboardMapper.class, + Class<?>[] mappers = {ActiveDashboardMapper.class, AuthorMapper.class, FilterMapper.class, CriterionMapper.class, FilterColumnMapper.class, DashboardMapper.class, DependencyMapper.class, DuplicationMapper.class, LoadedTemplateMapper.class, PropertiesMapper.class, PurgeMapper.class, PurgeVendorMapper.class, ResourceKeyUpdaterMapper.class, ResourceIndexerMapper.class, ResourceMapper.class, ResourceSnapshotMapper.class, ReviewCommentMapper.class, ReviewMapper.class, RoleMapper.class, RuleMapper.class, SchemaMigrationMapper.class, UserMapper.class, WidgetMapper.class, WidgetPropertyMapper.class, MeasureMapper.class}; loadMappers(conf, mappers); configureLogback(mappers); + sessionFactory = new SqlSessionFactoryBuilder().build(conf); return this; } @@ -147,7 +176,7 @@ public class MyBatis implements BatchComponent, ServerComponent { } } - private void loadMappers(Configuration mybatisConf, Class... mapperClasses) { + private void loadMappers(Configuration mybatisConf, Class<?>... mapperClasses) { for (Class mapperClass : mapperClasses) { loadMapper(mybatisConf, mapperClass); } @@ -156,7 +185,7 @@ public class MyBatis implements BatchComponent, ServerComponent { /** * See http://www.mybatis.org/core/logging.html : */ - private void configureLogback(Class[] mapperClasses) { + private void configureLogback(Class<?>... mapperClasses) { if (settings.getBoolean("sonar.showSql")) { Level level = (settings.getBoolean("sonar.showSqlResults") ? Level.TRACE : Level.DEBUG); for (Class mapperClass : mapperClasses) { @@ -165,28 +194,19 @@ public class MyBatis implements BatchComponent, ServerComponent { } } - private void loadMapper(Configuration mybatisConf, Class mapperClass) { - // trick to use database-specific XML files for a single Mapper Java interface - InputStream input = getPathToMapper(mapperClass); - try { - XMLMapperBuilder mapperParser = new XMLMapperBuilder(input, mybatisConf, mapperClass.getName(), mybatisConf.getSqlFragments()); - mapperParser.parse(); - mybatisConf.addLoadedResource(mapperClass.getName()); + private void loadMapper(Configuration configuration, Class mapperClass) { + String mapperName = mapperClass.getName(); + InputStream input = null; + try { + input = getClass().getResourceAsStream("/" + mapperName.replace('.', '/') + ".xml"); + new XMLMapperBuilder(input, configuration, mapperName, configuration.getSqlFragments()).parse(); + configuration.addLoadedResource(mapperName); } finally { - IOUtils.closeQuietly(input); + Closeables.closeQuietly(input); } } - private InputStream getPathToMapper(Class mapperClass) { - InputStream input = getClass().getResourceAsStream( - "/" + StringUtils.replace(mapperClass.getName(), ".", "/") + "-" + database.getDialect().getId() + ".xml"); - if (input == null) { - input = getClass().getResourceAsStream("/" + StringUtils.replace(mapperClass.getName(), ".", "/") + ".xml"); - } - return input; - } - private void loadAlias(Configuration conf, String alias, Class dtoClass) { conf.getTypeAliasRegistry().registerAlias(alias, dtoClass); } @@ -194,5 +214,4 @@ public class MyBatis implements BatchComponent, ServerComponent { private static JdbcTransactionFactory createTransactionFactory() { return new JdbcTransactionFactory(); } - } diff --git a/sonar-core/src/main/resources/org/sonar/core/properties/PropertiesMapper.xml b/sonar-core/src/main/resources/org/sonar/core/properties/PropertiesMapper.xml index 78b22358d0b..768ee357f24 100644 --- a/sonar-core/src/main/resources/org/sonar/core/properties/PropertiesMapper.xml +++ b/sonar-core/src/main/resources/org/sonar/core/properties/PropertiesMapper.xml @@ -55,4 +55,13 @@ VALUES (#{key}, #{resourceId}, #{userId}, #{value}) </insert> + <!-- Oracle --> + <insert id="insert" databaseId="oracle" parameterType="Property" useGeneratedKeys="true" keyProperty="id"> + <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> + </mapper> |