use of pro.taskana.exceptions.UnsupportedDatabaseException in project taskana by Taskana.
the class TaskanaEngineImpl method createSqlSessionManager.
/**
* This method creates the sqlSessionManager of myBatis. It integrates all the SQL mappers and sets the databaseId
* attribute.
*
* @return a {@link SqlSessionFactory}
*/
protected SqlSessionManager createSqlSessionManager() {
Environment environment = new Environment(DEFAULT, this.transactionFactory, taskanaEngineConfiguration.getDatasource());
Configuration configuration = new Configuration(environment);
// set databaseId
String databaseProductName;
try (Connection con = taskanaEngineConfiguration.getDatasource().getConnection()) {
databaseProductName = con.getMetaData().getDatabaseProductName();
if (databaseProductName.contains("DB2")) {
configuration.setDatabaseId("db2");
} else if (databaseProductName.contains("H2")) {
configuration.setDatabaseId("h2");
} else {
LOGGER.error("Method createSqlSessionManager() didn't find database with name {}. Throwing UnsupportedDatabaseException", databaseProductName);
throw new UnsupportedDatabaseException(databaseProductName);
}
} catch (SQLException e) {
LOGGER.error("Method createSqlSessionManager() could not open a connection to the database. No databaseId has been set.", e);
throw new SystemException("Method createSqlSessionManager() could not open a connection to the database. No databaseId has been set.");
}
// add mappers
configuration.addMapper(TaskMapper.class);
configuration.addMapper(TaskMonitorMapper.class);
configuration.addMapper(WorkbasketMapper.class);
configuration.addMapper(DistributionTargetMapper.class);
configuration.addMapper(ClassificationMapper.class);
configuration.addMapper(WorkbasketAccessMapper.class);
configuration.addMapper(ObjectReferenceMapper.class);
configuration.addMapper(QueryMapper.class);
configuration.addMapper(AttachmentMapper.class);
configuration.addMapper(JobMapper.class);
configuration.getTypeHandlerRegistry().register(MapTypeHandler.class);
SqlSessionFactory localSessionFactory = new SqlSessionFactoryBuilder().build(configuration);
return SqlSessionManager.newInstance(localSessionFactory);
}
Aggregations