List of usage examples for org.apache.ibatis.type TypeException TypeException
public TypeException(String message, Throwable cause)
From source file:com.baomidou.mybatisplus.MybatisDefaultParameterHandler.java
License:Apache License
@SuppressWarnings({ "rawtypes", "unchecked" }) @Override/* ww w.j a v a 2 s .co m*/ public void setParameters(PreparedStatement ps) { // ????? Map<String, Object> additionalParameters = null; try { additionalParameters = (Map<String, Object>) additionalParametersField.get(boundSql); } catch (IllegalAccessException e) { // ignored, Because it will never happen. } ErrorContext.instance().activity("setting parameters").object(mappedStatement.getParameterMap().getId()); List<ParameterMapping> parameterMappings = boundSql.getParameterMappings(); 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)) { // issue // #448 // ask // first // for // additional // params 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); if (value == null && MapUtils.isNotEmpty(additionalParameters)) { // issue #138 value = additionalParameters.get(propertyName); } } TypeHandler typeHandler = parameterMapping.getTypeHandler(); JdbcType jdbcType = parameterMapping.getJdbcType(); if (value == null && jdbcType == null) { jdbcType = configuration.getJdbcTypeForNull(); } try { typeHandler.setParameter(ps, i + 1, value, jdbcType); } catch (TypeException | SQLException e) { throw new TypeException( "Could not set parameters for mapping: " + parameterMapping + ". Cause: " + e, e); } } } } }
From source file:org.mybatis.guice.type.TypeHandlerProvider.java
License:Apache License
@Override @SuppressWarnings("unchecked") public TH get() { TH instance = null;/*from ww w .j a v a2s. co m*/ if (handledType != null) { try { Constructor<?> c = typeHandlerTypeLiteral.getRawType().getConstructor(Class.class); instance = (TH) c.newInstance(handledType); injector.injectMembers(instance); } catch (NoSuchMethodException ignored) { // ignored } catch (Exception e) { throw new TypeException( "Failed invoking constructor for handler " + typeHandlerTypeLiteral.getType(), e); } } if (instance == null) { try { instance = (TH) typeHandlerTypeLiteral.getRawType().newInstance(); injector.injectMembers(instance); } catch (Exception e) { throw new TypeException( "Failed invoking constructor for handler " + typeHandlerTypeLiteral.getType(), e); } } return instance; }