org.apache.ibatis.type.StringTypeHandler Java Examples

The following examples show how to use org.apache.ibatis.type.StringTypeHandler. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: TestSelectByExample.java    From tk-mybatis with MIT License 6 votes vote down vote up
@Test
public void testAndExample() {
    SqlSession sqlSession = MybatisHelper.getSqlSession();
    try {
        CountryMapper mapper = sqlSession.getMapper(CountryMapper.class);
        Example example = new Example(Country.class);
        example.createCriteria()
                .andCondition("countryname like 'C%' and id < 100")
                .andCondition("length(countryname) = ", 5)
                .andCondition("countrycode =", "CN", StringTypeHandler.class);
        List<Country> countries = mapper.selectByExample(example);
        //查询总数
        Assert.assertEquals(1, countries.size());
    } finally {
        sqlSession.close();
    }
}
 
Example #2
Source File: MybatisConfig.java    From BlogManagePlatform with Apache License 2.0 5 votes vote down vote up
@Bean
public ConfigurationCustomizer configurationCustomizer() {
	return new ConfigurationCustomizer() {

		@SuppressWarnings("unused")
		private int a = 1;

		@Override
		public void customize(org.apache.ibatis.session.Configuration configuration) {
			TypeHandlerRegistry registry = configuration.getTypeHandlerRegistry();
			registry.register(Object.class, JdbcType.BIT, new BooleanTypeHandler());
			registry.register(Object.class, JdbcType.BOOLEAN, new BooleanTypeHandler());
			registry.register(Object.class, JdbcType.TINYINT, new ByteTypeHandler());
			registry.register(Object.class, JdbcType.SMALLINT, new ShortTypeHandler());
			registry.register(Object.class, JdbcType.INTEGER, new IntegerTypeHandler());
			registry.register(Object.class, JdbcType.BIGINT, new LongTypeHandler());
			registry.register(Object.class, JdbcType.FLOAT, new FloatTypeHandler());
			registry.register(Object.class, JdbcType.DOUBLE, new DoubleTypeHandler());
			registry.register(Object.class, JdbcType.VARCHAR, new StringTypeHandler());
			registry.register(Object.class, JdbcType.LONGVARCHAR, new StringTypeHandler());
			registry.register(Object.class, JdbcType.CHAR, new StringTypeHandler());
			registry.register(Object.class, JdbcType.REAL, new BigDecimalTypeHandler());
			registry.register(Object.class, JdbcType.DECIMAL, new BigDecimalTypeHandler());
			registry.register(Object.class, JdbcType.NUMERIC, new BigDecimalTypeHandler());
		}
	};
}
 
Example #3
Source File: NameStyleTest.java    From Mapper with MIT License 5 votes vote down vote up
@Test
public void testCamelhump(){
    EntityHelper.initEntityNameMap(UserCamelhump.class, config);
    EntityTable entityTable = EntityHelper.getEntityTable(UserCamelhump.class);
    Assert.assertNotNull(entityTable);
    Assert.assertEquals("user_camelhump", entityTable.getName());

    Set<EntityColumn> columns = entityTable.getEntityClassColumns();
    Assert.assertEquals(1, columns.size());

    for (EntityColumn column : columns) {
        Assert.assertEquals("user_name", column.getColumn());
        Assert.assertEquals("userName", column.getProperty());

        Assert.assertEquals("user_name = #{userName}", column.getColumnEqualsHolder());
        Assert.assertEquals("user_name = #{record.userName}", column.getColumnEqualsHolder("record"));
        Assert.assertEquals("#{userName}", column.getColumnHolder());
        Assert.assertEquals("#{record.userName}", column.getColumnHolder("record"));
        Assert.assertEquals("#{record.userName}", column.getColumnHolder("record", "suffix"));
        Assert.assertEquals("#{record.userNamesuffix},", column.getColumnHolder("record", "suffix", ","));
        Assert.assertNull(column.getTypeHandler());
    }

    ResultMap resultMap = entityTable.getResultMap(configuration);
    Assert.assertEquals("[USER_NAME]", resultMap.getMappedColumns().toString());

    Assert.assertEquals(1, resultMap.getResultMappings().size());

    ResultMapping resultMapping = resultMap.getResultMappings().get(0);
    Assert.assertEquals("user_name", resultMapping.getColumn());
    Assert.assertEquals("userName", resultMapping.getProperty());
    Assert.assertNull(resultMapping.getJdbcType());
    Assert.assertEquals(StringTypeHandler.class, resultMapping.getTypeHandler().getClass());
}
 
Example #4
Source File: NameStyleTest.java    From Mapper with MIT License 5 votes vote down vote up
@Test
public void testCamelhumpAndUppercase(){
    EntityHelper.initEntityNameMap(UserCamelhumpAndUppercase.class, config);
    EntityTable entityTable = EntityHelper.getEntityTable(UserCamelhumpAndUppercase.class);
    Assert.assertNotNull(entityTable);
    Assert.assertEquals("USER_CAMELHUMP_AND_UPPERCASE", entityTable.getName());

    Set<EntityColumn> columns = entityTable.getEntityClassColumns();
    Assert.assertEquals(1, columns.size());

    for (EntityColumn column : columns) {
        Assert.assertEquals("USER_NAME", column.getColumn());
        Assert.assertEquals("userName", column.getProperty());

        Assert.assertEquals("USER_NAME = #{userName}", column.getColumnEqualsHolder());
        Assert.assertEquals("USER_NAME = #{record.userName}", column.getColumnEqualsHolder("record"));
        Assert.assertEquals("#{userName}", column.getColumnHolder());
        Assert.assertEquals("#{record.userName}", column.getColumnHolder("record"));
        Assert.assertEquals("#{record.userName}", column.getColumnHolder("record", "suffix"));
        Assert.assertEquals("#{record.userNamesuffix},", column.getColumnHolder("record", "suffix", ","));
        Assert.assertNull(column.getTypeHandler());
    }

    ResultMap resultMap = entityTable.getResultMap(configuration);
    Assert.assertEquals("[USER_NAME]", resultMap.getMappedColumns().toString());

    Assert.assertEquals(1, resultMap.getResultMappings().size());

    ResultMapping resultMapping = resultMap.getResultMappings().get(0);
    Assert.assertEquals("USER_NAME", resultMapping.getColumn());
    Assert.assertEquals("userName", resultMapping.getProperty());
    Assert.assertNull(resultMapping.getJdbcType());
    Assert.assertEquals(StringTypeHandler.class, resultMapping.getTypeHandler().getClass());
}
 
Example #5
Source File: NameStyleTest.java    From Mapper with MIT License 5 votes vote down vote up
@Test
public void testCamelhumpAndLowercase(){
    EntityHelper.initEntityNameMap(UserCamelhumpAndLowercase.class, config);
    EntityTable entityTable = EntityHelper.getEntityTable(UserCamelhumpAndLowercase.class);
    Assert.assertNotNull(entityTable);
    Assert.assertEquals("user_camelhump_and_lowercase", entityTable.getName());

    Set<EntityColumn> columns = entityTable.getEntityClassColumns();
    Assert.assertEquals(1, columns.size());

    for (EntityColumn column : columns) {
        Assert.assertEquals("user_name", column.getColumn());
        Assert.assertEquals("userName", column.getProperty());

        Assert.assertEquals("user_name = #{userName}", column.getColumnEqualsHolder());
        Assert.assertEquals("user_name = #{record.userName}", column.getColumnEqualsHolder("record"));
        Assert.assertEquals("#{userName}", column.getColumnHolder());
        Assert.assertEquals("#{record.userName}", column.getColumnHolder("record"));
        Assert.assertEquals("#{record.userName}", column.getColumnHolder("record", "suffix"));
        Assert.assertEquals("#{record.userNamesuffix},", column.getColumnHolder("record", "suffix", ","));
        Assert.assertNull(column.getTypeHandler());
    }

    ResultMap resultMap = entityTable.getResultMap(configuration);
    Assert.assertEquals("[USER_NAME]", resultMap.getMappedColumns().toString());

    Assert.assertEquals(1, resultMap.getResultMappings().size());

    ResultMapping resultMapping = resultMap.getResultMappings().get(0);
    Assert.assertEquals("user_name", resultMapping.getColumn());
    Assert.assertEquals("userName", resultMapping.getProperty());
    Assert.assertNull(resultMapping.getJdbcType());
    Assert.assertEquals(StringTypeHandler.class, resultMapping.getTypeHandler().getClass());
}
 
Example #6
Source File: NameStyleTest.java    From Mapper with MIT License 5 votes vote down vote up
@Test
public void testNormal(){
    EntityHelper.initEntityNameMap(UserNormal.class, config);
    EntityTable entityTable = EntityHelper.getEntityTable(UserNormal.class);
    Assert.assertNotNull(entityTable);
    Assert.assertEquals("UserNormal", entityTable.getName());

    Set<EntityColumn> columns = entityTable.getEntityClassColumns();
    Assert.assertEquals(1, columns.size());

    for (EntityColumn column : columns) {
        Assert.assertEquals("userName", column.getColumn());
        Assert.assertEquals("userName", column.getProperty());

        Assert.assertEquals("userName = #{userName}", column.getColumnEqualsHolder());
        Assert.assertEquals("userName = #{record.userName}", column.getColumnEqualsHolder("record"));
        Assert.assertEquals("#{userName}", column.getColumnHolder());
        Assert.assertEquals("#{record.userName}", column.getColumnHolder("record"));
        Assert.assertEquals("#{record.userName}", column.getColumnHolder("record", "suffix"));
        Assert.assertEquals("#{record.userNamesuffix},", column.getColumnHolder("record", "suffix", ","));
        Assert.assertNull(column.getTypeHandler());
    }

    ResultMap resultMap = entityTable.getResultMap(configuration);
    Assert.assertEquals("[USERNAME]", resultMap.getMappedColumns().toString());

    Assert.assertEquals(1, resultMap.getResultMappings().size());

    ResultMapping resultMapping = resultMap.getResultMappings().get(0);
    Assert.assertEquals("userName", resultMapping.getColumn());
    Assert.assertEquals("userName", resultMapping.getProperty());
    Assert.assertNull(resultMapping.getJdbcType());
    Assert.assertEquals(StringTypeHandler.class, resultMapping.getTypeHandler().getClass());
}
 
Example #7
Source File: NameStyleTest.java    From Mapper with MIT License 5 votes vote down vote up
@Test
public void testUppercase(){
    EntityHelper.initEntityNameMap(UserUppercase.class, config);
    EntityTable entityTable = EntityHelper.getEntityTable(UserUppercase.class);
    Assert.assertNotNull(entityTable);
    Assert.assertEquals("USERUPPERCASE", entityTable.getName());

    Set<EntityColumn> columns = entityTable.getEntityClassColumns();
    Assert.assertEquals(1, columns.size());

    for (EntityColumn column : columns) {
        Assert.assertEquals("USERNAME", column.getColumn());
        Assert.assertEquals("userName", column.getProperty());

        Assert.assertEquals("USERNAME = #{userName}", column.getColumnEqualsHolder());
        Assert.assertEquals("USERNAME = #{record.userName}", column.getColumnEqualsHolder("record"));
        Assert.assertEquals("#{userName}", column.getColumnHolder());
        Assert.assertEquals("#{record.userName}", column.getColumnHolder("record"));
        Assert.assertEquals("#{record.userName}", column.getColumnHolder("record", "suffix"));
        Assert.assertEquals("#{record.userNamesuffix},", column.getColumnHolder("record", "suffix", ","));
        Assert.assertNull(column.getTypeHandler());
    }

    ResultMap resultMap = entityTable.getResultMap(configuration);
    Assert.assertEquals("[USERNAME]", resultMap.getMappedColumns().toString());

    Assert.assertEquals(1, resultMap.getResultMappings().size());

    ResultMapping resultMapping = resultMap.getResultMappings().get(0);
    Assert.assertEquals("USERNAME", resultMapping.getColumn());
    Assert.assertEquals("userName", resultMapping.getProperty());
    Assert.assertNull(resultMapping.getJdbcType());
    Assert.assertEquals(StringTypeHandler.class, resultMapping.getTypeHandler().getClass());
}
 
Example #8
Source File: NameStyleTest.java    From Mapper with MIT License 5 votes vote down vote up
@Test
public void testLowercase(){
    EntityHelper.initEntityNameMap(UserLowercase.class, config);
    EntityTable entityTable = EntityHelper.getEntityTable(UserLowercase.class);
    Assert.assertNotNull(entityTable);
    Assert.assertEquals("userlowercase", entityTable.getName());

    Set<EntityColumn> columns = entityTable.getEntityClassColumns();
    Assert.assertEquals(1, columns.size());

    for (EntityColumn column : columns) {
        Assert.assertEquals("username", column.getColumn());
        Assert.assertEquals("userName", column.getProperty());

        Assert.assertEquals("username = #{userName}", column.getColumnEqualsHolder());
        Assert.assertEquals("username = #{record.userName}", column.getColumnEqualsHolder("record"));
        Assert.assertEquals("#{userName}", column.getColumnHolder());
        Assert.assertEquals("#{record.userName}", column.getColumnHolder("record"));
        Assert.assertEquals("#{record.userName}", column.getColumnHolder("record", "suffix"));
        Assert.assertEquals("#{record.userNamesuffix},", column.getColumnHolder("record", "suffix", ","));
        Assert.assertNull(column.getTypeHandler());
    }

    ResultMap resultMap = entityTable.getResultMap(configuration);
    Assert.assertEquals("[USERNAME]", resultMap.getMappedColumns().toString());

    Assert.assertEquals(1, resultMap.getResultMappings().size());

    ResultMapping resultMapping = resultMap.getResultMappings().get(0);
    Assert.assertEquals("username", resultMapping.getColumn());
    Assert.assertEquals("userName", resultMapping.getProperty());
    Assert.assertNull(resultMapping.getJdbcType());
    Assert.assertEquals(StringTypeHandler.class, resultMapping.getTypeHandler().getClass());
}
 
Example #9
Source File: ColumnTypeTest.java    From Mapper with MIT License 5 votes vote down vote up
@Test
public void testColumn(){
    EntityHelper.initEntityNameMap(UserColumn.class, config);
    EntityTable entityTable = EntityHelper.getEntityTable(UserColumn.class);
    Assert.assertNotNull(entityTable);

    Set<EntityColumn> columns = entityTable.getEntityClassColumns();
    Assert.assertEquals(1, columns.size());

    for (EntityColumn column : columns) {
        Assert.assertEquals("user_name", column.getColumn());
        Assert.assertEquals("name", column.getProperty());

        Assert.assertEquals("user_name = #{name}", column.getColumnEqualsHolder());
        Assert.assertEquals("user_name = #{record.name}", column.getColumnEqualsHolder("record"));
        Assert.assertEquals("#{name}", column.getColumnHolder());
        Assert.assertEquals("#{record.name}", column.getColumnHolder("record"));
        Assert.assertEquals("#{record.name}", column.getColumnHolder("record", "suffix"));
        Assert.assertEquals("#{record.namesuffix},", column.getColumnHolder("record", "suffix", ","));
        Assert.assertNull(column.getTypeHandler());
    }

    ResultMap resultMap = entityTable.getResultMap(configuration);
    Assert.assertEquals("[USER_NAME]", resultMap.getMappedColumns().toString());

    Assert.assertEquals(1, resultMap.getResultMappings().size());

    ResultMapping resultMapping = resultMap.getResultMappings().get(0);
    Assert.assertEquals("user_name", resultMapping.getColumn());
    Assert.assertEquals("name", resultMapping.getProperty());
    Assert.assertNull(resultMapping.getJdbcType());
    Assert.assertEquals(StringTypeHandler.class, resultMapping.getTypeHandler().getClass());
}
 
Example #10
Source File: ColumnTypeTest.java    From Mapper with MIT License 5 votes vote down vote up
@Test
public void testJdbcTypeVarchar(){
    EntityHelper.initEntityNameMap(UserJdbcTypeVarchar.class, config);
    EntityTable entityTable = EntityHelper.getEntityTable(UserJdbcTypeVarchar.class);
    Assert.assertNotNull(entityTable);

    Set<EntityColumn> columns = entityTable.getEntityClassColumns();
    Assert.assertEquals(1, columns.size());

    for (EntityColumn column : columns) {
        Assert.assertEquals("name", column.getColumn());
        Assert.assertEquals("name", column.getProperty());

        Assert.assertEquals("name = #{name, jdbcType=VARCHAR}", column.getColumnEqualsHolder());
        Assert.assertEquals("name = #{record.name, jdbcType=VARCHAR}", column.getColumnEqualsHolder("record"));
        Assert.assertEquals("#{name, jdbcType=VARCHAR}", column.getColumnHolder());
        Assert.assertEquals("#{record.name, jdbcType=VARCHAR}", column.getColumnHolder("record"));
        Assert.assertEquals("#{record.name, jdbcType=VARCHAR}", column.getColumnHolder("record", "suffix"));
        Assert.assertEquals("#{record.namesuffix, jdbcType=VARCHAR},", column.getColumnHolder("record", "suffix", ","));
        Assert.assertNull(column.getTypeHandler());
    }

    ResultMap resultMap = entityTable.getResultMap(configuration);
    Assert.assertEquals("[NAME]", resultMap.getMappedColumns().toString());

    Assert.assertEquals(1, resultMap.getResultMappings().size());

    ResultMapping resultMapping = resultMap.getResultMappings().get(0);
    Assert.assertEquals("name", resultMapping.getColumn());
    Assert.assertEquals("name", resultMapping.getProperty());
    Assert.assertNotNull(resultMapping.getJdbcType());
    Assert.assertEquals(JdbcType.VARCHAR, resultMapping.getJdbcType());
    Assert.assertEquals(StringTypeHandler.class, resultMapping.getTypeHandler().getClass());
}
 
Example #11
Source File: ColumnTypeTest.java    From Mapper with MIT License 5 votes vote down vote up
@Test
public void testJdbcTypeBlob(){
    EntityHelper.initEntityNameMap(UserJdbcTypeBlob.class, config);
    EntityTable entityTable = EntityHelper.getEntityTable(UserJdbcTypeBlob.class);
    Assert.assertNotNull(entityTable);

    Set<EntityColumn> columns = entityTable.getEntityClassColumns();
    Assert.assertEquals(1, columns.size());

    for (EntityColumn column : columns) {
        Assert.assertEquals("name", column.getColumn());
        Assert.assertEquals("name", column.getProperty());

        Assert.assertEquals("name = #{name, jdbcType=BLOB}", column.getColumnEqualsHolder());
        Assert.assertEquals("name = #{record.name, jdbcType=BLOB}", column.getColumnEqualsHolder("record"));
        Assert.assertEquals("#{name, jdbcType=BLOB}", column.getColumnHolder());
        Assert.assertEquals("#{record.name, jdbcType=BLOB}", column.getColumnHolder("record"));
        Assert.assertEquals("#{record.name, jdbcType=BLOB}", column.getColumnHolder("record", "suffix"));
        Assert.assertEquals("#{record.namesuffix, jdbcType=BLOB},", column.getColumnHolder("record", "suffix", ","));
        Assert.assertNull(column.getTypeHandler());
    }

    ResultMap resultMap = entityTable.getResultMap(configuration);
    Assert.assertEquals("[NAME]", resultMap.getMappedColumns().toString());

    Assert.assertEquals(1, resultMap.getResultMappings().size());

    ResultMapping resultMapping = resultMap.getResultMappings().get(0);
    Assert.assertEquals("name", resultMapping.getColumn());
    Assert.assertEquals("name", resultMapping.getProperty());
    Assert.assertNotNull(resultMapping.getJdbcType());
    Assert.assertEquals(JdbcType.BLOB, resultMapping.getJdbcType());
    Assert.assertEquals(StringTypeHandler.class, resultMapping.getTypeHandler().getClass());
}
 
Example #12
Source File: ColumnTest.java    From Mapper with MIT License 5 votes vote down vote up
@Test
public void testColumn(){
    EntityHelper.initEntityNameMap(UserColumn.class, config);
    EntityTable entityTable = EntityHelper.getEntityTable(UserColumn.class);
    Assert.assertNotNull(entityTable);

    Set<EntityColumn> columns = entityTable.getEntityClassColumns();
    Assert.assertEquals(1, columns.size());

    for (EntityColumn column : columns) {
        Assert.assertEquals("user_name", column.getColumn());
        Assert.assertEquals("name", column.getProperty());

        Assert.assertEquals("user_name = #{name}", column.getColumnEqualsHolder());
        Assert.assertEquals("user_name = #{record.name}", column.getColumnEqualsHolder("record"));
        Assert.assertEquals("#{name}", column.getColumnHolder());
        Assert.assertEquals("#{record.name}", column.getColumnHolder("record"));
        Assert.assertEquals("#{record.name}", column.getColumnHolder("record", "suffix"));
        Assert.assertEquals("#{record.namesuffix},", column.getColumnHolder("record", "suffix", ","));
        Assert.assertNull(column.getTypeHandler());
    }

    ResultMap resultMap = entityTable.getResultMap(configuration);
    Assert.assertEquals("[USER_NAME]", resultMap.getMappedColumns().toString());

    Assert.assertEquals(1, resultMap.getResultMappings().size());

    ResultMapping resultMapping = resultMap.getResultMappings().get(0);
    Assert.assertEquals("user_name", resultMapping.getColumn());
    Assert.assertEquals("name", resultMapping.getProperty());
    Assert.assertNull(resultMapping.getJdbcType());
    Assert.assertEquals(StringTypeHandler.class, resultMapping.getTypeHandler().getClass());
}
 
Example #13
Source File: NullTest.java    From mybaties with Apache License 2.0 4 votes vote down vote up
@Test
public void shouldGetTypeAndTypeHandlerForNullStringType() {
  assertEquals(JdbcType.VARCHAR, Null.STRING.getJdbcType());
  assertTrue(Null.STRING.getTypeHandler() instanceof StringTypeHandler);
}
 
Example #14
Source File: NullTest.java    From mybatis with Apache License 2.0 4 votes vote down vote up
@Test
public void shouldGetTypeAndTypeHandlerForNullStringType() {
  assertEquals(JdbcType.VARCHAR, Null.STRING.getJdbcType());
  assertTrue(Null.STRING.getTypeHandler() instanceof StringTypeHandler);
}