コード例 #1
0
ファイル: MyBatis.java プロジェクト: eSh3m4/sonarqube
 private void loadMapper(Configuration configuration, String mapperName) {
   InputStream input = null;
   try {
     input = getClass().getResourceAsStream("/" + mapperName.replace('.', '/') + ".xml");
     new XMLMapperBuilder(input, configuration, mapperName, configuration.getSqlFragments())
         .parse();
     configuration.addLoadedResource(mapperName);
     logback.setLoggerLevel(mapperName, Level.INFO);
   } catch (Exception e) {
     throw new IllegalArgumentException("Unable to load mapper " + mapperName, e);
   } finally {
     Closeables.closeQuietly(input);
   }
 }
コード例 #2
0
ファイル: MyBatis.java プロジェクト: eSh3m4/sonarqube
 private void loadAlias(Configuration conf, String alias, Class dtoClass) {
   conf.getTypeAliasRegistry().registerAlias(alias, dtoClass);
 }
コード例 #3
0
ファイル: MyBatis.java プロジェクト: eSh3m4/sonarqube
  public MyBatis start() {
    LogFactory.useSlf4jLogging();

    Configuration conf = new Configuration();
    conf.setEnvironment(
        new Environment("production", createTransactionFactory(), database.getDataSource()));
    conf.setUseGeneratedKeys(true);
    conf.setLazyLoadingEnabled(false);
    conf.setJdbcTypeForNull(JdbcType.NULL);
    Dialect dialect = database.getDialect();
    conf.setDatabaseId(dialect.getId());
    conf.getVariables().setProperty("_true", dialect.getTrueSqlValue());
    conf.getVariables().setProperty("_false", dialect.getFalseSqlValue());
    conf.getVariables()
        .setProperty("_scrollFetchSize", String.valueOf(dialect.getScrollDefaultFetchSize()));

    loadAlias(conf, "ActiveDashboard", ActiveDashboardDto.class);
    loadAlias(conf, "Author", AuthorDto.class);
    loadAlias(conf, "Component", ComponentDto.class);
    loadAlias(conf, "Dashboard", DashboardDto.class);
    loadAlias(conf, "Dependency", DependencyDto.class);
    loadAlias(conf, "DuplicationUnit", DuplicationUnitDto.class);
    loadAlias(conf, "Graph", GraphDto.class);
    loadAlias(conf, "Group", GroupDto.class);
    loadAlias(conf, "GroupRole", GroupRoleDto.class);
    loadAlias(conf, "GroupMembership", GroupMembershipDto.class);
    loadAlias(conf, "LoadedTemplate", LoadedTemplateDto.class);
    loadAlias(conf, "MeasureFilter", MeasureFilterDto.class);
    loadAlias(conf, "NotificationQueue", NotificationQueueDto.class);
    loadAlias(conf, "Property", PropertyDto.class);
    loadAlias(conf, "PurgeableSnapshot", PurgeableSnapshotDto.class);
    loadAlias(conf, "QualityGate", QualityGateDto.class);
    loadAlias(conf, "QualityGateCondition", QualityGateConditionDto.class);
    loadAlias(conf, "ProjectQgateAssociation", ProjectQgateAssociationDto.class);
    loadAlias(conf, "Resource", ResourceDto.class);
    loadAlias(conf, "ResourceIndex", ResourceIndexDto.class);
    loadAlias(conf, "ResourceSnapshot", ResourceSnapshotDto.class);
    loadAlias(conf, "Rule", RuleDto.class);
    loadAlias(conf, "RuleParam", RuleParamDto.class);
    loadAlias(conf, "Snapshot", SnapshotDto.class);
    loadAlias(conf, "Semaphore", SemaphoreDto.class);
    loadAlias(conf, "SchemaMigration", SchemaMigrationDto.class);
    loadAlias(conf, "User", UserDto.class);
    loadAlias(conf, "UserRole", UserRoleDto.class);
    loadAlias(conf, "UserGroup", UserGroupDto.class);
    loadAlias(conf, "Widget", WidgetDto.class);
    loadAlias(conf, "WidgetProperty", WidgetPropertyDto.class);
    loadAlias(conf, "MeasureModel", MeasureModel.class);
    loadAlias(conf, "Measure", MeasureDto.class);
    loadAlias(conf, "Metric", MetricDto.class);
    loadAlias(conf, "Issue", IssueDto.class);
    loadAlias(conf, "IssueChange", IssueChangeDto.class);
    loadAlias(conf, "IssueFilter", IssueFilterDto.class);
    loadAlias(conf, "IssueFilterFavourite", IssueFilterFavouriteDto.class);
    loadAlias(conf, "ActionPlanIssue", ActionPlanDto.class);
    loadAlias(conf, "ActionPlanStats", ActionPlanStatsDto.class);
    loadAlias(conf, "PermissionTemplate", PermissionTemplateDto.class);
    loadAlias(conf, "PermissionTemplateUser", PermissionTemplateUserDto.class);
    loadAlias(conf, "PermissionTemplateGroup", PermissionTemplateGroupDto.class);
    loadAlias(conf, "Characteristic", CharacteristicDto.class);
    loadAlias(conf, "UserWithPermission", UserWithPermissionDto.class);
    loadAlias(conf, "GroupWithPermission", GroupWithPermissionDto.class);
    loadAlias(conf, "QualityProfile", QualityProfileDto.class);
    loadAlias(conf, "ActiveRule", ActiveRuleDto.class);
    loadAlias(conf, "ActiveRuleParam", ActiveRuleParamDto.class);
    loadAlias(conf, "RequirementMigration", RequirementMigrationDto.class);
    loadAlias(conf, "Activity", ActivityDto.class);
    loadAlias(conf, "AnalysisReport", AnalysisReportDto.class);
    loadAlias(conf, "IdUuidPair", IdUuidPair.class);
    loadAlias(conf, "FilePathWithHash", FilePathWithHashDto.class);
    loadAlias(conf, "UuidWithProjectUuid", UuidWithProjectUuidDto.class);

    // AuthorizationMapper has to be loaded before IssueMapper because this last one used it
    loadMapper(conf, "org.sonar.core.user.AuthorizationMapper");
    // ResourceMapper has to be loaded before IssueMapper because this last one used it
    loadMapper(conf, ResourceMapper.class);

    loadMapper(conf, "org.sonar.core.permission.PermissionMapper");
    Class<?>[] mappers = {
      ActivityMapper.class,
      ActiveDashboardMapper.class,
      AuthorMapper.class,
      DashboardMapper.class,
      DependencyMapper.class,
      DuplicationMapper.class,
      GraphDtoMapper.class,
      IssueMapper.class,
      IssueChangeMapper.class,
      IssueFilterMapper.class,
      IssueFilterFavouriteMapper.class,
      LoadedTemplateMapper.class,
      MeasureFilterMapper.class,
      Migration44Mapper.class,
      PermissionTemplateMapper.class,
      PropertiesMapper.class,
      PurgeMapper.class,
      ResourceKeyUpdaterMapper.class,
      ResourceIndexerMapper.class,
      ResourceSnapshotMapper.class,
      RoleMapper.class,
      RuleMapper.class,
      SchemaMigrationMapper.class,
      SemaphoreMapper.class,
      UserMapper.class,
      GroupMapper.class,
      UserGroupMapper.class,
      WidgetMapper.class,
      WidgetPropertyMapper.class,
      org.sonar.api.database.model.MeasureMapper.class,
      FileSourceMapper.class,
      ActionPlanMapper.class,
      ActionPlanStatsMapper.class,
      NotificationQueueMapper.class,
      CharacteristicMapper.class,
      GroupMembershipMapper.class,
      QualityProfileMapper.class,
      ActiveRuleMapper.class,
      MeasureMapper.class,
      MetricMapper.class,
      QualityGateMapper.class,
      QualityGateConditionMapper.class,
      ComponentMapper.class,
      SnapshotMapper.class,
      ProjectQgateAssociationMapper.class,
      AnalysisReportMapper.class,
      ComponentIndexMapper.class,
      Migration45Mapper.class,
      Migration50Mapper.class
    };
    loadMappers(conf, mappers);

    sessionFactory = new SqlSessionFactoryBuilder().build(conf);
    return this;
  }