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

项目:MybatisCode    文件:AutomappingTest.java   
@Test
public void shouldIgnorePartialAutoMappingBehavior_InlineNestedResultMap() {
  // For nested resultMaps, PARTIAL works the same as NONE
  sqlSessionFactory.getConfiguration().setAutoMappingBehavior(AutoMappingBehavior.PARTIAL);
  SqlSession sqlSession = sqlSessionFactory.openSession();
  try {
    Mapper mapper = sqlSession.getMapper(Mapper.class);
    User user = mapper.getUserWithPets_Inline(2);
    Assert.assertEquals(Integer.valueOf(2), user.getId());
    Assert.assertEquals("User2", user.getName());
    Assert.assertNull("should not inherit auto-mapping", user.getPets().get(0).getPetName());
    Assert.assertEquals("John", user.getPets().get(0).getBreeder().getBreederName());
  } finally {
    sqlSession.close();
  }
}
项目:MybatisCode    文件:AutomappingTest.java   
@Test
public void shouldIgnorePartialAutoMappingBehavior_ExternalNestedResultMap() {
  // For nested resultMaps, PARTIAL works the same as NONE
  sqlSessionFactory.getConfiguration().setAutoMappingBehavior(AutoMappingBehavior.PARTIAL);
  SqlSession sqlSession = sqlSessionFactory.openSession();
  try {
    Mapper mapper = sqlSession.getMapper(Mapper.class);
    User user = mapper.getUserWithPets_External(2);
    Assert.assertEquals(Integer.valueOf(2), user.getId());
    Assert.assertEquals("User2", user.getName());
    Assert.assertNull("should not inherit auto-mapping", user.getPets().get(0).getPetName());
    Assert.assertEquals("John", user.getPets().get(0).getBreeder().getBreederName());
  } finally {
    sqlSession.close();
  }
}
项目:MybatisCode    文件:AutomappingTest.java   
@Test
public void shouldUpdateFinalField() {
  // set automapping to default partial
  sqlSessionFactory.getConfiguration().setAutoMappingBehavior(AutoMappingBehavior.PARTIAL);
  SqlSession sqlSession = sqlSessionFactory.openSession();
  try {
    Mapper mapper = sqlSession.getMapper(Mapper.class);
    Article article = mapper.getArticle();
    // Java Language Specification 17.5.3 Subsequent Modification of Final Fields
    // http://docs.oracle.com/javase/specs/jls/se5.0/html/memory.html#17.5.3
    // The final field should be updated in mapping
    Assert.assertTrue("should update version in mapping", article.version > 0);
  } finally {
    sqlSession.close();
  }
}
项目:MybatisCode    文件:NpeExtendsTest.java   
private SqlSessionFactory getSqlSessionFactoryWithConstructor() {
    UnpooledDataSourceFactory unpooledDataSourceFactory = new UnpooledDataSourceFactory();
    Properties properties = new Properties();
    properties.setProperty("driver", "org.hsqldb.jdbcDriver");
    properties.setProperty("url", "jdbc:hsqldb:mem:extends_with_constructor");
    properties.setProperty("username", "sa");
    unpooledDataSourceFactory.setProperties(properties);
    Environment environment = new Environment("extends_with_constructor", new JdbcTransactionFactory(), unpooledDataSourceFactory.getDataSource());

    Configuration configuration = new Configuration();
    configuration.setEnvironment(environment);
    configuration.addMapper(StudentConstructorMapper.class);
    configuration.addMapper(TeacherMapper.class);
    configuration.getMappedStatementNames();
    configuration.setAutoMappingBehavior(AutoMappingBehavior.NONE);

    return new DefaultSqlSessionFactory(configuration);
}
项目: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")));
}
项目:mybatis    文件:AutomappingTest.java   
@Test
public void shouldIgnorePartialAutoMappingBehavior_InlineNestedResultMap() {
  // For nested resultMaps, PARTIAL works the same as NONE
  sqlSessionFactory.getConfiguration().setAutoMappingBehavior(AutoMappingBehavior.PARTIAL);
  SqlSession sqlSession = sqlSessionFactory.openSession();
  try {
    Mapper mapper = sqlSession.getMapper(Mapper.class);
    User user = mapper.getUserWithPets_Inline(2);
    Assert.assertEquals(Integer.valueOf(2), user.getId());
    Assert.assertEquals("User2", user.getName());
    Assert.assertNull("should not inherit auto-mapping", user.getPets().get(0).getPetName());
    Assert.assertEquals("John", user.getPets().get(0).getBreeder().getBreederName());
  } finally {
    sqlSession.close();
  }
}
项目:mybatis    文件:AutomappingTest.java   
@Test
public void shouldIgnorePartialAutoMappingBehavior_ExternalNestedResultMap() {
  // For nested resultMaps, PARTIAL works the same as NONE
  sqlSessionFactory.getConfiguration().setAutoMappingBehavior(AutoMappingBehavior.PARTIAL);
  SqlSession sqlSession = sqlSessionFactory.openSession();
  try {
    Mapper mapper = sqlSession.getMapper(Mapper.class);
    User user = mapper.getUserWithPets_External(2);
    Assert.assertEquals(Integer.valueOf(2), user.getId());
    Assert.assertEquals("User2", user.getName());
    Assert.assertNull("should not inherit auto-mapping", user.getPets().get(0).getPetName());
    Assert.assertEquals("John", user.getPets().get(0).getBreeder().getBreederName());
  } finally {
    sqlSession.close();
  }
}
项目:mybatis    文件:AutomappingTest.java   
@Test
public void shouldUpdateFinalField() {
  // set automapping to default partial
  sqlSessionFactory.getConfiguration().setAutoMappingBehavior(AutoMappingBehavior.PARTIAL);
  SqlSession sqlSession = sqlSessionFactory.openSession();
  try {
    Mapper mapper = sqlSession.getMapper(Mapper.class);
    Article article = mapper.getArticle();
    // Java Language Specification 17.5.3 Subsequent Modification of Final Fields
    // http://docs.oracle.com/javase/specs/jls/se5.0/html/memory.html#17.5.3
    // The final field should be updated in mapping
    Assert.assertTrue("should update version in mapping", article.version > 0);
  } finally {
    sqlSession.close();
  }
}
项目:mybatis    文件:NpeExtendsTest.java   
private SqlSessionFactory getSqlSessionFactoryWithConstructor() {
    UnpooledDataSourceFactory unpooledDataSourceFactory = new UnpooledDataSourceFactory();
    Properties properties = new Properties();
    properties.setProperty("driver", "org.hsqldb.jdbcDriver");
    properties.setProperty("url", "jdbc:hsqldb:mem:extends_with_constructor");
    properties.setProperty("username", "sa");
    unpooledDataSourceFactory.setProperties(properties);
    Environment environment = new Environment("extends_with_constructor", new JdbcTransactionFactory(), unpooledDataSourceFactory.getDataSource());

    Configuration configuration = new Configuration();
    configuration.setEnvironment(environment);
    configuration.addMapper(StudentConstructorMapper.class);
    configuration.addMapper(TeacherMapper.class);
    configuration.getMappedStatementNames();
    configuration.setAutoMappingBehavior(AutoMappingBehavior.NONE);

    return new DefaultSqlSessionFactory(configuration);
}
项目: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")));
}
项目:mybaties    文件:AutomappingTest.java   
@Test
public void shouldIgnorePartialAutoMappingBehavior_InlineNestedResultMap() {
  // For nested resultMaps, PARTIAL works the same as NONE
  sqlSessionFactory.getConfiguration().setAutoMappingBehavior(AutoMappingBehavior.PARTIAL);
  SqlSession sqlSession = sqlSessionFactory.openSession();
  try {
    Mapper mapper = sqlSession.getMapper(Mapper.class);
    User user = mapper.getUserWithPets_Inline(2);
    Assert.assertEquals(Integer.valueOf(2), user.getId());
    Assert.assertEquals("User2", user.getName());
    Assert.assertNull("should not inherit auto-mapping", user.getPets().get(0).getPetName());
    Assert.assertEquals("John", user.getPets().get(0).getBreeder().getBreederName());
  } finally {
    sqlSession.close();
  }
}
项目:mybaties    文件:AutomappingTest.java   
@Test
public void shouldIgnorePartialAutoMappingBehavior_ExternalNestedResultMap() {
  // For nested resultMaps, PARTIAL works the same as NONE
  sqlSessionFactory.getConfiguration().setAutoMappingBehavior(AutoMappingBehavior.PARTIAL);
  SqlSession sqlSession = sqlSessionFactory.openSession();
  try {
    Mapper mapper = sqlSession.getMapper(Mapper.class);
    User user = mapper.getUserWithPets_External(2);
    Assert.assertEquals(Integer.valueOf(2), user.getId());
    Assert.assertEquals("User2", user.getName());
    Assert.assertNull("should not inherit auto-mapping", user.getPets().get(0).getPetName());
    Assert.assertEquals("John", user.getPets().get(0).getBreeder().getBreederName());
  } finally {
    sqlSession.close();
  }
}
项目:mybaties    文件:AutomappingTest.java   
@Test
public void shouldUpdateFinalField() {
  // set automapping to default partial
  sqlSessionFactory.getConfiguration().setAutoMappingBehavior(AutoMappingBehavior.PARTIAL);
  SqlSession sqlSession = sqlSessionFactory.openSession();
  try {
    Mapper mapper = sqlSession.getMapper(Mapper.class);
    Article article = mapper.getArticle();
    // Java Language Specification 17.5.3 Subsequent Modification of Final Fields
    // http://docs.oracle.com/javase/specs/jls/se5.0/html/memory.html#17.5.3
    // The final field should be updated in mapping
    Assert.assertTrue("should update version in mapping", article.version > 0);
  } finally {
    sqlSession.close();
  }
}
项目:mybaties    文件:NpeExtendsTest.java   
private SqlSessionFactory getSqlSessionFactoryWithConstructor() {
    UnpooledDataSourceFactory unpooledDataSourceFactory = new UnpooledDataSourceFactory();
    Properties properties = new Properties();
    properties.setProperty("driver", "org.hsqldb.jdbcDriver");
    properties.setProperty("url", "jdbc:hsqldb:mem:extends_with_constructor");
    properties.setProperty("username", "sa");
    unpooledDataSourceFactory.setProperties(properties);
    Environment environment = new Environment("extends_with_constructor", new JdbcTransactionFactory(), unpooledDataSourceFactory.getDataSource());

    Configuration configuration = new Configuration();
    configuration.setEnvironment(environment);
    configuration.addMapper(StudentConstructorMapper.class);
    configuration.addMapper(TeacherMapper.class);
    configuration.getMappedStatementNames();
    configuration.setAutoMappingBehavior(AutoMappingBehavior.NONE);

    return new DefaultSqlSessionFactory(configuration);
}
项目:play    文件:AutomappingTest.java   
@Test
public void shouldIgnorePartialAutoMappingBehavior_InlineNestedResultMap() {
  // For nested resultMaps, PARTIAL works the same as NONE
  sqlSessionFactory.getConfiguration().setAutoMappingBehavior(AutoMappingBehavior.PARTIAL);
  SqlSession sqlSession = sqlSessionFactory.openSession();
  try {
    Mapper mapper = sqlSession.getMapper(Mapper.class);
    User user = mapper.getUserWithPets_Inline(2);
    Assert.assertEquals(Integer.valueOf(2), user.getId());
    Assert.assertEquals("User2", user.getName());
    Assert.assertNull("should not inherit auto-mapping", user.getPets().get(0).getPetName());
    Assert.assertEquals("John", user.getPets().get(0).getBreeder().getBreederName());
  } finally {
    sqlSession.close();
  }
}
项目:play    文件:AutomappingTest.java   
@Test
public void shouldIgnorePartialAutoMappingBehavior_ExternalNestedResultMap() {
  // For nested resultMaps, PARTIAL works the same as NONE
  sqlSessionFactory.getConfiguration().setAutoMappingBehavior(AutoMappingBehavior.PARTIAL);
  SqlSession sqlSession = sqlSessionFactory.openSession();
  try {
    Mapper mapper = sqlSession.getMapper(Mapper.class);
    User user = mapper.getUserWithPets_External(2);
    Assert.assertEquals(Integer.valueOf(2), user.getId());
    Assert.assertEquals("User2", user.getName());
    Assert.assertNull("should not inherit auto-mapping", user.getPets().get(0).getPetName());
    Assert.assertEquals("John", user.getPets().get(0).getBreeder().getBreederName());
  } finally {
    sqlSession.close();
  }
}
项目:play    文件:AutomappingTest.java   
@Test
public void shouldUpdateFinalField() {
  // set automapping to default partial
  sqlSessionFactory.getConfiguration().setAutoMappingBehavior(AutoMappingBehavior.PARTIAL);
  SqlSession sqlSession = sqlSessionFactory.openSession();
  try {
    Mapper mapper = sqlSession.getMapper(Mapper.class);
    Article article = mapper.getArticle();
    // Java Language Specification 17.5.3 Subsequent Modification of Final Fields
    // http://docs.oracle.com/javase/specs/jls/se5.0/html/memory.html#17.5.3
    // The final field should be updated in mapping
    Assert.assertTrue("should update version in mapping", article.version > 0);
  } finally {
    sqlSession.close();
  }
}
项目:play    文件:NpeExtendsTest.java   
private SqlSessionFactory getSqlSessionFactoryWithConstructor() {
    UnpooledDataSourceFactory unpooledDataSourceFactory = new UnpooledDataSourceFactory();
    Properties properties = new Properties();
    properties.setProperty("driver", "org.hsqldb.jdbcDriver");
    properties.setProperty("url", "jdbc:hsqldb:mem:extends_with_constructor");
    properties.setProperty("username", "sa");
    unpooledDataSourceFactory.setProperties(properties);
    Environment environment = new Environment("extends_with_constructor", new JdbcTransactionFactory(), unpooledDataSourceFactory.getDataSource());

    Configuration configuration = new Configuration();
    configuration.setEnvironment(environment);
    configuration.addMapper(StudentConstructorMapper.class);
    configuration.addMapper(TeacherMapper.class);
    configuration.getMappedStatementNames();
    configuration.setAutoMappingBehavior(AutoMappingBehavior.NONE);

    return new DefaultSqlSessionFactory(configuration);
}
项目:openclouddb    文件:FastResultSetHandler.java   
protected Object getRowValue(ResultSet rs, ResultMap resultMap, CacheKey rowKey, ResultColumnCache resultColumnCache) throws SQLException {
  final ResultLoaderMap lazyLoader = instantiateResultLoaderMap();
  Object resultObject = createResultObject(rs, resultMap, lazyLoader, null, resultColumnCache);
  if (resultObject != null && !typeHandlerRegistry.hasTypeHandler(resultMap.getType())) {
    final MetaObject metaObject = configuration.newMetaObject(resultObject);
    boolean foundValues = resultMap.getConstructorResultMappings().size() > 0;
    if (shouldApplyAutomaticMappings(resultMap, !AutoMappingBehavior.NONE.equals(configuration.getAutoMappingBehavior()))) {
      final List<String> unmappedColumnNames = resultColumnCache.getUnmappedColumnNames(resultMap, null);
      foundValues = applyAutomaticMappings(rs, unmappedColumnNames, metaObject, null, resultColumnCache) || foundValues;
    }
    final List<String> mappedColumnNames = resultColumnCache.getMappedColumnNames(resultMap, null);
    foundValues = applyPropertyMappings(rs, resultMap, mappedColumnNames, metaObject, lazyLoader, null) || foundValues;
    foundValues = (lazyLoader != null && lazyLoader.size() > 0) || foundValues;
    resultObject = foundValues ? resultObject : null;
    return resultObject;
  }
  return resultObject;
}
项目:openclouddb    文件:FastResultSetHandler.java   
protected Object getRowValue(ResultSet rs, ResultMap resultMap, CacheKey rowKey, ResultColumnCache resultColumnCache) throws SQLException {
  final ResultLoaderMap lazyLoader = instantiateResultLoaderMap();
  Object resultObject = createResultObject(rs, resultMap, lazyLoader, null, resultColumnCache);
  if (resultObject != null && !typeHandlerRegistry.hasTypeHandler(resultMap.getType())) {
    final MetaObject metaObject = configuration.newMetaObject(resultObject);
    boolean foundValues = resultMap.getConstructorResultMappings().size() > 0;
    if (shouldApplyAutomaticMappings(resultMap, !AutoMappingBehavior.NONE.equals(configuration.getAutoMappingBehavior()))) {
      final List<String> unmappedColumnNames = resultColumnCache.getUnmappedColumnNames(resultMap, null);
      foundValues = applyAutomaticMappings(rs, unmappedColumnNames, metaObject, null, resultColumnCache) || foundValues;
    }
    final List<String> mappedColumnNames = resultColumnCache.getMappedColumnNames(resultMap, null);
    foundValues = applyPropertyMappings(rs, resultMap, mappedColumnNames, metaObject, lazyLoader, null) || foundValues;
    foundValues = (lazyLoader != null && lazyLoader.size() > 0) || foundValues;
    resultObject = foundValues ? resultObject : null;
    return resultObject;
  }
  return resultObject;
}
项目:mybatis-3    文件:AutomappingTest.java   
@Test
public void shouldIgnorePartialAutoMappingBehavior_InlineNestedResultMap() {
  // For nested resultMaps, PARTIAL works the same as NONE
  sqlSessionFactory.getConfiguration().setAutoMappingBehavior(AutoMappingBehavior.PARTIAL);
  SqlSession sqlSession = sqlSessionFactory.openSession();
  try {
    Mapper mapper = sqlSession.getMapper(Mapper.class);
    User user = mapper.getUserWithPets_Inline(2);
    Assert.assertEquals(Integer.valueOf(2), user.getId());
    Assert.assertEquals("User2", user.getName());
    Assert.assertNull("should not inherit auto-mapping", user.getPets().get(0).getPetName());
    Assert.assertEquals("John", user.getPets().get(0).getBreeder().getBreederName());
  } finally {
    sqlSession.close();
  }
}
项目:mybatis-3    文件:AutomappingTest.java   
@Test
public void shouldIgnorePartialAutoMappingBehavior_ExternalNestedResultMap() {
  // For nested resultMaps, PARTIAL works the same as NONE
  sqlSessionFactory.getConfiguration().setAutoMappingBehavior(AutoMappingBehavior.PARTIAL);
  SqlSession sqlSession = sqlSessionFactory.openSession();
  try {
    Mapper mapper = sqlSession.getMapper(Mapper.class);
    User user = mapper.getUserWithPets_External(2);
    Assert.assertEquals(Integer.valueOf(2), user.getId());
    Assert.assertEquals("User2", user.getName());
    Assert.assertNull("should not inherit auto-mapping", user.getPets().get(0).getPetName());
    Assert.assertEquals("John", user.getPets().get(0).getBreeder().getBreederName());
  } finally {
    sqlSession.close();
  }
}
项目:mybatis-3    文件:AutomappingTest.java   
@Test
public void shouldUpdateFinalField() {
  // set automapping to default partial
  sqlSessionFactory.getConfiguration().setAutoMappingBehavior(AutoMappingBehavior.PARTIAL);
  SqlSession sqlSession = sqlSessionFactory.openSession();
  try {
    Mapper mapper = sqlSession.getMapper(Mapper.class);
    Article article = mapper.getArticle();
    // Java Language Specification 17.5.3 Subsequent Modification of Final Fields
    // http://docs.oracle.com/javase/specs/jls/se5.0/html/memory.html#17.5.3
    // The final field should be updated in mapping
    Assert.assertTrue("should update version in mapping", article.version > 0);
  } finally {
    sqlSession.close();
  }
}
项目:mybatis-3    文件:NpeExtendsTest.java   
private SqlSessionFactory getSqlSessionFactoryWithConstructor() {
    UnpooledDataSourceFactory unpooledDataSourceFactory = new UnpooledDataSourceFactory();
    Properties properties = new Properties();
    properties.setProperty("driver", "org.hsqldb.jdbcDriver");
    properties.setProperty("url", "jdbc:hsqldb:mem:extends_with_constructor");
    properties.setProperty("username", "sa");
    unpooledDataSourceFactory.setProperties(properties);
    Environment environment = new Environment("extends_with_constructor", new JdbcTransactionFactory(), unpooledDataSourceFactory.getDataSource());

    Configuration configuration = new Configuration();
    configuration.setEnvironment(environment);
    configuration.addMapper(StudentConstructorMapper.class);
    configuration.addMapper(TeacherMapper.class);
    configuration.getMappedStatementNames();
    configuration.setAutoMappingBehavior(AutoMappingBehavior.NONE);

    return new DefaultSqlSessionFactory(configuration);
}
项目: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    文件:DefaultResultSetHandler.java   
private boolean shouldApplyAutomaticMappings(ResultMap resultMap, boolean isNested) {
  if (resultMap.getAutoMapping() != null) {
    return resultMap.getAutoMapping();
  } else {
    if (isNested) {
      return AutoMappingBehavior.FULL == configuration.getAutoMappingBehavior();
    } else {
      return AutoMappingBehavior.NONE != configuration.getAutoMappingBehavior();
    }
  }
}
项目:MybatisCode    文件:AutomappingTest.java   
@Test
public void shouldGetAUser() {
  sqlSessionFactory.getConfiguration().setAutoMappingBehavior(AutoMappingBehavior.NONE);
  SqlSession sqlSession = sqlSessionFactory.openSession();
  try {
    Mapper mapper = sqlSession.getMapper(Mapper.class);
    User user = mapper.getUser(1);
    Assert.assertEquals("User1", user.getName());
  } finally {
    sqlSession.close();
  }
}
项目:MybatisCode    文件:AutomappingTest.java   
@Test
public void shouldNotInheritAutoMappingInherited_InlineNestedResultMap() {
  sqlSessionFactory.getConfiguration().setAutoMappingBehavior(AutoMappingBehavior.NONE);
  SqlSession sqlSession = sqlSessionFactory.openSession();
  try {
    Mapper mapper = sqlSession.getMapper(Mapper.class);
    User user = mapper.getUserWithPets_Inline(2);
    Assert.assertEquals(Integer.valueOf(2), user.getId());
    Assert.assertEquals("User2", user.getName());
    Assert.assertNull("should not inherit auto-mapping", user.getPets().get(0).getPetName());
    Assert.assertEquals("John", user.getPets().get(0).getBreeder().getBreederName());
  } finally {
    sqlSession.close();
  }
}
项目:MybatisCode    文件:AutomappingTest.java   
@Test
public void shouldNotInheritAutoMappingInherited_ExternalNestedResultMap() {
  sqlSessionFactory.getConfiguration().setAutoMappingBehavior(AutoMappingBehavior.NONE);
  SqlSession sqlSession = sqlSessionFactory.openSession();
  try {
    Mapper mapper = sqlSession.getMapper(Mapper.class);
    User user = mapper.getUserWithPets_External(2);
    Assert.assertEquals(Integer.valueOf(2), user.getId());
    Assert.assertEquals("User2", user.getName());
    Assert.assertNull("should not inherit auto-mapping", user.getPets().get(0).getPetName());
    Assert.assertEquals("John", user.getPets().get(0).getBreeder().getBreederName());
  } finally {
    sqlSession.close();
  }
}
项目:MybatisCode    文件:AutomappingTest.java   
@Test
public void shouldRespectFullAutoMappingBehavior_InlineNestedResultMap() {
  sqlSessionFactory.getConfiguration().setAutoMappingBehavior(AutoMappingBehavior.FULL);
  SqlSession sqlSession = sqlSessionFactory.openSession();
  try {
    Mapper mapper = sqlSession.getMapper(Mapper.class);
    User user = mapper.getUserWithPets_Inline(2);
    Assert.assertEquals(Integer.valueOf(2), user.getId());
    Assert.assertEquals("User2", user.getName());
    Assert.assertEquals("Chien", user.getPets().get(0).getPetName());
    Assert.assertEquals("John", user.getPets().get(0).getBreeder().getBreederName());
  } finally {
    sqlSession.close();
  }
}
项目:MybatisCode    文件:AutomappingTest.java   
@Test
public void shouldRespectFullAutoMappingBehavior_ExternalNestedResultMap() {
  sqlSessionFactory.getConfiguration().setAutoMappingBehavior(AutoMappingBehavior.FULL);
  SqlSession sqlSession = sqlSessionFactory.openSession();
  try {
    Mapper mapper = sqlSession.getMapper(Mapper.class);
    User user = mapper.getUserWithPets_External(2);
    Assert.assertEquals(Integer.valueOf(2), user.getId());
    Assert.assertEquals("User2", user.getName());
    Assert.assertEquals("Chien", user.getPets().get(0).getPetName());
    Assert.assertEquals("John", user.getPets().get(0).getBreeder().getBreederName());
  } finally {
    sqlSession.close();
  }
}
项目:MybatisCode    文件:AutomappingTest.java   
@Test
public void shouldGetBooks() {
  // set automapping to default partial
  sqlSessionFactory.getConfiguration().setAutoMappingBehavior(AutoMappingBehavior.PARTIAL);
  SqlSession sqlSession = sqlSessionFactory.openSession();
  try {
    Mapper mapper = sqlSession.getMapper(Mapper.class);
    // no errors throw
    List<Book> books = mapper.getBooks();
    Assert.assertTrue("should return results,no errors throw", !books.isEmpty());
  } 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    文件:DefaultResultSetHandler.java   
private boolean shouldApplyAutomaticMappings(ResultMap resultMap, boolean isNested) {
  if (resultMap.getAutoMapping() != null) {
    return resultMap.getAutoMapping();
  } else {
    if (isNested) {
      return AutoMappingBehavior.FULL == configuration.getAutoMappingBehavior();
    } else {
      return AutoMappingBehavior.NONE != configuration.getAutoMappingBehavior();
    }
  }
}
项目:mybatis    文件:AutomappingTest.java   
@Test
public void shouldGetAUser() {
  sqlSessionFactory.getConfiguration().setAutoMappingBehavior(AutoMappingBehavior.NONE);
  SqlSession sqlSession = sqlSessionFactory.openSession();
  try {
    Mapper mapper = sqlSession.getMapper(Mapper.class);
    User user = mapper.getUser(1);
    Assert.assertEquals("User1", user.getName());
  } finally {
    sqlSession.close();
  }
}
项目:mybatis    文件:AutomappingTest.java   
@Test
public void shouldNotInheritAutoMappingInherited_InlineNestedResultMap() {
  sqlSessionFactory.getConfiguration().setAutoMappingBehavior(AutoMappingBehavior.NONE);
  SqlSession sqlSession = sqlSessionFactory.openSession();
  try {
    Mapper mapper = sqlSession.getMapper(Mapper.class);
    User user = mapper.getUserWithPets_Inline(2);
    Assert.assertEquals(Integer.valueOf(2), user.getId());
    Assert.assertEquals("User2", user.getName());
    Assert.assertNull("should not inherit auto-mapping", user.getPets().get(0).getPetName());
    Assert.assertEquals("John", user.getPets().get(0).getBreeder().getBreederName());
  } finally {
    sqlSession.close();
  }
}
项目:mybatis    文件:AutomappingTest.java   
@Test
public void shouldNotInheritAutoMappingInherited_ExternalNestedResultMap() {
  sqlSessionFactory.getConfiguration().setAutoMappingBehavior(AutoMappingBehavior.NONE);
  SqlSession sqlSession = sqlSessionFactory.openSession();
  try {
    Mapper mapper = sqlSession.getMapper(Mapper.class);
    User user = mapper.getUserWithPets_External(2);
    Assert.assertEquals(Integer.valueOf(2), user.getId());
    Assert.assertEquals("User2", user.getName());
    Assert.assertNull("should not inherit auto-mapping", user.getPets().get(0).getPetName());
    Assert.assertEquals("John", user.getPets().get(0).getBreeder().getBreederName());
  } finally {
    sqlSession.close();
  }
}
项目:mybatis    文件:AutomappingTest.java   
@Test
public void shouldRespectFullAutoMappingBehavior_InlineNestedResultMap() {
  sqlSessionFactory.getConfiguration().setAutoMappingBehavior(AutoMappingBehavior.FULL);
  SqlSession sqlSession = sqlSessionFactory.openSession();
  try {
    Mapper mapper = sqlSession.getMapper(Mapper.class);
    User user = mapper.getUserWithPets_Inline(2);
    Assert.assertEquals(Integer.valueOf(2), user.getId());
    Assert.assertEquals("User2", user.getName());
    Assert.assertEquals("Chien", user.getPets().get(0).getPetName());
    Assert.assertEquals("John", user.getPets().get(0).getBreeder().getBreederName());
  } finally {
    sqlSession.close();
  }
}