Java Code Examples for org.apache.ibatis.type.TypeHandlerRegistry#getTypeHandler()

The following examples show how to use org.apache.ibatis.type.TypeHandlerRegistry#getTypeHandler() . 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: XmlConfigBuilderTest.java    From mybaties with Apache License 2.0 6 votes vote down vote up
@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);
}
 
Example 2
Source File: XmlConfigBuilderTest.java    From mybatis with Apache License 2.0 6 votes vote down vote up
@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);
}
 
Example 3
Source File: MultipleJdbc3KeyGenerator.java    From tk-mybatis with MIT License 5 votes vote down vote up
private TypeHandler<?>[] getTypeHandlers(TypeHandlerRegistry typeHandlerRegistry, MetaObject metaParam, String[] keyProperties) {
    TypeHandler<?>[] typeHandlers = new TypeHandler<?>[keyProperties.length];
    for (int i = 0; i < keyProperties.length; i++) {
        if (metaParam.hasSetter(keyProperties[i])) {
            Class<?> keyPropertyType = metaParam.getSetterType(keyProperties[i]);
            TypeHandler<?> th = typeHandlerRegistry.getTypeHandler(keyPropertyType);
            typeHandlers[i] = th;
        }
    }
    return typeHandlers;
}
 
Example 4
Source File: ResultMapping.java    From mybaties with Apache License 2.0 5 votes vote down vote up
private void resolveTypeHandler() {
  if (resultMapping.typeHandler == null && resultMapping.javaType != null) {
    Configuration configuration = resultMapping.configuration;
    TypeHandlerRegistry typeHandlerRegistry = configuration.getTypeHandlerRegistry();
    resultMapping.typeHandler = typeHandlerRegistry.getTypeHandler(resultMapping.javaType, resultMapping.jdbcType);
  }
}
 
Example 5
Source File: ParameterMapping.java    From mybaties with Apache License 2.0 5 votes vote down vote up
private void resolveTypeHandler() {
    //如果没有指定特殊的typeHandler,则根据javaType,jdbcType来查表确定一个默认的typeHandler
  if (parameterMapping.typeHandler == null && parameterMapping.javaType != null) {
    Configuration configuration = parameterMapping.configuration;
    TypeHandlerRegistry typeHandlerRegistry = configuration.getTypeHandlerRegistry();
    parameterMapping.typeHandler = typeHandlerRegistry.getTypeHandler(parameterMapping.javaType, parameterMapping.jdbcType);
  }
}
 
Example 6
Source File: Jdbc3KeyGenerator.java    From mybaties with Apache License 2.0 5 votes vote down vote up
private TypeHandler<?>[] getTypeHandlers(TypeHandlerRegistry typeHandlerRegistry, MetaObject metaParam, String[] keyProperties) {
  TypeHandler<?>[] typeHandlers = new TypeHandler<?>[keyProperties.length];
  for (int i = 0; i < keyProperties.length; i++) {
    if (metaParam.hasSetter(keyProperties[i])) {
      Class<?> keyPropertyType = metaParam.getSetterType(keyProperties[i]);
      TypeHandler<?> th = typeHandlerRegistry.getTypeHandler(keyPropertyType);
      typeHandlers[i] = th;
    }
  }
  return typeHandlers;
}
 
Example 7
Source File: ResultMapping.java    From mybatis with Apache License 2.0 5 votes vote down vote up
private void resolveTypeHandler() {
  if (resultMapping.typeHandler == null && resultMapping.javaType != null) {
    Configuration configuration = resultMapping.configuration;
    TypeHandlerRegistry typeHandlerRegistry = configuration.getTypeHandlerRegistry();
    resultMapping.typeHandler = typeHandlerRegistry.getTypeHandler(resultMapping.javaType, resultMapping.jdbcType);
  }
}
 
Example 8
Source File: ParameterMapping.java    From mybatis with Apache License 2.0 5 votes vote down vote up
private void resolveTypeHandler() {
    //如果没有指定特殊的typeHandler,则根据javaType,jdbcType来查表确定一个默认的typeHandler
  if (parameterMapping.typeHandler == null && parameterMapping.javaType != null) {
    Configuration configuration = parameterMapping.configuration;
    TypeHandlerRegistry typeHandlerRegistry = configuration.getTypeHandlerRegistry();
    parameterMapping.typeHandler = typeHandlerRegistry.getTypeHandler(parameterMapping.javaType, parameterMapping.jdbcType);
  }
}
 
Example 9
Source File: Jdbc3KeyGenerator.java    From mybatis with Apache License 2.0 5 votes vote down vote up
private TypeHandler<?>[] getTypeHandlers(TypeHandlerRegistry typeHandlerRegistry, MetaObject metaParam, String[] keyProperties) {
  TypeHandler<?>[] typeHandlers = new TypeHandler<?>[keyProperties.length];
  for (int i = 0; i < keyProperties.length; i++) {
    if (metaParam.hasSetter(keyProperties[i])) {
      Class<?> keyPropertyType = metaParam.getSetterType(keyProperties[i]);
      TypeHandler<?> th = typeHandlerRegistry.getTypeHandler(keyPropertyType);
      typeHandlers[i] = th;
    }
  }
  return typeHandlers;
}