本文整理汇总了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);
}
示例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"));
}
}
示例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);
}
}
示例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"));
}
}