/** {@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; }
/** * Creates the SQL schema during service start-up. Note: This design assumes a volatile database * engine. */ @Override @Transactional protected void startUp() throws IOException { Configuration configuration = sessionFactory.getConfiguration(); String createStatementName = "create_tables"; configuration.setMapUnderscoreToCamelCase(true); configuration.addMappedStatement( new Builder( configuration, createStatementName, new StaticSqlSource( configuration, CharStreams.toString( new InputStreamReader( DbStorage.class.getResourceAsStream("schema.sql"), Charsets.UTF_8))), SqlCommandType.UPDATE) .build()); try (SqlSession session = sessionFactory.openSession()) { session.update(createStatementName); } }