org.apache.ibatis.type.TypeException Java Examples

The following examples show how to use org.apache.ibatis.type.TypeException. 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: PluginMybatisXmlMapperBuilder.java    From springboot-plugin-framework-parent with Apache License 2.0 6 votes vote down vote up
@Override
protected <T> Class<? extends T> resolveAlias(String alias) {
    if (alias == null) {
        return null;
    }
    Map<String, Class<?>> typeAliases = typeAliasRegistry.getTypeAliases();
    String key = alias.toLowerCase(Locale.ENGLISH);
    if (typeAliases.containsKey(key)) {
        return typeAliasRegistry.resolveAlias(alias);
    } else {
        try {
            return (Class<T>) Class.forName(alias, false, pluginClassLoader);
        } catch (ClassNotFoundException e) {
            throw new TypeException("Could not resolve type alias '" + alias + "'.  Cause: " + e, e);
        }
    }
}
 
Example #2
Source File: ArrayTypeHandler.java    From tutorial with MIT License 6 votes vote down vote up
@Override
public void setNonNullParameter(PreparedStatement preparedStatement, int i, T t, JdbcType jdbcType) throws SQLException {
    logger.trace("setNonNullParameter(ps, i, {}, {}", t, jdbcType);
    logger.trace("<T> {}, {}, {}, getGenericInterfaces:{} getGenericSuperclass:{} ", type, type.getTypeParameters(), type.isArray(), type.getGenericInterfaces(), type.getGenericSuperclass());
    String typeName = null;
    if (t instanceof Integer[]) {
        typeName = "integer";
    } else if (t instanceof String[]) {
        typeName = "varchar";
    } else if (t instanceof Boolean[]) {
        typeName = "boolean";
    } else if (t instanceof Double[]) {
        typeName = "numeric";
    }

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

    Connection conn = preparedStatement.getConnection();
    Array array = conn.createArrayOf(typeName, (Object[]) t);
    preparedStatement.setArray(i, array);

}
 
Example #3
Source File: GeneralExceptionsTest.java    From mybaties with Apache License 2.0 6 votes vote down vote up
@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);
  }

}
 
Example #4
Source File: GeneralExceptionsTest.java    From mybatis with Apache License 2.0 6 votes vote down vote up
@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);
  }

}
 
Example #5
Source File: TransController.java    From das with Apache License 2.0 5 votes vote down vote up
@Override
public <T> Class<T> resolveAlias(String string) {
    try {
        super.resolveAlias(string);
    }catch (TypeException e){
        ClassPool cp = ClassPool.getDefault();
        CtClass clz = cp.makeClass(string);
        try {
            Class result = clz.toClass();
        } catch (CannotCompileException e1) {
            e1.printStackTrace();
        }
    }
    return super.resolveAlias(string);
}