当前位置: 首页>>代码示例>>Java>>正文


Java TypeHandlerRegistry类代码示例

本文整理汇总了Java中org.apache.ibatis.type.TypeHandlerRegistry的典型用法代码示例。如果您正苦于以下问题:Java TypeHandlerRegistry类的具体用法?Java TypeHandlerRegistry怎么用?Java TypeHandlerRegistry使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


TypeHandlerRegistry类属于org.apache.ibatis.type包,在下文中一共展示了TypeHandlerRegistry类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: prepareInsertAuthorMappedStatement

import org.apache.ibatis.type.TypeHandlerRegistry; //导入依赖的package包/类
public static MappedStatement prepareInsertAuthorMappedStatement(final Configuration config) {
  final TypeHandlerRegistry registry = config.getTypeHandlerRegistry();
  MappedStatement ms = new MappedStatement.Builder(config, "insertAuthor", new StaticSqlSource(config,"INSERT INTO author (id,username,password,email,bio,favourite_section) values(?,?,?,?,?,?)"), SqlCommandType.INSERT)
      .parameterMap(
          new ParameterMap.Builder(
              config, "defaultParameterMap", Author.class,
              new ArrayList<ParameterMapping>() {
                {
                  add(new ParameterMapping.Builder(config, "id", registry.getTypeHandler(int.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).build();
  return ms;
}
 
开发者ID:yuexiahandao,项目名称:MybatisCode,代码行数:20,代码来源:ExecutorTestHelper.java

示例2: prepareSelectAuthorViaOutParams

import org.apache.ibatis.type.TypeHandlerRegistry; //导入依赖的package包/类
public static MappedStatement prepareSelectAuthorViaOutParams(final Configuration config) {
  final TypeHandlerRegistry registry = config.getTypeHandlerRegistry();
  MappedStatement ms = new MappedStatement.Builder(config, "selectAuthorViaOutParams", new StaticSqlSource(config, "{call selectAuthorViaOutParams(?,?,?,?,?)}"), SqlCommandType.SELECT)
      .statementType(StatementType.CALLABLE)
      .parameterMap(new ParameterMap.Builder(config, "defaultParameterMap", Author.class,
          new ArrayList<ParameterMapping>() {
            {
              add(new ParameterMapping.Builder(config, "id", registry.getTypeHandler(int.class)).build());
              add(new ParameterMapping.Builder(config, "username", registry.getTypeHandler(String.class)).jdbcType(JdbcType.VARCHAR).mode(ParameterMode.OUT).build());
              add(new ParameterMapping.Builder(config, "password", registry.getTypeHandler(String.class)).jdbcType(JdbcType.VARCHAR).mode(ParameterMode.OUT).build());
              add(new ParameterMapping.Builder(config, "email", registry.getTypeHandler(String.class)).jdbcType(JdbcType.VARCHAR).mode(ParameterMode.OUT).build());
              add(new ParameterMapping.Builder(config, "bio", registry.getTypeHandler(String.class)).jdbcType(JdbcType.VARCHAR).mode(ParameterMode.OUT).build());
            }
          }).build())
      .resultMaps(new ArrayList<ResultMap>())
      .cache(authorCache).build();
  return ms;
}
 
开发者ID:txazo,项目名称:mybatis,代码行数:19,代码来源:ExecutorTestHelper.java

示例3: registerJavaTypeInitializingTypeHandler

import org.apache.ibatis.type.TypeHandlerRegistry; //导入依赖的package包/类
@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);
}
 
开发者ID:yuexiahandao,项目名称:MybatisCode,代码行数:21,代码来源:XmlConfigBuilderTest.java

示例4: prepareInsertAuthorMappedStatementWithAutoKey

import org.apache.ibatis.type.TypeHandlerRegistry; //导入依赖的package包/类
public static MappedStatement prepareInsertAuthorMappedStatementWithAutoKey(final Configuration config) {
  final TypeHandlerRegistry registry = config.getTypeHandlerRegistry();
  MappedStatement ms = new MappedStatement.Builder(config, "insertAuthor", new StaticSqlSource(config,"INSERT INTO author (username,password,email,bio,favourite_section) values(?,?,?,?,?)"), SqlCommandType.INSERT)
      .parameterMap(
          new ParameterMap.Builder(config, "defaultParameterMap", Author.class, new ArrayList<ParameterMapping>() {
            {
              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 Jdbc3KeyGenerator())
      .keyProperty("id")
      .build();
  return ms;
}
 
开发者ID:yuexiahandao,项目名称:MybatisCode,代码行数:20,代码来源:ExecutorTestHelper.java

示例5: prepareUpdateAuthorMappedStatement

import org.apache.ibatis.type.TypeHandlerRegistry; //导入依赖的package包/类
public static MappedStatement prepareUpdateAuthorMappedStatement(final Configuration config) {
  final TypeHandlerRegistry registry = config.getTypeHandlerRegistry();
  MappedStatement ms = new MappedStatement.Builder(config, "updateAuthor", new StaticSqlSource(config,"UPDATE author SET username = ?, password = ?, email = ?, bio = ? WHERE id = ?"), SqlCommandType.UPDATE)
      .parameterMap(new ParameterMap.Builder(config, "defaultParameterMap", Author.class,
          new ArrayList<ParameterMapping>() {
            {
              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, "id", registry.getTypeHandler(int.class)).build());
            }
          }).build())
      .cache(authorCache).build();
  return ms;
}
 
开发者ID:yuexiahandao,项目名称:MybatisCode,代码行数:17,代码来源:ExecutorTestHelper.java

示例6: createSelectAuthorWithIDof99MappedStatement

import org.apache.ibatis.type.TypeHandlerRegistry; //导入依赖的package包/类
public static MappedStatement createSelectAuthorWithIDof99MappedStatement(final Configuration config) {
  final TypeHandlerRegistry registry = config.getTypeHandlerRegistry();
  MappedStatement ms = new MappedStatement.Builder(config, "selectAuthor", new StaticSqlSource(config,"SELECT * FROM author WHERE id = 99"), SqlCommandType.SELECT)
      .statementType(StatementType.STATEMENT)
      .parameterMap(new ParameterMap.Builder(config, "defaultParameterMap", Author.class, new ArrayList<ParameterMapping>()).build())
      .resultMaps(new ArrayList<ResultMap>() {
        {
          add(new ResultMap.Builder(config, "defaultResultMap", Author.class, new ArrayList<ResultMapping>() {
            {
              add(new ResultMapping.Builder(config, "id", "id", registry.getTypeHandler(int.class)).build());
              add(new ResultMapping.Builder(config, "username", "username", registry.getTypeHandler(String.class)).build());
              add(new ResultMapping.Builder(config, "password", "password", registry.getTypeHandler(String.class)).build());
              add(new ResultMapping.Builder(config, "email", "email", registry.getTypeHandler(String.class)).build());
              add(new ResultMapping.Builder(config, "bio", "bio", registry.getTypeHandler(String.class)).build());
            }
          }).build());
        }
      }).build();
  return ms;
}
 
开发者ID:yuexiahandao,项目名称:MybatisCode,代码行数:21,代码来源:ExecutorTestHelper.java

示例7: getTypeHandlers

import org.apache.ibatis.type.TypeHandlerRegistry; //导入依赖的package包/类
private TypeHandler<?>[] getTypeHandlers(TypeHandlerRegistry typeHandlerRegistry, MetaObject metaParam, String[] keyProperties, ResultSetMetaData rsmd) throws SQLException {
  TypeHandler<?>[] typeHandlers = new TypeHandler<?>[keyProperties.length];
  for (int i = 0; i < keyProperties.length; i++) {
    if (metaParam.hasSetter(keyProperties[i])) {
      TypeHandler<?> th;
      try {
        Class<?> keyPropertyType = metaParam.getSetterType(keyProperties[i]);
        th = typeHandlerRegistry.getTypeHandler(keyPropertyType, JdbcType.forCode(rsmd.getColumnType(i + 1)));
      } catch (BindingException e) {
        th = null;
      }
      typeHandlers[i] = th;
    }
  }
  return typeHandlers;
}
 
开发者ID:mybatis,项目名称:mybatis-3,代码行数:17,代码来源:Jdbc3KeyGenerator.java

示例8: prepareInsertAuthorMappedStatementWithAutoKey

import org.apache.ibatis.type.TypeHandlerRegistry; //导入依赖的package包/类
public static MappedStatement prepareInsertAuthorMappedStatementWithAutoKey(final Configuration config) {
  final TypeHandlerRegistry registry = config.getTypeHandlerRegistry();
  MappedStatement ms = new MappedStatement.Builder(config, "insertAuthor", new StaticSqlSource(config,"INSERT INTO author (username,password,email,bio,favourite_section) values(?,?,?,?,?)"), SqlCommandType.INSERT)
      .parameterMap(
          new ParameterMap.Builder(config, "defaultParameterMap", Author.class, new ArrayList<ParameterMapping>() {
            {
              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(Jdbc3KeyGenerator.INSTANCE)
      .keyProperty("id")
      .build();
  return ms;
}
 
开发者ID:mybatis,项目名称:mybatis-3,代码行数:20,代码来源:ExecutorTestHelper.java

示例9: getTypeHandlers

import org.apache.ibatis.type.TypeHandlerRegistry; //导入依赖的package包/类
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;
}
 
开发者ID:Yanweichen,项目名称:MybatisGeneatorUtil,代码行数:12,代码来源:MultipleJdbc3KeyGenerator.java

示例10: getNamespaceSql

import org.apache.ibatis.type.TypeHandlerRegistry; //导入依赖的package包/类
/**
 * 通过命名空间方式获取sql
 * @param session
 * @param namespace
 * @param params
 * @return
 */
public static String getNamespaceSql(SqlSession session, String namespace, Object params) {
    Configuration configuration = session.getConfiguration();
    MappedStatement mappedStatement = configuration.getMappedStatement(namespace);
    TypeHandlerRegistry typeHandlerRegistry = mappedStatement.getConfiguration().getTypeHandlerRegistry();
    BoundSql boundSql = mappedStatement.getBoundSql(params);
    List<ParameterMapping> parameterMappings = boundSql.getParameterMappings();
    String sql = boundSql.getSql();
    if (parameterMappings != null) {
        for (int i = 0; i < parameterMappings.size(); i++) {
            ParameterMapping parameterMapping = parameterMappings.get(i);
            if (parameterMapping.getMode() != ParameterMode.OUT) {
                Object value;
                String propertyName = parameterMapping.getProperty();
                if (boundSql.hasAdditionalParameter(propertyName)) {
                    value = boundSql.getAdditionalParameter(propertyName);
                } else if (params == null) {
                    value = null;
                } else if (typeHandlerRegistry.hasTypeHandler(params.getClass())) {
                    value = params;
                } else {
                    MetaObject metaObject = configuration.newMetaObject(params);
                    value = metaObject.getValue(propertyName);
                }
                JdbcType jdbcType = parameterMapping.getJdbcType();
                if (value == null && jdbcType == null) jdbcType = configuration.getJdbcTypeForNull();
                sql = replaceParameter(sql, value, jdbcType, parameterMapping.getJavaType());
            }
        }
    }
    return sql;
}
 
开发者ID:itfsw,项目名称:mybatis-generator-plugin,代码行数:39,代码来源:SqlHelper.java

示例11: resolveTypeHandler

import org.apache.ibatis.type.TypeHandlerRegistry; //导入依赖的package包/类
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);
  }
}
 
开发者ID:yuexiahandao,项目名称:MybatisCode,代码行数:8,代码来源:ResultMapping.java

示例12: resolveTypeHandler

import org.apache.ibatis.type.TypeHandlerRegistry; //导入依赖的package包/类
private void resolveTypeHandler() {
  if (parameterMapping.typeHandler == null && parameterMapping.javaType != null) {
    Configuration configuration = parameterMapping.configuration;
    TypeHandlerRegistry typeHandlerRegistry = configuration.getTypeHandlerRegistry();
    parameterMapping.typeHandler = typeHandlerRegistry.getTypeHandler(parameterMapping.javaType, parameterMapping.jdbcType);
  }
}
 
开发者ID:yuexiahandao,项目名称:MybatisCode,代码行数:8,代码来源:ParameterMapping.java

示例13: createCacheKey

import org.apache.ibatis.type.TypeHandlerRegistry; //导入依赖的package包/类
@Override
public CacheKey createCacheKey(MappedStatement ms, Object parameterObject, RowBounds rowBounds, BoundSql boundSql) {
  if (closed) {
    throw new ExecutorException("Executor was closed.");
  }
  CacheKey cacheKey = new CacheKey();
  cacheKey.update(ms.getId());
  cacheKey.update(rowBounds.getOffset());
  cacheKey.update(rowBounds.getLimit());
  cacheKey.update(boundSql.getSql());
  List<ParameterMapping> parameterMappings = boundSql.getParameterMappings();
  TypeHandlerRegistry typeHandlerRegistry = ms.getConfiguration().getTypeHandlerRegistry();
  // mimic DefaultParameterHandler logic
  for (ParameterMapping parameterMapping : parameterMappings) {
    if (parameterMapping.getMode() != ParameterMode.OUT) {
      Object value;
      String propertyName = parameterMapping.getProperty();
      if (boundSql.hasAdditionalParameter(propertyName)) {
        value = boundSql.getAdditionalParameter(propertyName);
      } else if (parameterObject == null) {
        value = null;
      } else if (typeHandlerRegistry.hasTypeHandler(parameterObject.getClass())) {
        value = parameterObject;
      } else {
        MetaObject metaObject = configuration.newMetaObject(parameterObject);
        value = metaObject.getValue(propertyName);
      }
      cacheKey.update(value);
    }
  }
  if (configuration.getEnvironment() != null) {
    // issue #176
    cacheKey.update(configuration.getEnvironment().getId());
  }
  return cacheKey;
}
 
开发者ID:yuexiahandao,项目名称:MybatisCode,代码行数:37,代码来源:BaseExecutor.java

示例14: getTypeHandlers

import org.apache.ibatis.type.TypeHandlerRegistry; //导入依赖的package包/类
private TypeHandler<?>[] getTypeHandlers(TypeHandlerRegistry typeHandlerRegistry, MetaObject metaParam, String[] keyProperties, ResultSetMetaData rsmd) throws SQLException {
  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, JdbcType.forCode(rsmd.getColumnType(i + 1)));
      typeHandlers[i] = th;
    }
  }
  return typeHandlers;
}
 
开发者ID:yuexiahandao,项目名称:MybatisCode,代码行数:12,代码来源:Jdbc3KeyGenerator.java

示例15: getMappedStatement

import org.apache.ibatis.type.TypeHandlerRegistry; //导入依赖的package包/类
MappedStatement getMappedStatement() {
  final Configuration config = new Configuration();
  final TypeHandlerRegistry registry = config.getTypeHandlerRegistry();
  return new MappedStatement.Builder(config, "testSelect", new StaticSqlSource(config, "some select statement"), SqlCommandType.SELECT).resultMaps(
      new ArrayList<ResultMap>() {
        {
          add(new ResultMap.Builder(config, "testMap", HashMap.class, new ArrayList<ResultMapping>() {
            {
              add(new ResultMapping.Builder(config, "cOlUmN1", "CoLuMn1", registry.getTypeHandler(Integer.class)).build());
            }
          }).build());
        }
      }).build();
}
 
开发者ID:yuexiahandao,项目名称:MybatisCode,代码行数:15,代码来源:DefaultParameterHandlerTest.java


注:本文中的org.apache.ibatis.type.TypeHandlerRegistry类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。