Java 类org.apache.ibatis.session.LocalCacheScope 实例源码

项目:mybatis    文件:XMLConfigBuilder.java   
private void settingsElement(Properties props) throws Exception {
  configuration.setAutoMappingBehavior(AutoMappingBehavior.valueOf(props.getProperty("autoMappingBehavior", "PARTIAL")));
  configuration.setAutoMappingUnknownColumnBehavior(AutoMappingUnknownColumnBehavior.valueOf(props.getProperty("autoMappingUnknownColumnBehavior", "NONE")));
  configuration.setCacheEnabled(booleanValueOf(props.getProperty("cacheEnabled"), true));
  configuration.setProxyFactory((ProxyFactory) createInstance(props.getProperty("proxyFactory")));
  configuration.setLazyLoadingEnabled(booleanValueOf(props.getProperty("lazyLoadingEnabled"), false));
  configuration.setAggressiveLazyLoading(booleanValueOf(props.getProperty("aggressiveLazyLoading"), true));
  configuration.setMultipleResultSetsEnabled(booleanValueOf(props.getProperty("multipleResultSetsEnabled"), true));
  configuration.setUseColumnLabel(booleanValueOf(props.getProperty("useColumnLabel"), true));
  configuration.setUseGeneratedKeys(booleanValueOf(props.getProperty("useGeneratedKeys"), false));
  configuration.setDefaultExecutorType(ExecutorType.valueOf(props.getProperty("defaultExecutorType", "SIMPLE")));
  configuration.setDefaultStatementTimeout(integerValueOf(props.getProperty("defaultStatementTimeout"), null));
  configuration.setDefaultFetchSize(integerValueOf(props.getProperty("defaultFetchSize"), null));
  configuration.setMapUnderscoreToCamelCase(booleanValueOf(props.getProperty("mapUnderscoreToCamelCase"), false));
  configuration.setSafeRowBoundsEnabled(booleanValueOf(props.getProperty("safeRowBoundsEnabled"), false));
  configuration.setLocalCacheScope(LocalCacheScope.valueOf(props.getProperty("localCacheScope", "SESSION")));
  configuration.setJdbcTypeForNull(JdbcType.valueOf(props.getProperty("jdbcTypeForNull", "OTHER")));
  configuration.setLazyLoadTriggerMethods(stringSetValueOf(props.getProperty("lazyLoadTriggerMethods"), "equals,clone,hashCode,toString"));
  configuration.setSafeResultHandlerEnabled(booleanValueOf(props.getProperty("safeResultHandlerEnabled"), true));
  configuration.setDefaultScriptingLanguage(resolveClass(props.getProperty("defaultScriptingLanguage")));
  configuration.setCallSettersOnNulls(booleanValueOf(props.getProperty("callSettersOnNulls"), false));
  configuration.setLogPrefix(props.getProperty("logPrefix"));
  configuration.setLogImpl(resolveClass(props.getProperty("logImpl")));
  configuration.setConfigurationFactory(resolveClass(props.getProperty("configurationFactory")));
}
项目:spring-boot-sample    文件:XMLConfigBuilder.java   
private void settingsElement(Properties props) throws Exception {
    configuration.setAutoMappingBehavior(AutoMappingBehavior.valueOf(props.getProperty("autoMappingBehavior", "PARTIAL")));
    configuration.setAutoMappingUnknownColumnBehavior(AutoMappingUnknownColumnBehavior.valueOf(props.getProperty("autoMappingUnknownColumnBehavior", "NONE")));
    configuration.setCacheEnabled(booleanValueOf(props.getProperty("cacheEnabled"), true));
    configuration.setProxyFactory((ProxyFactory) createInstance(props.getProperty("proxyFactory")));
    configuration.setLazyLoadingEnabled(booleanValueOf(props.getProperty("lazyLoadingEnabled"), false));
    configuration.setAggressiveLazyLoading(booleanValueOf(props.getProperty("aggressiveLazyLoading"), true));
    configuration.setMultipleResultSetsEnabled(booleanValueOf(props.getProperty("multipleResultSetsEnabled"), true));
    configuration.setUseColumnLabel(booleanValueOf(props.getProperty("useColumnLabel"), true));
    configuration.setUseGeneratedKeys(booleanValueOf(props.getProperty("useGeneratedKeys"), false));
    configuration.setDefaultExecutorType(ExecutorType.valueOf(props.getProperty("defaultExecutorType", "SIMPLE")));
    configuration.setDefaultStatementTimeout(integerValueOf(props.getProperty("defaultStatementTimeout"), null));
    configuration.setDefaultFetchSize(integerValueOf(props.getProperty("defaultFetchSize"), null));
    configuration.setMapUnderscoreToCamelCase(booleanValueOf(props.getProperty("mapUnderscoreToCamelCase"), false));
    configuration.setSafeRowBoundsEnabled(booleanValueOf(props.getProperty("safeRowBoundsEnabled"), false));
    configuration.setLocalCacheScope(LocalCacheScope.valueOf(props.getProperty("localCacheScope", "SESSION")));
    configuration.setJdbcTypeForNull(JdbcType.valueOf(props.getProperty("jdbcTypeForNull", "OTHER")));
    configuration.setLazyLoadTriggerMethods(stringSetValueOf(props.getProperty("lazyLoadTriggerMethods"), "equals,clone,hashCode,toString"));
    configuration.setSafeResultHandlerEnabled(booleanValueOf(props.getProperty("safeResultHandlerEnabled"), true));
    configuration.setDefaultScriptingLanguage(resolveClass(props.getProperty("defaultScriptingLanguage")));
    configuration.setCallSettersOnNulls(booleanValueOf(props.getProperty("callSettersOnNulls"), false));
    configuration.setLogPrefix(props.getProperty("logPrefix"));
    configuration.setLogImpl(resolveClass(props.getProperty("logImpl")));
    configuration.setConfigurationFactory(resolveClass(props.getProperty("configurationFactory")));
}
项目:mybatis-plus-mini    文件:MybatisXMLConfigBuilder.java   
private void settingsElement(Properties props) throws Exception {
    configuration.setAutoMappingBehavior(AutoMappingBehavior.valueOf(props.getProperty("autoMappingBehavior", "PARTIAL")));
    configuration.setAutoMappingUnknownColumnBehavior(AutoMappingUnknownColumnBehavior.valueOf(props.getProperty("autoMappingUnknownColumnBehavior", "NONE")));
    configuration.setCacheEnabled(booleanValueOf(props.getProperty("cacheEnabled"), true));
    configuration.setProxyFactory((ProxyFactory) createInstance(props.getProperty("proxyFactory")));
    configuration.setLazyLoadingEnabled(booleanValueOf(props.getProperty("lazyLoadingEnabled"), false));
    configuration.setAggressiveLazyLoading(booleanValueOf(props.getProperty("aggressiveLazyLoading"), false));
    configuration.setMultipleResultSetsEnabled(booleanValueOf(props.getProperty("multipleResultSetsEnabled"), true));
    configuration.setUseColumnLabel(booleanValueOf(props.getProperty("useColumnLabel"), true));
    configuration.setUseGeneratedKeys(booleanValueOf(props.getProperty("useGeneratedKeys"), false));
    configuration.setDefaultExecutorType(ExecutorType.valueOf(props.getProperty("defaultExecutorType", "SIMPLE")));
    configuration.setDefaultStatementTimeout(integerValueOf(props.getProperty("defaultStatementTimeout"), null));
    configuration.setDefaultFetchSize(integerValueOf(props.getProperty("defaultFetchSize"), null));
    configuration.setMapUnderscoreToCamelCase(booleanValueOf(props.getProperty("mapUnderscoreToCamelCase"), false));
    configuration.setSafeRowBoundsEnabled(booleanValueOf(props.getProperty("safeRowBoundsEnabled"), false));
    configuration.setLocalCacheScope(LocalCacheScope.valueOf(props.getProperty("localCacheScope", "SESSION")));
    configuration.setJdbcTypeForNull(JdbcType.valueOf(props.getProperty("jdbcTypeForNull", "OTHER")));
    configuration.setLazyLoadTriggerMethods(stringSetValueOf(props.getProperty("lazyLoadTriggerMethods"), "equals,clone,hashCode,toString"));
    configuration.setSafeResultHandlerEnabled(booleanValueOf(props.getProperty("safeResultHandlerEnabled"), true));
    configuration.setDefaultScriptingLanguage(resolveClass(props.getProperty("defaultScriptingLanguage")));
    configuration.setCallSettersOnNulls(booleanValueOf(props.getProperty("callSettersOnNulls"), false));
    configuration.setUseActualParamName(booleanValueOf(props.getProperty("useActualParamName"), true));
    configuration.setReturnInstanceForEmptyRow(booleanValueOf(props.getProperty("returnInstanceForEmptyRow"), false));
    configuration.setLogPrefix(props.getProperty("logPrefix"));
    @SuppressWarnings("unchecked")
    Class<? extends Log> logImpl = (Class<? extends Log>) resolveClass(props.getProperty("logImpl"));
    configuration.setLogImpl(logImpl);
    configuration.setConfigurationFactory(resolveClass(props.getProperty("configurationFactory")));
}
项目:alfresco-core    文件:HierarchicalXMLConfigBuilder.java   
private void settingsElement(XNode context) throws Exception {
    if (context != null) {
        Properties props = context.getChildrenAsProperties();
        // Check that all settings are known to the configuration class
        MetaClass metaConfig = MetaClass.forClass(Configuration.class, localReflectorFactory);
        for (Object key : props.keySet()) {
            if (!metaConfig.hasSetter(String.valueOf(key))) {
                throw new BuilderException("The setting " + key + " is not known.  Make sure you spelled it correctly (case sensitive).");
            }
        }
        configuration.setAutoMappingBehavior(AutoMappingBehavior.valueOf(props.getProperty("autoMappingBehavior", "PARTIAL")));
        configuration.setCacheEnabled(booleanValueOf(props.getProperty("cacheEnabled"), true));
        configuration.setProxyFactory((ProxyFactory) createInstance(props.getProperty("proxyFactory")));
        configuration.setLazyLoadingEnabled(booleanValueOf(props.getProperty("lazyLoadingEnabled"), false));
        configuration.setAggressiveLazyLoading(booleanValueOf(props.getProperty("aggressiveLazyLoading"), true));
        configuration.setMultipleResultSetsEnabled(booleanValueOf(props.getProperty("multipleResultSetsEnabled"), true));
        configuration.setUseColumnLabel(booleanValueOf(props.getProperty("useColumnLabel"), true));
        configuration.setUseGeneratedKeys(booleanValueOf(props.getProperty("useGeneratedKeys"), false));
        configuration.setDefaultExecutorType(ExecutorType.valueOf(props.getProperty("defaultExecutorType", "SIMPLE")));
        configuration.setDefaultStatementTimeout(integerValueOf(props.getProperty("defaultStatementTimeout"), null));
        configuration.setDefaultFetchSize(integerValueOf(props.getProperty("defaultFetchSize"), null));
        configuration.setMapUnderscoreToCamelCase(booleanValueOf(props.getProperty("mapUnderscoreToCamelCase"), false));
        configuration.setSafeRowBoundsEnabled(booleanValueOf(props.getProperty("safeRowBoundsEnabled"), false));
        configuration.setLocalCacheScope(LocalCacheScope.valueOf(props.getProperty("localCacheScope", "SESSION")));
        configuration.setJdbcTypeForNull(JdbcType.valueOf(props.getProperty("jdbcTypeForNull", "OTHER")));
        configuration.setLazyLoadTriggerMethods(stringSetValueOf(props.getProperty("lazyLoadTriggerMethods"), "equals,clone,hashCode,toString"));
        configuration.setSafeResultHandlerEnabled(booleanValueOf(props.getProperty("safeResultHandlerEnabled"), true));
        configuration.setDefaultScriptingLanguage(resolveClass(props.getProperty("defaultScriptingLanguage")));
        configuration.setCallSettersOnNulls(booleanValueOf(props.getProperty("callSettersOnNulls"), false));
        configuration.setLogPrefix(props.getProperty("logPrefix"));
        configuration.setLogImpl(resolveClass(props.getProperty("logImpl")));
    }
}
项目:MybatisCode    文件:XMLConfigBuilder.java   
private void settingsElement(Properties props) throws Exception {
  configuration.setAutoMappingBehavior(AutoMappingBehavior.valueOf(props.getProperty("autoMappingBehavior", "PARTIAL")));
  configuration.setAutoMappingUnknownColumnBehavior(AutoMappingUnknownColumnBehavior.valueOf(props.getProperty("autoMappingUnknownColumnBehavior", "NONE")));
  configuration.setCacheEnabled(booleanValueOf(props.getProperty("cacheEnabled"), true));
  configuration.setProxyFactory((ProxyFactory) createInstance(props.getProperty("proxyFactory")));
  configuration.setLazyLoadingEnabled(booleanValueOf(props.getProperty("lazyLoadingEnabled"), false));
  configuration.setAggressiveLazyLoading(booleanValueOf(props.getProperty("aggressiveLazyLoading"), true));
  configuration.setMultipleResultSetsEnabled(booleanValueOf(props.getProperty("multipleResultSetsEnabled"), true));
  configuration.setUseColumnLabel(booleanValueOf(props.getProperty("useColumnLabel"), true));
  configuration.setUseGeneratedKeys(booleanValueOf(props.getProperty("useGeneratedKeys"), false));
  configuration.setDefaultExecutorType(ExecutorType.valueOf(props.getProperty("defaultExecutorType", "SIMPLE")));
  configuration.setDefaultStatementTimeout(integerValueOf(props.getProperty("defaultStatementTimeout"), null));
  configuration.setDefaultFetchSize(integerValueOf(props.getProperty("defaultFetchSize"), null));
  configuration.setMapUnderscoreToCamelCase(booleanValueOf(props.getProperty("mapUnderscoreToCamelCase"), false));
  configuration.setSafeRowBoundsEnabled(booleanValueOf(props.getProperty("safeRowBoundsEnabled"), false));
  configuration.setLocalCacheScope(LocalCacheScope.valueOf(props.getProperty("localCacheScope", "SESSION")));
  configuration.setJdbcTypeForNull(JdbcType.valueOf(props.getProperty("jdbcTypeForNull", "OTHER")));
  configuration.setLazyLoadTriggerMethods(stringSetValueOf(props.getProperty("lazyLoadTriggerMethods"), "equals,clone,hashCode,toString"));
  configuration.setSafeResultHandlerEnabled(booleanValueOf(props.getProperty("safeResultHandlerEnabled"), true));
  configuration.setDefaultScriptingLanguage(resolveClass(props.getProperty("defaultScriptingLanguage")));
  configuration.setCallSettersOnNulls(booleanValueOf(props.getProperty("callSettersOnNulls"), false));
  configuration.setUseActualParamName(booleanValueOf(props.getProperty("useActualParamName"), true));
  configuration.setLogPrefix(props.getProperty("logPrefix"));
  @SuppressWarnings("unchecked")
  Class<? extends Log> logImpl = (Class<? extends Log>)resolveClass(props.getProperty("logImpl"));
  configuration.setLogImpl(logImpl);
  configuration.setConfigurationFactory(resolveClass(props.getProperty("configurationFactory")));
}
项目:MybatisCode    文件:BaseExecutor.java   
@SuppressWarnings("unchecked")
@Override
public <E> List<E> query(MappedStatement ms, Object parameter, RowBounds rowBounds, ResultHandler resultHandler, CacheKey key, BoundSql boundSql) throws SQLException {
  ErrorContext.instance().resource(ms.getResource()).activity("executing a query").object(ms.getId());
  if (closed) {
    throw new ExecutorException("Executor was closed.");
  }
  if (queryStack == 0 && ms.isFlushCacheRequired()) {
    clearLocalCache();
  }
  List<E> list;
  try {
    queryStack++;
    list = resultHandler == null ? (List<E>) localCache.getObject(key) : null;
    if (list != null) {
      handleLocallyCachedOutputParameters(ms, key, parameter, boundSql);
    } else {
      list = queryFromDatabase(ms, parameter, rowBounds, resultHandler, key, boundSql);
    }
  } finally {
    queryStack--;
  }
  if (queryStack == 0) {
    for (DeferredLoad deferredLoad : deferredLoads) {
      deferredLoad.load();
    }
    // issue #601
    deferredLoads.clear();
    if (configuration.getLocalCacheScope() == LocalCacheScope.STATEMENT) {
      // issue #482
      clearLocalCache();
    }
  }
  return list;
}
项目:MybatisCode    文件:ForceFlushOnSelectTest.java   
@Test
public void testSelectShouldFlushLocalCacheIfFlushLocalCacheAtferEachStatementIsTrue() throws SQLException {
  sqlSessionFactory.getConfiguration().setLocalCacheScope(LocalCacheScope.STATEMENT);
  SqlSession sqlSession = sqlSessionFactory.openSession(ExecutorType.SIMPLE);
  try {
    PersonMapper personMapper = sqlSession.getMapper(PersonMapper.class);
    List<Person> people = personMapper.selectAllNoFlush();
    updateDatabase(sqlSession.getConnection());
    people = personMapper.selectAllFlush();
    assertEquals("Simone", people.get(0).getFirstName());
    sqlSession.commit();
  } finally {
    sqlSession.close();
  }
}
项目:MybatisCode    文件:XmlConfigBuilderTest.java   
@Test
public void shouldSuccessfullyLoadMinimalXMLConfigFile() throws Exception {
  String resource = "org/apache/ibatis/builder/MinimalMapperConfig.xml";
  InputStream inputStream = Resources.getResourceAsStream(resource);
  XMLConfigBuilder builder = new XMLConfigBuilder(inputStream);
  Configuration config = builder.parse();
  assertNotNull(config);
  assertThat(config.getAutoMappingBehavior(), is(AutoMappingBehavior.PARTIAL));
  assertThat(config.getAutoMappingUnknownColumnBehavior(), is(AutoMappingUnknownColumnBehavior.NONE));
  assertThat(config.isCacheEnabled(), is(true));
  assertThat(config.getProxyFactory(), is(instanceOf(JavassistProxyFactory.class)));
  assertThat(config.isLazyLoadingEnabled(), is(false));
  assertThat(config.isAggressiveLazyLoading(), is(true));
  assertThat(config.isMultipleResultSetsEnabled(), is(true));
  assertThat(config.isUseColumnLabel(), is(true));
  assertThat(config.isUseGeneratedKeys(), is(false));
  assertThat(config.getDefaultExecutorType(), is(ExecutorType.SIMPLE));
  assertNull(config.getDefaultStatementTimeout());
  assertNull(config.getDefaultFetchSize());
  assertThat(config.isMapUnderscoreToCamelCase(), is(false));
  assertThat(config.isSafeRowBoundsEnabled(), is(false));
  assertThat(config.getLocalCacheScope(), is(LocalCacheScope.SESSION));
  assertThat(config.getJdbcTypeForNull(), is(JdbcType.OTHER));
  assertThat(config.getLazyLoadTriggerMethods(), is((Set<String>) new HashSet<String>(Arrays.asList("equals", "clone", "hashCode", "toString"))));
  assertThat(config.isSafeResultHandlerEnabled(), is(true));
    assertThat(config.getDefaultScriptingLanuageInstance(), is(instanceOf(XMLLanguageDriver.class)));
  assertThat(config.isCallSettersOnNulls(), is(false));
  assertNull(config.getLogPrefix());
  assertNull(config.getLogImpl());
  assertNull(config.getConfigurationFactory());
}
项目:mybatis    文件:ForceFlushOnSelectTest.java   
@Test
public void testSelectShouldFlushLocalCacheIfFlushLocalCacheAtferEachStatementIsTrue() throws SQLException {
  sqlSessionFactory.getConfiguration().setLocalCacheScope(LocalCacheScope.STATEMENT);
  SqlSession sqlSession = sqlSessionFactory.openSession(ExecutorType.SIMPLE);
  try {
    PersonMapper personMapper = sqlSession.getMapper(PersonMapper.class);
    List<Person> people = personMapper.selectAllNoFlush();
    updateDatabase(sqlSession.getConnection());
    people = personMapper.selectAllFlush();
    assertEquals("Simone", people.get(0).getFirstName());
    sqlSession.commit();
  } finally {
    sqlSession.close();
  }
}
项目:mybatis    文件:XmlConfigBuilderTest.java   
@Test
public void shouldSuccessfullyLoadMinimalXMLConfigFile() throws Exception {
  String resource = "org/apache/ibatis/builder/MinimalMapperConfig.xml";
  InputStream inputStream = Resources.getResourceAsStream(resource);
  XMLConfigBuilder builder = new XMLConfigBuilder(inputStream);
  Configuration config = builder.parse();
  assertNotNull(config);
  assertThat(config.getAutoMappingBehavior(), is(AutoMappingBehavior.PARTIAL));
  assertThat(config.getAutoMappingUnknownColumnBehavior(), is(AutoMappingUnknownColumnBehavior.NONE));
  assertThat(config.isCacheEnabled(), is(true));
  assertThat(config.getProxyFactory(), is(instanceOf(JavassistProxyFactory.class)));
  assertThat(config.isLazyLoadingEnabled(), is(false));
  assertThat(config.isAggressiveLazyLoading(), is(true));
  assertThat(config.isMultipleResultSetsEnabled(), is(true));
  assertThat(config.isUseColumnLabel(), is(true));
  assertThat(config.isUseGeneratedKeys(), is(false));
  assertThat(config.getDefaultExecutorType(), is(ExecutorType.SIMPLE));
  assertNull(config.getDefaultStatementTimeout());
  assertNull(config.getDefaultFetchSize());
  assertThat(config.isMapUnderscoreToCamelCase(), is(false));
  assertThat(config.isSafeRowBoundsEnabled(), is(false));
  assertThat(config.getLocalCacheScope(), is(LocalCacheScope.SESSION));
  assertThat(config.getJdbcTypeForNull(), is(JdbcType.OTHER));
  assertThat(config.getLazyLoadTriggerMethods(), is((Set<String>) new HashSet<String>(Arrays.asList("equals", "clone", "hashCode", "toString"))));
  assertThat(config.isSafeResultHandlerEnabled(), is(true));
    assertThat(config.getDefaultScriptingLanuageInstance(), is(instanceOf(XMLLanguageDriver.class)));
  assertThat(config.isCallSettersOnNulls(), is(false));
  assertNull(config.getLogPrefix());
  assertNull(config.getLogImpl());
  assertNull(config.getConfigurationFactory());
}
项目:mybatis    文件:XmlConfigBuilderTest.java   
@Test
public void shouldSuccessfullyLoadXMLConfigFile() throws Exception {
  String resource = "org/apache/ibatis/builder/CustomizedSettingsMapperConfig.xml";
  InputStream inputStream = Resources.getResourceAsStream(resource);
  XMLConfigBuilder builder = new XMLConfigBuilder(inputStream);
  Configuration config = builder.parse();

  assertThat(config.getAutoMappingBehavior(), is(AutoMappingBehavior.NONE));
  assertThat(config.getAutoMappingUnknownColumnBehavior(), is(AutoMappingUnknownColumnBehavior.WARNING));
  assertThat(config.isCacheEnabled(), is(false));
  assertThat(config.getProxyFactory(), is(instanceOf(CglibProxyFactory.class)));
  assertThat(config.isLazyLoadingEnabled(), is(true));
  assertThat(config.isAggressiveLazyLoading(), is(false));
  assertThat(config.isMultipleResultSetsEnabled(), is(false));
  assertThat(config.isUseColumnLabel(), is(false));
  assertThat(config.isUseGeneratedKeys(), is(true));
  assertThat(config.getDefaultExecutorType(), is(ExecutorType.BATCH));
  assertThat(config.getDefaultStatementTimeout(), is(10));
  assertThat(config.getDefaultFetchSize(), is(100));
  assertThat(config.isMapUnderscoreToCamelCase(), is(true));
  assertThat(config.isSafeRowBoundsEnabled(), is(true));
  assertThat(config.getLocalCacheScope(), is(LocalCacheScope.STATEMENT));
  assertThat(config.getJdbcTypeForNull(), is(JdbcType.NULL));
  assertThat(config.getLazyLoadTriggerMethods(), is((Set<String>) new HashSet<String>(Arrays.asList("equals", "clone", "hashCode", "toString", "xxx"))));
  assertThat(config.isSafeResultHandlerEnabled(), is(false));
  assertThat(config.getDefaultScriptingLanuageInstance(), is(instanceOf(RawLanguageDriver.class)));
  assertThat(config.isCallSettersOnNulls(), is(true));
  assertThat(config.getLogPrefix(), is("mybatis_"));
  assertThat(config.getLogImpl().getName(), is(Slf4jImpl.class.getName()));
  assertThat(config.getVfsImpl().getName(), is(JBoss6VFS.class.getName()));
  assertThat(config.getConfigurationFactory().getName(), is(String.class.getName()));

}
项目:mybatis-plus    文件:MybatisXMLConfigBuilder.java   
private void settingsElement(Properties props) throws Exception {
    configuration.setAutoMappingBehavior(AutoMappingBehavior.valueOf(props.getProperty("autoMappingBehavior", "PARTIAL")));
    configuration.setAutoMappingUnknownColumnBehavior(AutoMappingUnknownColumnBehavior.valueOf(props.getProperty("autoMappingUnknownColumnBehavior", "NONE")));
    configuration.setCacheEnabled(booleanValueOf(props.getProperty("cacheEnabled"), true));
    configuration.setProxyFactory((ProxyFactory) createInstance(props.getProperty("proxyFactory")));
    configuration.setLazyLoadingEnabled(booleanValueOf(props.getProperty("lazyLoadingEnabled"), false));
    configuration.setAggressiveLazyLoading(booleanValueOf(props.getProperty("aggressiveLazyLoading"), false));
    configuration.setMultipleResultSetsEnabled(booleanValueOf(props.getProperty("multipleResultSetsEnabled"), true));
    configuration.setUseColumnLabel(booleanValueOf(props.getProperty("useColumnLabel"), true));
    configuration.setUseGeneratedKeys(booleanValueOf(props.getProperty("useGeneratedKeys"), false));
    configuration.setDefaultExecutorType(ExecutorType.valueOf(props.getProperty("defaultExecutorType", "SIMPLE")));
    configuration.setDefaultStatementTimeout(integerValueOf(props.getProperty("defaultStatementTimeout"), null));
    configuration.setDefaultFetchSize(integerValueOf(props.getProperty("defaultFetchSize"), null));
    configuration.setMapUnderscoreToCamelCase(booleanValueOf(props.getProperty("mapUnderscoreToCamelCase"), false));
    configuration.setSafeRowBoundsEnabled(booleanValueOf(props.getProperty("safeRowBoundsEnabled"), false));
    configuration.setLocalCacheScope(LocalCacheScope.valueOf(props.getProperty("localCacheScope", "SESSION")));
    configuration.setJdbcTypeForNull(JdbcType.valueOf(props.getProperty("jdbcTypeForNull", "OTHER")));
    configuration.setLazyLoadTriggerMethods(stringSetValueOf(props.getProperty("lazyLoadTriggerMethods"), "equals,clone,hashCode,toString"));
    configuration.setSafeResultHandlerEnabled(booleanValueOf(props.getProperty("safeResultHandlerEnabled"), true));
    configuration.setDefaultScriptingLanguage(resolveClass(props.getProperty("defaultScriptingLanguage")));
    configuration.setCallSettersOnNulls(booleanValueOf(props.getProperty("callSettersOnNulls"), false));
    configuration.setUseActualParamName(booleanValueOf(props.getProperty("useActualParamName"), true));
    configuration.setReturnInstanceForEmptyRow(booleanValueOf(props.getProperty("returnInstanceForEmptyRow"), false));
    configuration.setLogPrefix(props.getProperty("logPrefix"));
    @SuppressWarnings("unchecked")
    Class<? extends Log> logImpl = (Class<? extends Log>) resolveClass(props.getProperty("logImpl"));
    configuration.setLogImpl(logImpl);
    configuration.setConfigurationFactory(resolveClass(props.getProperty("configurationFactory")));
}
项目:mybaties    文件:ForceFlushOnSelectTest.java   
@Test
public void testSelectShouldFlushLocalCacheIfFlushLocalCacheAtferEachStatementIsTrue() throws SQLException {
  sqlSessionFactory.getConfiguration().setLocalCacheScope(LocalCacheScope.STATEMENT);
  SqlSession sqlSession = sqlSessionFactory.openSession(ExecutorType.SIMPLE);
  try {
    PersonMapper personMapper = sqlSession.getMapper(PersonMapper.class);
    List<Person> people = personMapper.selectAllNoFlush();
    updateDatabase(sqlSession.getConnection());
    people = personMapper.selectAllFlush();
    assertEquals("Simone", people.get(0).getFirstName());
    sqlSession.commit();
  } finally {
    sqlSession.close();
  }
}
项目:play    文件:XMLConfigBuilder.java   
private void settingsElement(XNode context) throws Exception {
  if (context != null) {
    Properties props = context.getChildrenAsProperties();
    // Check that all settings are known to the configuration class
    MetaClass metaConfig = MetaClass.forClass(Configuration.class, localReflectorFactory);
    for (Object key : props.keySet()) {
      if (!metaConfig.hasSetter(String.valueOf(key))) {
        throw new BuilderException("The setting " + key + " is not known.  Make sure you spelled it correctly (case sensitive).");
      }
    }
    configuration.setAutoMappingBehavior(AutoMappingBehavior.valueOf(props.getProperty("autoMappingBehavior", "PARTIAL")));
    configuration.setCacheEnabled(booleanValueOf(props.getProperty("cacheEnabled"), true));
    configuration.setProxyFactory((ProxyFactory) createInstance(props.getProperty("proxyFactory")));
    configuration.setLazyLoadingEnabled(booleanValueOf(props.getProperty("lazyLoadingEnabled"), false));
    configuration.setAggressiveLazyLoading(booleanValueOf(props.getProperty("aggressiveLazyLoading"), true));
    configuration.setMultipleResultSetsEnabled(booleanValueOf(props.getProperty("multipleResultSetsEnabled"), true));
    configuration.setUseColumnLabel(booleanValueOf(props.getProperty("useColumnLabel"), true));
    configuration.setUseGeneratedKeys(booleanValueOf(props.getProperty("useGeneratedKeys"), false));
    configuration.setDefaultExecutorType(ExecutorType.valueOf(props.getProperty("defaultExecutorType", "SIMPLE")));
    configuration.setDefaultStatementTimeout(integerValueOf(props.getProperty("defaultStatementTimeout"), null));
    configuration.setDefaultFetchSize(integerValueOf(props.getProperty("defaultFetchSize"), null));
    configuration.setMapUnderscoreToCamelCase(booleanValueOf(props.getProperty("mapUnderscoreToCamelCase"), false));
    configuration.setSafeRowBoundsEnabled(booleanValueOf(props.getProperty("safeRowBoundsEnabled"), false));
    configuration.setLocalCacheScope(LocalCacheScope.valueOf(props.getProperty("localCacheScope", "SESSION")));
    configuration.setJdbcTypeForNull(JdbcType.valueOf(props.getProperty("jdbcTypeForNull", "OTHER")));
    configuration.setLazyLoadTriggerMethods(stringSetValueOf(props.getProperty("lazyLoadTriggerMethods"), "equals,clone,hashCode,toString"));
    configuration.setSafeResultHandlerEnabled(booleanValueOf(props.getProperty("safeResultHandlerEnabled"), true));
    configuration.setDefaultScriptingLanguage(resolveClass(props.getProperty("defaultScriptingLanguage")));
    configuration.setCallSettersOnNulls(booleanValueOf(props.getProperty("callSettersOnNulls"), false));
    configuration.setLogPrefix(props.getProperty("logPrefix"));
    configuration.setLogImpl(resolveClass(props.getProperty("logImpl")));
    configuration.setConfigurationFactory(resolveClass(props.getProperty("configurationFactory")));
  }
}
项目:play    文件:BaseExecutor.java   
@SuppressWarnings("unchecked")
@Override
public <E> List<E> query(MappedStatement ms, Object parameter, RowBounds rowBounds, ResultHandler resultHandler, CacheKey key, BoundSql boundSql) throws SQLException {
  ErrorContext.instance().resource(ms.getResource()).activity("executing a query").object(ms.getId());
  if (closed) {
    throw new ExecutorException("Executor was closed.");
  }
  if (queryStack == 0 && ms.isFlushCacheRequired()) {
    //清除本地缓存数据,回话缓存还可用
    clearLocalCache();
  }
  List<E> list;
  try {
    queryStack++;
    list = resultHandler == null ? (List<E>) localCache.getObject(key) : null;
    if (list != null) {
     //从本地缓存(一级缓存)中读取数据(当服务器宕机后数据消失)
      handleLocallyCachedOutputParameters(ms, key, parameter, boundSql);
    } else {
    //3.缓存中没有值,直接从数据库中读取数据
      list = queryFromDatabase(ms, parameter, rowBounds, resultHandler, key, boundSql);
    }
  } finally {
    queryStack--;
  }
  if (queryStack == 0) {
    for (DeferredLoad deferredLoad : deferredLoads) {
      deferredLoad.load();
    }
    // issue #601
    deferredLoads.clear();
    if (configuration.getLocalCacheScope() == LocalCacheScope.STATEMENT) {
      // issue #482
      clearLocalCache();
    }
  }
  return list;
}
项目:play    文件:ForceFlushOnSelectTest.java   
@Test
public void testSelectShouldFlushLocalCacheIfFlushLocalCacheAtferEachStatementIsTrue() throws SQLException {
  sqlSessionFactory.getConfiguration().setLocalCacheScope(LocalCacheScope.STATEMENT);
  SqlSession sqlSession = sqlSessionFactory.openSession(ExecutorType.SIMPLE);
  try {
    PersonMapper personMapper = sqlSession.getMapper(PersonMapper.class);
    List<Person> people = personMapper.selectAllNoFlush();
    updateDatabase(sqlSession.getConnection());
    people = personMapper.selectAllFlush();
    assertEquals("Simone", people.get(0).getFirstName());
    sqlSession.commit();
  } finally {
    sqlSession.close();
  }
}
项目:play    文件:XmlConfigBuilderTest.java   
@Test
public void shouldSuccessfullyLoadMinimalXMLConfigFile() throws Exception {
  String resource = "org/apache/ibatis/builder/MinimalMapperConfig.xml";
  InputStream inputStream = Resources.getResourceAsStream(resource);
  XMLConfigBuilder builder = new XMLConfigBuilder(inputStream);
  Configuration config = builder.parse();
  assertNotNull(config);
  assertThat(config.getAutoMappingBehavior(), is(AutoMappingBehavior.PARTIAL));
  assertThat(config.isCacheEnabled(), is(true));
  assertThat(config.getProxyFactory(), is(instanceOf(JavassistProxyFactory.class)));
  assertThat(config.isLazyLoadingEnabled(), is(false));
  assertThat(config.isAggressiveLazyLoading(), is(true));
  assertThat(config.isMultipleResultSetsEnabled(), is(true));
  assertThat(config.isUseColumnLabel(), is(true));
  assertThat(config.isUseGeneratedKeys(), is(false));
  assertThat(config.getDefaultExecutorType(), is(ExecutorType.SIMPLE));
  assertNull(config.getDefaultStatementTimeout());
  assertNull(config.getDefaultFetchSize());
  assertThat(config.isMapUnderscoreToCamelCase(), is(false));
  assertThat(config.isSafeRowBoundsEnabled(), is(false));
  assertThat(config.getLocalCacheScope(), is(LocalCacheScope.SESSION));
  assertThat(config.getJdbcTypeForNull(), is(JdbcType.OTHER));
  assertThat(config.getLazyLoadTriggerMethods(), is((Set<String>) new HashSet<String>(Arrays.asList("equals", "clone", "hashCode", "toString"))));
  assertThat(config.isSafeResultHandlerEnabled(), is(true));
    assertThat(config.getDefaultScriptingLanuageInstance(), is(instanceOf(XMLLanguageDriver.class)));
  assertThat(config.isCallSettersOnNulls(), is(false));
  assertNull(config.getLogPrefix());
  assertNull(config.getLogImpl());
  assertNull(config.getConfigurationFactory());
}
项目:play    文件:XmlConfigBuilderTest.java   
@Test
public void shouldSuccessfullyLoadXMLConfigFile() throws Exception {
  String resource = "org/apache/ibatis/builder/CustomizedSettingsMapperConfig.xml";
  InputStream inputStream = Resources.getResourceAsStream(resource);
  XMLConfigBuilder builder = new XMLConfigBuilder(inputStream);
  Configuration config = builder.parse();

  assertThat(config.getAutoMappingBehavior(), is(AutoMappingBehavior.NONE));
  assertThat(config.isCacheEnabled(), is(false));
  assertThat(config.getProxyFactory(), is(instanceOf(CglibProxyFactory.class)));
  assertThat(config.isLazyLoadingEnabled(), is(true));
  assertThat(config.isAggressiveLazyLoading(), is(false));
  assertThat(config.isMultipleResultSetsEnabled(), is(false));
  assertThat(config.isUseColumnLabel(), is(false));
  assertThat(config.isUseGeneratedKeys(), is(true));
  assertThat(config.getDefaultExecutorType(), is(ExecutorType.BATCH));
  assertThat(config.getDefaultStatementTimeout(), is(10));
  assertThat(config.getDefaultFetchSize(), is(100));
  assertThat(config.isMapUnderscoreToCamelCase(), is(true));
  assertThat(config.isSafeRowBoundsEnabled(), is(true));
  assertThat(config.getLocalCacheScope(), is(LocalCacheScope.STATEMENT));
  assertThat(config.getJdbcTypeForNull(), is(JdbcType.NULL));
  assertThat(config.getLazyLoadTriggerMethods(), is((Set<String>) new HashSet<String>(Arrays.asList("equals", "clone", "hashCode", "toString", "xxx"))));
  assertThat(config.isSafeResultHandlerEnabled(), is(false));
  assertThat(config.getDefaultScriptingLanuageInstance(), is(instanceOf(RawLanguageDriver.class)));
  assertThat(config.isCallSettersOnNulls(), is(true));
  assertThat(config.getLogPrefix(), is("mybatis_"));
  assertThat(config.getLogImpl().getName(), is(Slf4jImpl.class.getName()));
  assertThat(config.getConfigurationFactory().getName(), is(String.class.getName()));

}
项目:QuickProject    文件:XMLConfigBuilder.java   
private void settingsElement(XNode context) throws Exception {
  if (context != null) {
    Properties props = context.getChildrenAsProperties();
    // Check that all settings are known to the configuration class
    MetaClass metaConfig = MetaClass.forClass(Configuration.class);
    for (Object key : props.keySet()) {
      if (!metaConfig.hasSetter(String.valueOf(key))) {
        throw new BuilderException("The setting " + key + " is not known.  Make sure you spelled it correctly (case sensitive).");
      }
    }
    configuration.setAutoMappingBehavior(AutoMappingBehavior.valueOf(props.getProperty("autoMappingBehavior", "PARTIAL")));
    configuration.setCacheEnabled(booleanValueOf(props.getProperty("cacheEnabled"), true));
    configuration.setProxyFactory((ProxyFactory) createInstance(props.getProperty("proxyFactory")));
    configuration.setLazyLoadingEnabled(booleanValueOf(props.getProperty("lazyLoadingEnabled"), false));
    configuration.setAggressiveLazyLoading(booleanValueOf(props.getProperty("aggressiveLazyLoading"), true));
    configuration.setMultipleResultSetsEnabled(booleanValueOf(props.getProperty("multipleResultSetsEnabled"), true));
    configuration.setUseColumnLabel(booleanValueOf(props.getProperty("useColumnLabel"), true));
    configuration.setUseGeneratedKeys(booleanValueOf(props.getProperty("useGeneratedKeys"), false));
    configuration.setDefaultExecutorType(ExecutorType.valueOf(props.getProperty("defaultExecutorType", "SIMPLE")));
    configuration.setDefaultStatementTimeout(integerValueOf(props.getProperty("defaultStatementTimeout"), null));
    configuration.setMapUnderscoreToCamelCase(booleanValueOf(props.getProperty("mapUnderscoreToCamelCase"), false));
    configuration.setSafeRowBoundsEnabled(booleanValueOf(props.getProperty("safeRowBoundsEnabled"), false));
    configuration.setLocalCacheScope(LocalCacheScope.valueOf(props.getProperty("localCacheScope", "SESSION")));
    configuration.setJdbcTypeForNull(JdbcType.valueOf(props.getProperty("jdbcTypeForNull", "OTHER")));
    configuration.setLazyLoadTriggerMethods(stringSetValueOf(props.getProperty("lazyLoadTriggerMethods"), "equals,clone,hashCode,toString"));
    configuration.setSafeResultHandlerEnabled(booleanValueOf(props.getProperty("safeResultHandlerEnabled"), true));
    configuration.setDefaultScriptingLanguage(resolveClass(props.getProperty("defaultScriptingLanguage")));
    configuration.setCallSettersOnNulls(booleanValueOf(props.getProperty("callSettersOnNulls"), false));
    configuration.setLogPrefix(props.getProperty("logPrefix"));
    configuration.setLogImpl(resolveClass(props.getProperty("logImpl")));
    configuration.setConfigurationFactory(resolveClass(props.getProperty("configurationFactory")));
  }
}
项目:mybatis-3    文件:XMLConfigBuilder.java   
private void settingsElement(Properties props) throws Exception {
  configuration.setAutoMappingBehavior(AutoMappingBehavior.valueOf(props.getProperty("autoMappingBehavior", "PARTIAL")));
  configuration.setAutoMappingUnknownColumnBehavior(AutoMappingUnknownColumnBehavior.valueOf(props.getProperty("autoMappingUnknownColumnBehavior", "NONE")));
  configuration.setCacheEnabled(booleanValueOf(props.getProperty("cacheEnabled"), true));
  configuration.setProxyFactory((ProxyFactory) createInstance(props.getProperty("proxyFactory")));
  configuration.setLazyLoadingEnabled(booleanValueOf(props.getProperty("lazyLoadingEnabled"), false));
  configuration.setAggressiveLazyLoading(booleanValueOf(props.getProperty("aggressiveLazyLoading"), false));
  configuration.setMultipleResultSetsEnabled(booleanValueOf(props.getProperty("multipleResultSetsEnabled"), true));
  configuration.setUseColumnLabel(booleanValueOf(props.getProperty("useColumnLabel"), true));
  configuration.setUseGeneratedKeys(booleanValueOf(props.getProperty("useGeneratedKeys"), false));
  configuration.setDefaultExecutorType(ExecutorType.valueOf(props.getProperty("defaultExecutorType", "SIMPLE")));
  configuration.setDefaultStatementTimeout(integerValueOf(props.getProperty("defaultStatementTimeout"), null));
  configuration.setDefaultFetchSize(integerValueOf(props.getProperty("defaultFetchSize"), null));
  configuration.setMapUnderscoreToCamelCase(booleanValueOf(props.getProperty("mapUnderscoreToCamelCase"), false));
  configuration.setSafeRowBoundsEnabled(booleanValueOf(props.getProperty("safeRowBoundsEnabled"), false));
  configuration.setLocalCacheScope(LocalCacheScope.valueOf(props.getProperty("localCacheScope", "SESSION")));
  configuration.setJdbcTypeForNull(JdbcType.valueOf(props.getProperty("jdbcTypeForNull", "OTHER")));
  configuration.setLazyLoadTriggerMethods(stringSetValueOf(props.getProperty("lazyLoadTriggerMethods"), "equals,clone,hashCode,toString"));
  configuration.setSafeResultHandlerEnabled(booleanValueOf(props.getProperty("safeResultHandlerEnabled"), true));
  configuration.setDefaultScriptingLanguage(resolveClass(props.getProperty("defaultScriptingLanguage")));
  @SuppressWarnings("unchecked")
  Class<? extends TypeHandler> typeHandler = (Class<? extends TypeHandler>)resolveClass(props.getProperty("defaultEnumTypeHandler"));
  configuration.setDefaultEnumTypeHandler(typeHandler);
  configuration.setCallSettersOnNulls(booleanValueOf(props.getProperty("callSettersOnNulls"), false));
  configuration.setUseActualParamName(booleanValueOf(props.getProperty("useActualParamName"), true));
  configuration.setReturnInstanceForEmptyRow(booleanValueOf(props.getProperty("returnInstanceForEmptyRow"), false));
  configuration.setLogPrefix(props.getProperty("logPrefix"));
  @SuppressWarnings("unchecked")
  Class<? extends Log> logImpl = (Class<? extends Log>)resolveClass(props.getProperty("logImpl"));
  configuration.setLogImpl(logImpl);
  configuration.setConfigurationFactory(resolveClass(props.getProperty("configurationFactory")));
}
项目:mybatis-3    文件:BaseExecutor.java   
@SuppressWarnings("unchecked")
@Override
public <E> List<E> query(MappedStatement ms, Object parameter, RowBounds rowBounds, ResultHandler resultHandler, CacheKey key, BoundSql boundSql) throws SQLException {
  ErrorContext.instance().resource(ms.getResource()).activity("executing a query").object(ms.getId());
  if (closed) {
    throw new ExecutorException("Executor was closed.");
  }
  if (queryStack == 0 && ms.isFlushCacheRequired()) {
    clearLocalCache();
  }
  List<E> list;
  try {
    queryStack++;
    list = resultHandler == null ? (List<E>) localCache.getObject(key) : null;
    if (list != null) {
      handleLocallyCachedOutputParameters(ms, key, parameter, boundSql);
    } else {
      list = queryFromDatabase(ms, parameter, rowBounds, resultHandler, key, boundSql);
    }
  } finally {
    queryStack--;
  }
  if (queryStack == 0) {
    for (DeferredLoad deferredLoad : deferredLoads) {
      deferredLoad.load();
    }
    // issue #601
    deferredLoads.clear();
    if (configuration.getLocalCacheScope() == LocalCacheScope.STATEMENT) {
      // issue #482
      clearLocalCache();
    }
  }
  return list;
}
项目:mybatis-3    文件:ForceFlushOnSelectTest.java   
@Test
public void testSelectShouldFlushLocalCacheIfFlushLocalCacheAtferEachStatementIsTrue() throws SQLException {
  sqlSessionFactory.getConfiguration().setLocalCacheScope(LocalCacheScope.STATEMENT);
  SqlSession sqlSession = sqlSessionFactory.openSession(ExecutorType.SIMPLE);
  try {
    PersonMapper personMapper = sqlSession.getMapper(PersonMapper.class);
    List<Person> people = personMapper.selectAllNoFlush();
    updateDatabase(sqlSession.getConnection());
    people = personMapper.selectAllFlush();
    assertEquals("Simone", people.get(0).getFirstName());
    sqlSession.commit();
  } finally {
    sqlSession.close();
  }
}
项目:mybatis-3    文件:XmlConfigBuilderTest.java   
@Test
public void shouldSuccessfullyLoadMinimalXMLConfigFile() throws Exception {
  String resource = "org/apache/ibatis/builder/MinimalMapperConfig.xml";
  InputStream inputStream = Resources.getResourceAsStream(resource);
  XMLConfigBuilder builder = new XMLConfigBuilder(inputStream);
  Configuration config = builder.parse();
  assertNotNull(config);
  assertThat(config.getAutoMappingBehavior()).isEqualTo(AutoMappingBehavior.PARTIAL);
  assertThat(config.getAutoMappingUnknownColumnBehavior()).isEqualTo(AutoMappingUnknownColumnBehavior.NONE);
  assertThat(config.isCacheEnabled()).isTrue();
  assertThat(config.getProxyFactory()).isInstanceOf(JavassistProxyFactory.class);
  assertThat(config.isLazyLoadingEnabled()).isFalse();
  assertThat(config.isAggressiveLazyLoading()).isFalse();
  assertThat(config.isMultipleResultSetsEnabled()).isTrue();
  assertThat(config.isUseColumnLabel()).isTrue();
  assertThat(config.isUseGeneratedKeys()).isFalse();
  assertThat(config.getDefaultExecutorType()).isEqualTo(ExecutorType.SIMPLE);
  assertNull(config.getDefaultStatementTimeout());
  assertNull(config.getDefaultFetchSize());
  assertThat(config.isMapUnderscoreToCamelCase()).isFalse();
  assertThat(config.isSafeRowBoundsEnabled()).isFalse();
  assertThat(config.getLocalCacheScope()).isEqualTo(LocalCacheScope.SESSION);
  assertThat(config.getJdbcTypeForNull()).isEqualTo(JdbcType.OTHER);
  assertThat(config.getLazyLoadTriggerMethods()).isEqualTo((Set<String>) new HashSet<String>(Arrays.asList("equals", "clone", "hashCode", "toString")));
  assertThat(config.isSafeResultHandlerEnabled()).isTrue();
  assertThat(config.getDefaultScriptingLanuageInstance()).isInstanceOf(XMLLanguageDriver.class);
  assertThat(config.isCallSettersOnNulls()).isFalse();
  assertNull(config.getLogPrefix());
  assertNull(config.getLogImpl());
  assertNull(config.getConfigurationFactory());
  assertThat(config.getTypeHandlerRegistry().getTypeHandler(RoundingMode.class)).isInstanceOf(EnumTypeHandler.class);
  inputStream.close();
}
项目:MybatisCode    文件:XmlConfigBuilderTest.java   
@Test
public void shouldSuccessfullyLoadXMLConfigFile() throws Exception {
  String resource = "org/apache/ibatis/builder/CustomizedSettingsMapperConfig.xml";
  InputStream inputStream = Resources.getResourceAsStream(resource);
  Properties props = new Properties();
  props.put("prop2", "cccc");
  XMLConfigBuilder builder = new XMLConfigBuilder(inputStream, null, props);
  Configuration config = builder.parse();

  assertThat(config.getAutoMappingBehavior(), is(AutoMappingBehavior.NONE));
  assertThat(config.getAutoMappingUnknownColumnBehavior(), is(AutoMappingUnknownColumnBehavior.WARNING));
  assertThat(config.isCacheEnabled(), is(false));
  assertThat(config.getProxyFactory(), is(instanceOf(CglibProxyFactory.class)));
  assertThat(config.isLazyLoadingEnabled(), is(true));
  assertThat(config.isAggressiveLazyLoading(), is(false));
  assertThat(config.isMultipleResultSetsEnabled(), is(false));
  assertThat(config.isUseColumnLabel(), is(false));
  assertThat(config.isUseGeneratedKeys(), is(true));
  assertThat(config.getDefaultExecutorType(), is(ExecutorType.BATCH));
  assertThat(config.getDefaultStatementTimeout(), is(10));
  assertThat(config.getDefaultFetchSize(), is(100));
  assertThat(config.isMapUnderscoreToCamelCase(), is(true));
  assertThat(config.isSafeRowBoundsEnabled(), is(true));
  assertThat(config.getLocalCacheScope(), is(LocalCacheScope.STATEMENT));
  assertThat(config.getJdbcTypeForNull(), is(JdbcType.NULL));
  assertThat(config.getLazyLoadTriggerMethods(), is((Set<String>) new HashSet<String>(Arrays.asList("equals", "clone", "hashCode", "toString", "xxx"))));
  assertThat(config.isSafeResultHandlerEnabled(), is(false));
  assertThat(config.getDefaultScriptingLanuageInstance(), is(instanceOf(RawLanguageDriver.class)));
  assertThat(config.isCallSettersOnNulls(), is(true));
  assertThat(config.getLogPrefix(), is("mybatis_"));
  assertThat(config.getLogImpl().getName(), is(Slf4jImpl.class.getName()));
  assertThat(config.getVfsImpl().getName(), is(JBoss6VFS.class.getName()));
  assertThat(config.getConfigurationFactory().getName(), is(String.class.getName()));

  assertTrue(config.getTypeAliasRegistry().getTypeAliases().get("blogauthor").equals(Author.class));
  assertTrue(config.getTypeAliasRegistry().getTypeAliases().get("blog").equals(Blog.class));
  assertTrue(config.getTypeAliasRegistry().getTypeAliases().get("cart").equals(Cart.class));

  assertThat(config.getTypeHandlerRegistry().getTypeHandler(Integer.class), is(instanceOf(CustomIntegerTypeHandler.class)));
  assertThat(config.getTypeHandlerRegistry().getTypeHandler(Long.class), is(instanceOf(CustomLongTypeHandler.class)));
  assertThat(config.getTypeHandlerRegistry().getTypeHandler(String.class), is(instanceOf(CustomStringTypeHandler.class)));
  assertThat(config.getTypeHandlerRegistry().getTypeHandler(String.class, JdbcType.VARCHAR), is(instanceOf(CustomStringTypeHandler.class)));

  ExampleObjectFactory objectFactory = (ExampleObjectFactory)config.getObjectFactory();
  assertThat(objectFactory.getProperties().size(), is(1));
  assertThat(objectFactory.getProperties().getProperty("objectFactoryProperty"), is("100"));

  assertThat(config.getObjectWrapperFactory(), is(instanceOf(CustomObjectWrapperFactory.class)));

  assertThat(config.getReflectorFactory(), is(instanceOf(CustomReflectorFactory.class)));

  ExamplePlugin plugin = (ExamplePlugin)config.getInterceptors().get(0);
  assertThat(plugin.getProperties().size(), is(1));
  assertThat(plugin.getProperties().getProperty("pluginProperty"), is("100"));

  Environment environment = config.getEnvironment();
  assertThat(environment.getId(), is("development"));
  assertThat(environment.getDataSource(), is(instanceOf(UnpooledDataSource.class)));
  assertThat(environment.getTransactionFactory(), is(instanceOf(JdbcTransactionFactory.class)));

  assertThat(config.getDatabaseId(), is("derby"));

  assertThat(config.getMapperRegistry().getMappers().size(), is(4));
  assertThat(config.getMapperRegistry().hasMapper(CachedAuthorMapper.class), is(true));
  assertThat(config.getMapperRegistry().hasMapper(CustomMapper.class), is(true));
  assertThat(config.getMapperRegistry().hasMapper(BlogMapper.class), is(true));
  assertThat(config.getMapperRegistry().hasMapper(NestedBlogMapper.class), is(true));

}
项目:mybatis    文件:BaseExecutor.java   
/**
 * 源码解析: 查询
 *
 * @param ms Mapper方法声明
 * @param parameter 参数
 * @param rowBounds 分页
 * @param resultHandler 结果处理
 * @param key 缓存key
 * @param boundSql 绑定的sql
 * @return 查询结果集
 */
@SuppressWarnings("unchecked")
@Override
public <E> List<E> query(MappedStatement ms, Object parameter, RowBounds rowBounds, ResultHandler resultHandler, CacheKey key, BoundSql boundSql) throws SQLException {
  ErrorContext.instance().resource(ms.getResource()).activity("executing a query").object(ms.getId());
  if (closed) {
    throw new ExecutorException("Executor was closed.");
  }
  if (queryStack == 0 && ms.isFlushCacheRequired()) {
    // 源码解析: 是查询栈顶并且有声明清空缓存, 则清除本地缓存
    clearLocalCache();
  }
  // 源码解析: 查询结果集
  List<E> list;
  try {
    // 源码解析: 查询栈自加1
    queryStack++;
    // 源码解析: ResultHandler为null, 尝试从缓存查询
    list = resultHandler == null ? (List<E>) localCache.getObject(key) : null;
    if (list != null) {
      handleLocallyCachedOutputParameters(ms, key, parameter, boundSql);
    } else {
      // 源码解析: 从数据库查询结果集
      list = queryFromDatabase(ms, parameter, rowBounds, resultHandler, key, boundSql);
    }
  } finally {
    // 源码解析: 查询栈自减1
    queryStack--;
  }
  if (queryStack == 0) {
    for (DeferredLoad deferredLoad : deferredLoads) {
      deferredLoad.load();
    }
    // issue #601
    deferredLoads.clear();
    if (configuration.getLocalCacheScope() == LocalCacheScope.STATEMENT) {
      // issue #482
      clearLocalCache();
    }
  }
  return list;
}
项目:mybaties    文件:XMLConfigBuilder.java   
private void settingsElement(XNode context) throws Exception {
  if (context != null) {
    Properties props = context.getChildrenAsProperties();
    // Check that all settings are known to the configuration class
    //检查下是否在Configuration类里都有相应的setter方法(没有拼写错误)
    MetaClass metaConfig = MetaClass.forClass(Configuration.class);
    for (Object key : props.keySet()) {
      if (!metaConfig.hasSetter(String.valueOf(key))) {
        throw new BuilderException("The setting " + key + " is not known.  Make sure you spelled it correctly (case sensitive).");
      }
    }

    //下面非常简单,一个个设置属性
    //如何自动映射列到字段/ 属性
    configuration.setAutoMappingBehavior(AutoMappingBehavior.valueOf(props.getProperty("autoMappingBehavior", "PARTIAL")));
    //缓存
    configuration.setCacheEnabled(booleanValueOf(props.getProperty("cacheEnabled"), true));
    //proxyFactory (CGLIB | JAVASSIST)
    //延迟加载的核心技术就是用代理模式,CGLIB/JAVASSIST两者选一
    configuration.setProxyFactory((ProxyFactory) createInstance(props.getProperty("proxyFactory")));
    //延迟加载
    configuration.setLazyLoadingEnabled(booleanValueOf(props.getProperty("lazyLoadingEnabled"), false));
    //延迟加载时,每种属性是否还要按需加载
    configuration.setAggressiveLazyLoading(booleanValueOf(props.getProperty("aggressiveLazyLoading"), true));
    //允不允许多种结果集从一个单独 的语句中返回
    configuration.setMultipleResultSetsEnabled(booleanValueOf(props.getProperty("multipleResultSetsEnabled"), true));
    //使用列标签代替列名
    configuration.setUseColumnLabel(booleanValueOf(props.getProperty("useColumnLabel"), true));
    //允许 JDBC 支持生成的键
    configuration.setUseGeneratedKeys(booleanValueOf(props.getProperty("useGeneratedKeys"), false));
    //配置默认的执行器
    configuration.setDefaultExecutorType(ExecutorType.valueOf(props.getProperty("defaultExecutorType", "SIMPLE")));
    //超时时间
    configuration.setDefaultStatementTimeout(integerValueOf(props.getProperty("defaultStatementTimeout"), null));
    //是否将DB字段自动映射到驼峰式Java属性(A_COLUMN-->aColumn)
    configuration.setMapUnderscoreToCamelCase(booleanValueOf(props.getProperty("mapUnderscoreToCamelCase"), false));
    //嵌套语句上使用RowBounds
    configuration.setSafeRowBoundsEnabled(booleanValueOf(props.getProperty("safeRowBoundsEnabled"), false));
    //默认用session级别的缓存
    configuration.setLocalCacheScope(LocalCacheScope.valueOf(props.getProperty("localCacheScope", "SESSION")));
    //为null值设置jdbctype
    configuration.setJdbcTypeForNull(JdbcType.valueOf(props.getProperty("jdbcTypeForNull", "OTHER")));
    //Object的哪些方法将触发延迟加载
    configuration.setLazyLoadTriggerMethods(stringSetValueOf(props.getProperty("lazyLoadTriggerMethods"), "equals,clone,hashCode,toString"));
    //使用安全的ResultHandler
    configuration.setSafeResultHandlerEnabled(booleanValueOf(props.getProperty("safeResultHandlerEnabled"), true));
    //动态SQL生成语言所使用的脚本语言
    configuration.setDefaultScriptingLanguage(resolveClass(props.getProperty("defaultScriptingLanguage")));
    //当结果集中含有Null值时是否执行映射对象的setter或者Map对象的put方法。此设置对于原始类型如int,boolean等无效。 
    configuration.setCallSettersOnNulls(booleanValueOf(props.getProperty("callSettersOnNulls"), false));
    //logger名字的前缀
    configuration.setLogPrefix(props.getProperty("logPrefix"));
    //显式定义用什么log框架,不定义则用默认的自动发现jar包机制
    configuration.setLogImpl(resolveClass(props.getProperty("logImpl")));
    //配置工厂
    configuration.setConfigurationFactory(resolveClass(props.getProperty("configurationFactory")));
  }
}
项目:mybaties    文件:BaseExecutor.java   
@SuppressWarnings("unchecked")
@Override
public <E> List<E> query(MappedStatement ms, Object parameter, RowBounds rowBounds, ResultHandler resultHandler, CacheKey key, BoundSql boundSql) throws SQLException {
  ErrorContext.instance().resource(ms.getResource()).activity("executing a query").object(ms.getId());
  //如果已经关闭,报错
  if (closed) {
    throw new ExecutorException("Executor was closed.");
  }
  //先清局部缓存,再查询.但仅查询堆栈为0,才清。为了处理递归调用
  if (queryStack == 0 && ms.isFlushCacheRequired()) {
    clearLocalCache();
  }
  List<E> list;
  try {
    //加一,这样递归调用到上面的时候就不会再清局部缓存了
    queryStack++;
    //先根据cachekey从localCache去查
    list = resultHandler == null ? (List<E>) localCache.getObject(key) : null;
    if (list != null) {
      //若查到localCache缓存,处理localOutputParameterCache
      handleLocallyCachedOutputParameters(ms, key, parameter, boundSql);
    } else {
      //从数据库查
      list = queryFromDatabase(ms, parameter, rowBounds, resultHandler, key, boundSql);
    }
  } finally {
    //清空堆栈
    queryStack--;
  }
  if (queryStack == 0) {
    //延迟加载队列中所有元素
    for (DeferredLoad deferredLoad : deferredLoads) {
      deferredLoad.load();
    }
    // issue #601
    //清空延迟加载队列
    deferredLoads.clear();
    if (configuration.getLocalCacheScope() == LocalCacheScope.STATEMENT) {
      // issue #482
    //如果是STATEMENT,清本地缓存
      clearLocalCache();
    }
  }
  return list;
}
项目:brigen-base    文件:InjectorConfig.java   
public LocalCacheScope getLocalCacheScope() {
    return localCacheScope;
}
项目:brigen-base    文件:InjectorConfig.java   
public void setLocalCacheScope(LocalCacheScope localCacheScope) {
    this.localCacheScope = localCacheScope;
}
项目:mybatis-3    文件:XmlConfigBuilderTest.java   
@Test
public void shouldSuccessfullyLoadXMLConfigFile() throws Exception {
  String resource = "org/apache/ibatis/builder/CustomizedSettingsMapperConfig.xml";
  InputStream inputStream = Resources.getResourceAsStream(resource);
  Properties props = new Properties();
  props.put("prop2", "cccc");
  XMLConfigBuilder builder = new XMLConfigBuilder(inputStream, null, props);
  Configuration config = builder.parse();

  assertThat(config.getAutoMappingBehavior()).isEqualTo(AutoMappingBehavior.NONE);
  assertThat(config.getAutoMappingUnknownColumnBehavior()).isEqualTo(AutoMappingUnknownColumnBehavior.WARNING);
  assertThat(config.isCacheEnabled()).isFalse();
  assertThat(config.getProxyFactory()).isInstanceOf(CglibProxyFactory.class);
  assertThat(config.isLazyLoadingEnabled()).isTrue();
  assertThat(config.isAggressiveLazyLoading()).isTrue();
  assertThat(config.isMultipleResultSetsEnabled()).isFalse();
  assertThat(config.isUseColumnLabel()).isFalse();
  assertThat(config.isUseGeneratedKeys()).isTrue();
  assertThat(config.getDefaultExecutorType()).isEqualTo(ExecutorType.BATCH);
  assertThat(config.getDefaultStatementTimeout()).isEqualTo(10);
  assertThat(config.getDefaultFetchSize()).isEqualTo(100);
  assertThat(config.isMapUnderscoreToCamelCase()).isTrue();
  assertThat(config.isSafeRowBoundsEnabled()).isTrue();
  assertThat(config.getLocalCacheScope()).isEqualTo(LocalCacheScope.STATEMENT);
  assertThat(config.getJdbcTypeForNull()).isEqualTo(JdbcType.NULL);
  assertThat(config.getLazyLoadTriggerMethods()).isEqualTo((Set<String>) new HashSet<String>(Arrays.asList("equals", "clone", "hashCode", "toString", "xxx")));
  assertThat(config.isSafeResultHandlerEnabled()).isFalse();
  assertThat(config.getDefaultScriptingLanuageInstance()).isInstanceOf(RawLanguageDriver.class);
  assertThat(config.isCallSettersOnNulls()).isTrue();
  assertThat(config.getLogPrefix()).isEqualTo("mybatis_");
  assertThat(config.getLogImpl().getName()).isEqualTo(Slf4jImpl.class.getName());
  assertThat(config.getVfsImpl().getName()).isEqualTo(JBoss6VFS.class.getName());
  assertThat(config.getConfigurationFactory().getName()).isEqualTo(String.class.getName());

  assertTrue(config.getTypeAliasRegistry().getTypeAliases().get("blogauthor").equals(Author.class));
  assertTrue(config.getTypeAliasRegistry().getTypeAliases().get("blog").equals(Blog.class));
  assertTrue(config.getTypeAliasRegistry().getTypeAliases().get("cart").equals(Cart.class));

  assertThat(config.getTypeHandlerRegistry().getTypeHandler(Integer.class)).isInstanceOf(CustomIntegerTypeHandler.class);
  assertThat(config.getTypeHandlerRegistry().getTypeHandler(Long.class)).isInstanceOf(CustomLongTypeHandler.class);
  assertThat(config.getTypeHandlerRegistry().getTypeHandler(String.class)).isInstanceOf(CustomStringTypeHandler.class);
  assertThat(config.getTypeHandlerRegistry().getTypeHandler(String.class, JdbcType.VARCHAR)).isInstanceOf(CustomStringTypeHandler.class);
  assertThat(config.getTypeHandlerRegistry().getTypeHandler(RoundingMode.class)).isInstanceOf(EnumOrdinalTypeHandler.class);

  ExampleObjectFactory objectFactory = (ExampleObjectFactory)config.getObjectFactory();
  assertThat(objectFactory.getProperties().size()).isEqualTo(1);
  assertThat(objectFactory.getProperties().getProperty("objectFactoryProperty")).isEqualTo("100");

  assertThat(config.getObjectWrapperFactory()).isInstanceOf(CustomObjectWrapperFactory.class);

  assertThat(config.getReflectorFactory()).isInstanceOf(CustomReflectorFactory.class);

  ExamplePlugin plugin = (ExamplePlugin)config.getInterceptors().get(0);
  assertThat(plugin.getProperties().size()).isEqualTo(1);
  assertThat(plugin.getProperties().getProperty("pluginProperty")).isEqualTo("100");

  Environment environment = config.getEnvironment();
  assertThat(environment.getId()).isEqualTo("development");
  assertThat(environment.getDataSource()).isInstanceOf(UnpooledDataSource.class);
  assertThat(environment.getTransactionFactory()).isInstanceOf(JdbcTransactionFactory.class);

  assertThat(config.getDatabaseId()).isEqualTo("derby");

  assertThat(config.getMapperRegistry().getMappers().size()).isEqualTo(4);
  assertThat(config.getMapperRegistry().hasMapper(CachedAuthorMapper.class)).isTrue();
  assertThat(config.getMapperRegistry().hasMapper(CustomMapper.class)).isTrue();
  assertThat(config.getMapperRegistry().hasMapper(BlogMapper.class)).isTrue();
  assertThat(config.getMapperRegistry().hasMapper(NestedBlogMapper.class)).isTrue();
  inputStream.close();
}