]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-3645 Forgot to merge an Oracle mapper and to remove dead code
authorDavid Gageot <david@gageot.net>
Wed, 11 Jul 2012 16:37:50 +0000 (18:37 +0200)
committerDavid Gageot <david@gageot.net>
Wed, 11 Jul 2012 16:48:25 +0000 (18:48 +0200)
sonar-core/src/main/java/org/sonar/core/persistence/MyBatis.java
sonar-core/src/main/resources/org/sonar/core/properties/PropertiesMapper.xml

index 65c2d425ba30d0cca89a34df3fc7e75571c63e7b..4b0e85edf99c6ff71ce2b38fbe13def7fd526d42 100644 (file)
 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();
   }
-
 }
index 78b22358d0b0683a2aaa8c385e2bba14dba96ae7..768ee357f24a06154aa5c8c1c72778652e37c4b8 100644 (file)
     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>