/** {@inheritDoc} */ public Configuration get() { final Configuration configuration = new Configuration(environment); configuration.setLazyLoadingEnabled(lazyLoadingEnabled); configuration.setAggressiveLazyLoading(aggressiveLazyLoading); configuration.setMultipleResultSetsEnabled(multipleResultSetsEnabled); configuration.setUseGeneratedKeys(useGeneratedKeys); configuration.setUseColumnLabel(useColumnLabel); configuration.setCacheEnabled(cacheEnabled); configuration.setDefaultExecutorType(defaultExecutorType); configuration.setAutoMappingBehavior(autoMappingBehavior); configuration.setObjectFactory(objectFactory); configuration.setObjectWrapperFactory(objectWrapperFactory); configuration.setDefaultScriptingLanguage(defaultScriptingLanguageType); configuration.setMapUnderscoreToCamelCase(mapUnderscoreToCamelCase); configuration.setCallSettersOnNulls(callSettersOnNulls); configuration.setDefaultStatementTimeout(defaultStatementTimeout); try { if (databaseIdProvider != null) { configuration.setDatabaseId(databaseIdProvider.getDatabaseId(dataSource)); } for (Map.Entry<String, Class<?>> alias : typeAliases.entrySet()) { configuration.getTypeAliasRegistry().registerAlias(alias.getKey(), alias.getValue()); } for (Map.Entry<Class<?>, TypeHandler<?>> typeHandler : typeHandlers.entrySet()) { registerTypeHandler(configuration, typeHandler.getKey(), typeHandler.getValue()); } for (TypeHandler<?> typeHandler : mappingTypeHandlers) { configuration.getTypeHandlerRegistry().register(typeHandler); } for (Class<?> mapperClass : mapperClasses) { if (!configuration.hasMapper(mapperClass)) { configuration.addMapper(mapperClass); } } for (Interceptor interceptor : plugins) { configuration.addInterceptor(interceptor); } if (failFast) { configuration.getMappedStatementNames(); } } catch (Throwable cause) { throw new ProvisionException( "An error occurred while building the org.apache.ibatis.session.Configuration", cause); } finally { ErrorContext.instance().reset(); } return configuration; }
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; }
@Override public void applyConfigurationSetting(Configuration configuration) { configuration.setUseGeneratedKeys(useGeneratedKeys); }