Java Code Examples for org.apache.ibatis.session.Configuration#setDatabaseId()

The following examples show how to use org.apache.ibatis.session.Configuration#setDatabaseId() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ProcessEngineConfigurationImpl.java    From activiti6-boot2 with Apache License 2.0 6 votes vote down vote up
public Configuration initMybatisConfiguration(Environment environment, Reader reader, Properties properties) {
  XMLConfigBuilder parser = new XMLConfigBuilder(reader, "", properties);
  Configuration configuration = parser.getConfiguration();

  if(databaseType != null) {
      configuration.setDatabaseId(databaseType);
  }

  configuration.setEnvironment(environment);

  initMybatisTypeHandlers(configuration);
  initCustomMybatisMappers(configuration);

  configuration = parseMybatisConfiguration(configuration, parser);
  return configuration;
}
 
Example 2
Source File: AbstractDataBaseBean.java    From spring-boot-starter-dao with Apache License 2.0 6 votes vote down vote up
protected final AbstractBeanDefinition createSqlSessionFactoryBean(String dataSourceName, String mapperPackage,
		String typeAliasesPackage, Dialect dialect, Configuration configuration) {
	configuration.setDatabaseId(dataSourceName);
	BeanDefinitionBuilder bdb = BeanDefinitionBuilder.rootBeanDefinition(SqlSessionFactoryBean.class);
	bdb.addPropertyValue("configuration", configuration);
	bdb.addPropertyValue("failFast", true);
	bdb.addPropertyValue("typeAliases", this.saenTypeAliases(typeAliasesPackage));
	bdb.addPropertyReference("dataSource", dataSourceName);
	bdb.addPropertyValue("plugins", new Interceptor[] { new CustomPageInterceptor(dialect) });
	if (!StringUtils.isEmpty(mapperPackage)) {
		try {
			mapperPackage = new StandardEnvironment().resolveRequiredPlaceholders(mapperPackage);
			String mapperPackages = ClassUtils.convertClassNameToResourcePath(mapperPackage);
			String mapperPackagePath = ResourcePatternResolver.CLASSPATH_ALL_URL_PREFIX + mapperPackages + "/*.xml";
			Resource[] resources = new PathMatchingResourcePatternResolver().getResources(mapperPackagePath);
			bdb.addPropertyValue("mapperLocations", resources);
		} catch (Exception e) {
			log.error("初始化失败", e);
			throw new RuntimeException( String.format("SqlSessionFactory 初始化失败  mapperPackage=%s", mapperPackage + ""));
		}
	}
	return bdb.getBeanDefinition();
}
 
Example 3
Source File: AbstractEngineConfiguration.java    From flowable-engine with Apache License 2.0 6 votes vote down vote up
public Configuration initMybatisConfiguration(Environment environment, Reader reader, Properties properties) {
    XMLConfigBuilder parser = new XMLConfigBuilder(reader, "", properties);
    Configuration configuration = parser.getConfiguration();

    if (databaseType != null) {
        configuration.setDatabaseId(databaseType);
    }

    configuration.setEnvironment(environment);

    initCustomMybatisMappers(configuration);
    initMybatisTypeHandlers(configuration);
    initCustomMybatisInterceptors(configuration);
    if (isEnableLogSqlExecutionTime()) {
        initMyBatisLogSqlExecutionTimePlugin(configuration);
    }

    configuration = parseMybatisConfiguration(parser);
    return configuration;
}
 
Example 4
Source File: FormEngineConfiguration.java    From activiti6-boot2 with Apache License 2.0 5 votes vote down vote up
public Configuration initMybatisConfiguration(Environment environment, Reader reader, Properties properties) {
  XMLConfigBuilder parser = new XMLConfigBuilder(reader, "", properties);
  Configuration configuration = parser.getConfiguration();

  if (databaseType != null) {
    configuration.setDatabaseId(databaseType);
  }

  configuration.setEnvironment(environment);

  initCustomMybatisMappers(configuration);

  configuration = parseMybatisConfiguration(configuration, parser);
  return configuration;
}
 
Example 5
Source File: DmnEngineConfiguration.java    From activiti6-boot2 with Apache License 2.0 5 votes vote down vote up
public Configuration initMybatisConfiguration(Environment environment, Reader reader, Properties properties) {
  XMLConfigBuilder parser = new XMLConfigBuilder(reader, "", properties);
  Configuration configuration = parser.getConfiguration();

  if (databaseType != null) {
    configuration.setDatabaseId(databaseType);
  }

  configuration.setEnvironment(environment);

  initCustomMybatisMappers(configuration);

  configuration = parseMybatisConfiguration(configuration, parser);
  return configuration;
}
 
Example 6
Source File: TaskQueryImplTest.java    From taskana with Apache License 2.0 5 votes vote down vote up
@BeforeEach
void setup() {
  when(internalTaskanaEngine.getEngine()).thenReturn(taskanaEngine);
  when(taskanaEngine.getTaskService()).thenReturn(taskServiceMock);

  Configuration configuration = new org.apache.ibatis.session.Configuration();
  configuration.setDatabaseId(DB.H2.dbProductId);
  when(internalTaskanaEngine.getSqlSession()).thenReturn(sqlSession);
  when(sqlSession.getConfiguration()).thenReturn(configuration);

  taskQueryImpl = new TaskQueryImpl(internalTaskanaEngine);
}
 
Example 7
Source File: AbstractDataBaseBean.java    From spring-boot-starter-dao with Apache License 2.0 5 votes vote down vote up
protected Configuration cloneConfiguration(Configuration configuration) { 
	Configuration relust=new Configuration();
	relust.setEnvironment(configuration.getEnvironment());
	relust.setSafeRowBoundsEnabled(configuration.isSafeRowBoundsEnabled());
	relust.setSafeResultHandlerEnabled(configuration.isSafeResultHandlerEnabled());
	relust.setMapUnderscoreToCamelCase(configuration.isMapUnderscoreToCamelCase());
	relust.setAggressiveLazyLoading(configuration.isAggressiveLazyLoading());
	relust.setMultipleResultSetsEnabled(configuration.isMultipleResultSetsEnabled());
	relust.setUseGeneratedKeys(configuration.isUseGeneratedKeys());
	relust.setUseColumnLabel(configuration.isUseColumnLabel());
	relust.setCacheEnabled(configuration.isCacheEnabled());
	relust.setCallSettersOnNulls(configuration.isCallSettersOnNulls());
	relust.setUseActualParamName(configuration.isUseActualParamName());
	relust.setReturnInstanceForEmptyRow(configuration.isReturnInstanceForEmptyRow());
	relust.setLogPrefix(configuration.getLogPrefix());
	relust.setLogImpl(configuration.getLogImpl());
	relust.setVfsImpl(configuration.getVfsImpl());
	relust.setLocalCacheScope(configuration.getLocalCacheScope());
	relust.setJdbcTypeForNull(configuration.getJdbcTypeForNull());
	relust.setLazyLoadTriggerMethods(configuration.getLazyLoadTriggerMethods());
	relust.setDefaultStatementTimeout(configuration.getDefaultStatementTimeout());
	relust.setDefaultFetchSize(configuration.getDefaultFetchSize());
	relust.setDefaultExecutorType(configuration.getDefaultExecutorType());
	relust.setAutoMappingBehavior(configuration.getAutoMappingBehavior());
	relust.setAutoMappingUnknownColumnBehavior(configuration.getAutoMappingUnknownColumnBehavior());
	relust.setVariables(configuration.getVariables());
	relust.setReflectorFactory(configuration.getReflectorFactory());
	relust.setObjectFactory(configuration.getObjectFactory());
	relust.setObjectWrapperFactory(configuration.getObjectWrapperFactory());
	relust.setLazyLoadingEnabled(configuration.isLazyLoadingEnabled());
	relust.setProxyFactory(configuration.getProxyFactory());
	relust.setDatabaseId(configuration.getDatabaseId());
	relust.setConfigurationFactory(configuration.getConfigurationFactory());
	relust.getTypeHandlerRegistry().setDefaultEnumTypeHandler(GlobalEnumTypeHandler.class);
	return relust;
}
 
Example 8
Source File: PlaceholderTypesTest.java    From nexus-public with Eclipse Public License 1.0 5 votes vote down vote up
@Test
public void hasBuiltInDefaultsForH2() {
  Configuration config = new Configuration();
  config.setDatabaseId("H2");

  configurePlaceholderTypes(config);

  assertThat(config.getVariables().get("UUID_TYPE"), is("UUID"));
  assertThat(config.getVariables().get("JSON_TYPE"), is("JSON"));
  assertThat(config.getVariables().get("BINARY_TYPE"), is("BYTEA"));
}
 
Example 9
Source File: PlaceholderTypesTest.java    From nexus-public with Eclipse Public License 1.0 5 votes vote down vote up
@Test
public void hasBuiltInDefaultsForPostgreSQL() {
  Configuration config = new Configuration();
  config.setDatabaseId("PostgreSQL");

  configurePlaceholderTypes(config);

  assertThat(config.getVariables().get("UUID_TYPE"), is("UUID"));
  assertThat(config.getVariables().get("JSON_TYPE"), is("JSONB"));
  assertThat(config.getVariables().get("BINARY_TYPE"), is("BYTEA"));
}
 
Example 10
Source File: PlaceholderTypesTest.java    From nexus-public with Eclipse Public License 1.0 5 votes vote down vote up
@Test
public void canSupplyTypesForOtherDatabases() {
  Configuration config = new Configuration();
  config.setDatabaseId("MyDB");

  config.getVariables().setProperty("UUID_TYPE.MyDB", "CHARACTER VARYING (36)");
  config.getVariables().setProperty("JSON_TYPE.MyDB", "CLOB");
  config.getVariables().setProperty("BINARY_TYPE.MyDB", "BLOB");

  configurePlaceholderTypes(config);

  assertThat(config.getVariables().get("UUID_TYPE"), is("CHARACTER VARYING (36)"));
  assertThat(config.getVariables().get("JSON_TYPE"), is("CLOB"));
  assertThat(config.getVariables().get("BINARY_TYPE"), is("BLOB"));
}
 
Example 11
Source File: PlaceholderTypesTest.java    From nexus-public with Eclipse Public License 1.0 5 votes vote down vote up
@Test
public void failOnMissingType() {
  Configuration config = new Configuration();
  config.setDatabaseId("MyDB");
  try {
    configurePlaceholderTypes(config);
    fail("Expected IllegalArgumentException");
  }
  catch (IllegalArgumentException e) {
    assertThat(e.getMessage(), containsString("No database type configured for UUID_TYPE.MyDB"));
  }
}
 
Example 12
Source File: PlaceholderTypesTest.java    From nexus-public with Eclipse Public License 1.0 5 votes vote down vote up
@Test
public void failOnInvalidTypes() {
  Configuration config = new Configuration();
  config.setDatabaseId("MyDB");

  assertTypeIsInvalid(config, "1");
  assertTypeIsInvalid(config, "A1");
  assertTypeIsInvalid(config, "AA ");
  assertTypeIsInvalid(config, "AA 2");
  assertTypeIsInvalid(config, "AA B2");
  assertTypeIsInvalid(config, "AA BB ");
  assertTypeIsInvalid(config, "AA BB 3");
  assertTypeIsInvalid(config, "AA BB C");
  assertTypeIsInvalid(config, "A(");
  assertTypeIsInvalid(config, "A)");
  assertTypeIsInvalid(config, "A()");
  assertTypeIsInvalid(config, "A(B)");
  assertTypeIsInvalid(config, "A(1");
  assertTypeIsInvalid(config, "A(1(");
  assertTypeIsInvalid(config, "A  (1)");
  assertTypeIsInvalid(config, "A B(");
  assertTypeIsInvalid(config, "A B)");
  assertTypeIsInvalid(config, "A B()");
  assertTypeIsInvalid(config, "A B(C)");
  assertTypeIsInvalid(config, "A B(2");
  assertTypeIsInvalid(config, "A B(2(");
  assertTypeIsInvalid(config, "A B  (2)");

  assertTypeIsValid(config, "A");
  assertTypeIsValid(config, "AA BB");
  assertTypeIsValid(config, "A(1)");
  assertTypeIsValid(config, "A (1)");
  assertTypeIsValid(config, "A B(2)");
  assertTypeIsValid(config, "A B (2)");
}
 
Example 13
Source File: TaskanaEngineImpl.java    From taskana with Apache License 2.0 4 votes vote down vote up
/**
 * 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();
    String databaseProductId = DB.getDatabaseProductId(databaseProductName);
    configuration.setDatabaseId(databaseProductId);

  } catch (SQLException e) {
    throw new SystemException(
        "Method createSqlSessionManager() could not open a connection "
            + "to the database. No databaseId has been set.",
        e.getCause());
  }

  // register type handlers
  configuration.getTypeHandlerRegistry().register(new MapTypeHandler());
  configuration.getTypeHandlerRegistry().register(Instant.class, new InstantTypeHandler());
  configuration.getTypeHandlerRegistry().register(JdbcType.TIMESTAMP, new InstantTypeHandler());
  // add mappers
  configuration.addMapper(TaskMapper.class);
  configuration.addMapper(MonitorMapper.class);
  configuration.addMapper(WorkbasketMapper.class);
  configuration.addMapper(DistributionTargetMapper.class);
  configuration.addMapper(ClassificationMapper.class);
  configuration.addMapper(WorkbasketAccessMapper.class);
  configuration.addMapper(ObjectReferenceMapper.class);
  configuration.addMapper(WorkbasketQueryMapper.class);
  configuration.addMapper(TaskQueryMapper.class);
  configuration.addMapper(TaskCommentMapper.class);
  configuration.addMapper(ClassificationQueryMapper.class);
  configuration.addMapper(AttachmentMapper.class);
  configuration.addMapper(JobMapper.class);
  SqlSessionFactory localSessionFactory = new SqlSessionFactoryBuilder().build(configuration);
  return SqlSessionManager.newInstance(localSessionFactory);
}