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


Java TypeException类代码示例

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


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

示例1: setNonNullParameter

import org.apache.ibatis.type.TypeException; //导入依赖的package包/类
@Override
public void setNonNullParameter(PreparedStatement ps, int i, Object[] parameter,
                                JdbcType jdbcType) throws SQLException {

    String typeName = null;
    if (parameter instanceof Integer[]) {
        typeName = TYPE_NAME_INTEGER;
    } else if (parameter instanceof String[]) {
        typeName = TYPE_NAME_VARCHAR;
    } else if (parameter instanceof Boolean[]) {
        typeName = TYPE_NAME_BOOLEAN;
    } else if (parameter instanceof Double[]) {
        typeName = TYPE_NAME_NUMERIC;
    }

    if (typeName == null) {
        throw new TypeException("ArrayTypeHandler parameter typeName error, your type is " + parameter.getClass().getName());
    }

    // 这3行是关键的代码,创建Array,然后ps.setArray(i, array)就可以了
    Connection conn = ps.getConnection();
    Array array = conn.createArrayOf(typeName, parameter);
    ps.setArray(i, array);
}
 
开发者ID:ling49043171,项目名称:mark-framework,代码行数:25,代码来源:ArrayTypeHandler.java

示例2: setParametersThrowsProperException

import org.apache.ibatis.type.TypeException; //导入依赖的package包/类
@Test
public void setParametersThrowsProperException() throws SQLException {
  final MappedStatement mappedStatement = getMappedStatement();
  final Object parameterObject = null;
  final BoundSql boundSql = mock(BoundSql.class);

  TypeHandler<String> typeHandler = mock(TypeHandler.class);
  doThrow(new SQLException("foo")).when(typeHandler).setParameter(any(PreparedStatement.class), anyInt(), anyString(), any(JdbcType.class));
  ParameterMapping parameterMapping = new ParameterMapping.Builder(mappedStatement.getConfiguration(), "prop", typeHandler).build();
  List<ParameterMapping> parameterMappings = Collections.singletonList(parameterMapping);
  when(boundSql.getParameterMappings()).thenReturn(parameterMappings);

  DefaultParameterHandler defaultParameterHandler = new DefaultParameterHandler(mappedStatement, parameterObject, boundSql);

  PreparedStatement ps = mock(PreparedStatement.class);
  try {
    defaultParameterHandler.setParameters(ps);
    Assert.fail("Should have thrown TypeException");
  } catch (Exception e) {
    Assert.assertTrue("expected TypeException", e instanceof TypeException);
    Assert.assertTrue("", e.getMessage().contains("mapping: ParameterMapping"));
  }

}
 
开发者ID:yuexiahandao,项目名称:MybatisCode,代码行数:25,代码来源:DefaultParameterHandlerTest.java

示例3: shouldInstantiateAndThrowAllCustomExceptions

import org.apache.ibatis.type.TypeException; //导入依赖的package包/类
@Test
public void shouldInstantiateAndThrowAllCustomExceptions() throws Exception {
  Class<?>[] exceptionTypes = {
      BindingException.class,
      CacheException.class,
      DataSourceException.class,
      ExecutorException.class,
      LogException.class,
      ParsingException.class,
      BuilderException.class,
      PluginException.class,
      ReflectionException.class,
      PersistenceException.class,
      SqlSessionException.class,
      TransactionException.class,
      TypeException.class, 
      ScriptingException.class
  };
  for (Class<?> exceptionType : exceptionTypes) {
    testExceptionConstructors(exceptionType);
  }

}
 
开发者ID:yuexiahandao,项目名称:MybatisCode,代码行数:24,代码来源:GeneralExceptionsTest.java

示例4: setParametersThrowsProperException

import org.apache.ibatis.type.TypeException; //导入依赖的package包/类
@Test
public void setParametersThrowsProperException() throws SQLException {
  final MappedStatement mappedStatement = getMappedStatement();
  final Object parameterObject = null;
  final BoundSql boundSql = mock(BoundSql.class);

  TypeHandler<Object> typeHandler = mock(TypeHandler.class);
  doThrow(new SQLException("foo")).when(typeHandler).setParameter(any(PreparedStatement.class), anyInt(), any(), any(JdbcType.class));
  ParameterMapping parameterMapping = new ParameterMapping.Builder(mappedStatement.getConfiguration(), "prop", typeHandler).build();
  List<ParameterMapping> parameterMappings = Collections.singletonList(parameterMapping);
  when(boundSql.getParameterMappings()).thenReturn(parameterMappings);

  DefaultParameterHandler defaultParameterHandler = new DefaultParameterHandler(mappedStatement, parameterObject, boundSql);

  PreparedStatement ps = mock(PreparedStatement.class);
  try {
    defaultParameterHandler.setParameters(ps);
    Assert.fail("Should have thrown TypeException");
  } catch (Exception e) {
    Assert.assertTrue("expected TypeException", e instanceof TypeException);
    Assert.assertTrue("", e.getMessage().contains("mapping: ParameterMapping"));
  }

}
 
开发者ID:mybatis,项目名称:mybatis-3,代码行数:25,代码来源:DefaultParameterHandlerTest.java


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