use of io.quarkus.deployment.configuration.ConfigurationError in project quarkus-mybatis by quarkiverse.
the class MyBatisProcessor method generateSqlSessionFactory.
@Record(ExecutionTime.STATIC_INIT)
@BuildStep
void generateSqlSessionFactory(MyBatisRuntimeConfig myBatisRuntimeConfig, ConfigurationFactoryBuildItem configurationFactoryBuildItem, SqlSessionFactoryBuilderBuildItem sqlSessionFactoryBuilderBuildItem, List<MyBatisMapperBuildItem> myBatisMapperBuildItems, List<MyBatisMappedTypeBuildItem> myBatisMappedTypeBuildItems, List<MyBatisMappedJdbcTypeBuildItem> myBatisMappedJdbcTypeBuildItems, List<JdbcDataSourceBuildItem> jdbcDataSourcesBuildItem, BuildProducer<SqlSessionFactoryBuildItem> sqlSessionFactory, MyBatisRecorder recorder) {
List<String> mappedTypes = myBatisMappedTypeBuildItems.stream().map(m -> m.getMappedTypeName().toString()).collect(Collectors.toList());
List<String> mappedJdbcTypes = myBatisMappedJdbcTypeBuildItems.stream().map(m -> m.getMappedJdbcTypeName().toString()).collect(Collectors.toList());
List<Pair<String, Boolean>> dataSources = new ArrayList<>();
if (myBatisRuntimeConfig.dataSource.isPresent()) {
String dataSourceName = myBatisRuntimeConfig.dataSource.get();
Optional<JdbcDataSourceBuildItem> jdbcDataSourceBuildItem = jdbcDataSourcesBuildItem.stream().filter(i -> i.getName().equals(dataSourceName)).findFirst();
if (!jdbcDataSourceBuildItem.isPresent()) {
throw new ConfigurationError("Can not find datasource " + dataSourceName);
}
dataSources.add(Pair.of(dataSourceName, true));
} else {
dataSources = jdbcDataSourcesBuildItem.stream().map(dataSource -> Pair.of(dataSource.getName(), dataSource.isDefault())).collect(Collectors.toList());
if (dataSources.isEmpty()) {
throw new ConfigurationError("No datasource found");
}
}
dataSources.forEach(dataSource -> {
MyBatisDataSourceRuntimeConfig dataSourceConfig = myBatisRuntimeConfig.dataSources.get(dataSource.getKey());
List<String> mappers = myBatisMapperBuildItems.stream().filter(m -> m.getDataSourceName().equals(dataSource.getKey())).map(m -> m.getMapperName().toString()).collect(Collectors.toList());
sqlSessionFactory.produce(new SqlSessionFactoryBuildItem(recorder.createSqlSessionFactory(configurationFactoryBuildItem.getFactory(), sqlSessionFactoryBuilderBuildItem.getBuilder(), myBatisRuntimeConfig, dataSourceConfig, dataSource.getKey(), mappers, mappedTypes, mappedJdbcTypes), dataSource.getKey(), dataSource.getValue(), false));
});
}
Aggregations