use of org.apache.ibatis.type.TypeHandlerRegistry in project mybatis-3 by mybatis.
the class ExecutorTestHelper method prepareInsertAuthorMappedStatementWithBeforeAutoKey.
public static MappedStatement prepareInsertAuthorMappedStatementWithBeforeAutoKey(final Configuration config) {
final TypeHandlerRegistry registry = config.getTypeHandlerRegistry();
final ResultMap rm = new ResultMap.Builder(config, "keyResultMap", Integer.class, new ArrayList<ResultMapping>()).build();
MappedStatement kms = new MappedStatement.Builder(config, "insertAuthor!selectKey", new StaticSqlSource(config, "SELECT 123456 as id FROM SYSIBM.SYSDUMMY1"), SqlCommandType.SELECT).keyProperty("id").resultMaps(new ArrayList<ResultMap>() {
{
add(rm);
}
}).build();
config.addMappedStatement(kms);
MappedStatement ms = new MappedStatement.Builder(config, "insertAuthor", new DynamicSqlSource(config, new TextSqlNode("INSERT INTO author (id,username,password,email,bio,favourite_section) values(#{id},#{username},#{password},#{email},#{bio:VARCHAR},#{favouriteSection})")), SqlCommandType.INSERT).parameterMap(new ParameterMap.Builder(config, "defaultParameterMap", Author.class, new ArrayList<ParameterMapping>() {
{
add(new ParameterMapping.Builder(config, "id", registry.getTypeHandler(Integer.class)).build());
add(new ParameterMapping.Builder(config, "username", registry.getTypeHandler(String.class)).build());
add(new ParameterMapping.Builder(config, "password", registry.getTypeHandler(String.class)).build());
add(new ParameterMapping.Builder(config, "email", registry.getTypeHandler(String.class)).build());
add(new ParameterMapping.Builder(config, "bio", registry.getTypeHandler(String.class)).jdbcType(JdbcType.VARCHAR).build());
add(new ParameterMapping.Builder(config, "favouriteSection", registry.getTypeHandler(Section.class)).jdbcType(JdbcType.VARCHAR).build());
}
}).build()).cache(authorCache).keyGenerator(new SelectKeyGenerator(kms, true)).keyProperty("id").build();
return ms;
}
use of org.apache.ibatis.type.TypeHandlerRegistry in project mybatis-3 by mybatis.
the class XmlConfigBuilderTest method registerJavaTypeInitializingTypeHandler.
@Test
public void registerJavaTypeInitializingTypeHandler() {
final String MAPPER_CONFIG = "<?xml version=\"1.0\" encoding=\"UTF-8\" ?>\n" + "<!DOCTYPE configuration PUBLIC \"-//mybatis.org//DTD Config 3.0//EN\" \"http://mybatis.org/dtd/mybatis-3-config.dtd\">\n" + "<configuration>\n" + " <typeHandlers>\n" + " <typeHandler javaType=\"org.apache.ibatis.builder.XmlConfigBuilderTest$MyEnum\"\n" + " handler=\"org.apache.ibatis.builder.XmlConfigBuilderTest$EnumOrderTypeHandler\"/>\n" + " </typeHandlers>\n" + "</configuration>\n";
XMLConfigBuilder builder = new XMLConfigBuilder(new StringReader(MAPPER_CONFIG));
builder.parse();
TypeHandlerRegistry typeHandlerRegistry = builder.getConfiguration().getTypeHandlerRegistry();
TypeHandler<MyEnum> typeHandler = typeHandlerRegistry.getTypeHandler(MyEnum.class);
assertTrue(typeHandler instanceof EnumOrderTypeHandler);
assertArrayEquals(MyEnum.values(), ((EnumOrderTypeHandler) typeHandler).constants);
}
use of org.apache.ibatis.type.TypeHandlerRegistry in project mybatis-3 by mybatis.
the class AutodiscoverTest method testTypeHandler.
@Test
public void testTypeHandler() {
TypeHandlerRegistry typeHandlerRegistry = sqlSessionFactory.getConfiguration().getTypeHandlerRegistry();
assertTrue(typeHandlerRegistry.hasTypeHandler(BigInteger.class));
}
Aggregations