Example usage for org.apache.ibatis.binding BindingException BindingException

List of usage examples for org.apache.ibatis.binding BindingException BindingException

Introduction

In this page you can find the example usage for org.apache.ibatis.binding BindingException BindingException.

Prototype

public BindingException(Throwable cause) 

Source Link

Usage

From source file:com.baomidou.mybatisplus.MybatisMapperAnnotationBuilder.java

License:Apache License

private SqlSource getSqlSourceFromAnnotations(Method method, Class<?> parameterType,
        LanguageDriver languageDriver) {
    try {//from  w  w  w . ja v a2  s  .c om
        Class<? extends Annotation> sqlAnnotationType = getSqlAnnotationType(method);
        Class<? extends Annotation> sqlProviderAnnotationType = getSqlProviderAnnotationType(method);
        if (sqlAnnotationType != null) {
            if (sqlProviderAnnotationType != null) {
                throw new BindingException(
                        "You cannot supply both a static SQL and SqlProvider to method named "
                                + method.getName());
            }
            Annotation sqlAnnotation = method.getAnnotation(sqlAnnotationType);
            final String[] strings = (String[]) sqlAnnotation.getClass().getMethod("value")
                    .invoke(sqlAnnotation);
            return buildSqlSourceFromStrings(strings, parameterType, languageDriver);
        } else if (sqlProviderAnnotationType != null) {
            Annotation sqlProviderAnnotation = method.getAnnotation(sqlProviderAnnotationType);
            return new ProviderSqlSource(assistant.getConfiguration(), sqlProviderAnnotation);
        }
        return null;
    } catch (Exception e) {
        throw new BuilderException("Could not find value method on SQL annotation.  Cause: " + e, e);
    }
}

From source file:com.baomidou.mybatisplus.MybatisMapperRegistry.java

License:Apache License

@SuppressWarnings("unchecked")
public <T> T getMapper(Class<T> type, SqlSession sqlSession) {
    final MapperProxyFactory<T> mapperProxyFactory = (MapperProxyFactory<T>) knownMappers.get(type);
    if (mapperProxyFactory == null) {
        throw new BindingException("Type " + type + " is not known to the MybatisPlusMapperRegistry.");
    }/*  www . ja  v a  2  s  . c  o  m*/
    try {
        return mapperProxyFactory.newInstance(sqlSession);
    } catch (Exception e) {
        throw new BindingException("Error getting mapper instance. Cause: " + e, e);
    }
}

From source file:com.chrhc.mybatis.locker.interceptor.OptimisticLocker.java

License:Apache License

@Override
public Object intercept(Invocation invocation) throws Exception {
    String versionColumn;/*from  w  ww  .j av a 2 s  .  co  m*/
    String versionField;
    if (null == props || props.isEmpty()) {
        versionColumn = "version";
        versionField = "version";
    } else {
        versionColumn = props.getProperty("versionColumn", "version");
        versionField = props.getProperty("versionField", "version");
    }
    String interceptMethod = invocation.getMethod().getName();
    if (!"prepare".equals(interceptMethod)) {
        return invocation.proceed();
    }
    StatementHandler handler = (StatementHandler) PluginUtil.processTarget(invocation.getTarget());
    MetaObject metaObject = SystemMetaObject.forObject(handler);
    MappedStatement ms = (MappedStatement) metaObject.getValue("delegate.mappedStatement");
    SqlCommandType sqlCmdType = ms.getSqlCommandType();
    if (sqlCmdType != SqlCommandType.UPDATE) {
        return invocation.proceed();
    }
    BoundSql boundSql = (BoundSql) metaObject.getValue("delegate.boundSql");
    VersionLocker vl = getVersionLocker(ms, boundSql);
    if (null != vl && !vl.value()) {
        return invocation.proceed();
    }
    Object originalVersion = metaObject.getValue("delegate.boundSql.parameterObject." + versionField);
    if (originalVersion == null || Long.parseLong(originalVersion.toString()) <= 0) {
        throw new BindingException("value of version field[" + versionField + "]can not be empty");
    }
    String originalSql = boundSql.getSql();
    if (log.isDebugEnabled()) {
        log.debug("==> originalSql: " + originalSql);
    }
    originalSql = addVersionToSql(originalSql, versionColumn, originalVersion);
    metaObject.setValue("delegate.boundSql.sql", originalSql);
    if (log.isDebugEnabled()) {
        log.debug("==> originalSql after add version: " + originalSql);
    }
    return invocation.proceed();
}

From source file:com.eryansky.common.orm.mybatis.proxy.PaginationMapperMethod.java

License:Apache License

/**
 * ?// w w w.  ja  v a  2  s.c om
 *
 * @param args ??
 * @return 
 */
@SuppressWarnings("unchecked")
public Object execute(Object[] args) {
    final Object param = getParam(args);
    Page<Object> page;
    RowBounds rowBounds;
    if (paginationIndex != null) {
        page = (Page<Object>) args[paginationIndex];
        rowBounds = new RowBounds(page.getFirstResult(), page.getMaxResults());
    } else if (rowBoundsIndex != null) {
        rowBounds = (RowBounds) args[rowBoundsIndex];
        page = new Page<Object>();
    } else {
        throw new BindingException(
                "Invalid bound statement (not found rowBounds or pagination in paramenters)");
    }
    page.setTotalCount(executeForCount(param));
    page.setResult(executeForList(param, rowBounds));
    return page;
}

From source file:com.eryansky.common.orm.mybatis.proxy.PaginationMapperMethod.java

License:Apache License

/**
 * ???//from  w w w .  ja va 2  s .com
 */
private void setupCommandType() {
    MappedStatement ms = config.getMappedStatement(commandName);
    type = ms.getSqlCommandType();
    if (type != SqlCommandType.SELECT) {
        throw new BindingException("Unsupport execution method for: " + commandName);
    }
}

From source file:com.eryansky.common.orm.mybatis.proxy.PaginationMapperMethod.java

License:Apache License

/**
 * ?Statement/*from ww  w  .  j  av a 2 s  . c  o  m*/
 */
private void validateStatement() {
    if (!config.hasStatement(commandName)) {
        throw new BindingException("Invalid bound statement (not found): " + commandName);
    }
    if (!config.hasStatement(commandCountName)) {
        throw new BindingException("Invalid bound statement (not found): " + commandCountName);
    }
}

From source file:com.eryansky.common.orm.mybatis.proxy.PaginationMapperProxy.java

License:Apache License

@Override
public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
    if (isObjectMethod(method)) {
        return null;
    }//www  . jav a 2s.c om
    final Class<?> declaringInterface = findDeclaringInterface(proxy, method);
    if (Page.class.isAssignableFrom(method.getReturnType())) {
        // ?
        return new PaginationMapperMethod(declaringInterface, method, sqlSession).execute(args);
    }
    // ??
    final MapperMethod mapperMethod = new MapperMethod(declaringInterface, method,
            sqlSession.getConfiguration());
    final Object result = mapperMethod.execute(sqlSession, args);
    if (result == null && method.getReturnType().isPrimitive()) {
        throw new BindingException("Mapper method '" + method.getName() + "' (" + method.getDeclaringClass()
                + ") attempted to return null from a method with a primitive return type ("
                + method.getReturnType() + ").");
    }
    return result;
}

From source file:com.eryansky.common.orm.mybatis.proxy.PaginationMapperProxy.java

License:Apache License

private Class<?> findDeclaringInterface(Object proxy, Method method) {
    Class<?> declaringInterface = null;
    for (Class<?> mapperFaces : proxy.getClass().getInterfaces()) {
        Method m = ReflectionUtils.getAccessibleMethod(mapperFaces, method.getName(),
                method.getParameterTypes());
        if (m != null) {
            declaringInterface = mapperFaces;
        }//w  w w .j a  v  a2 s .  co m
    }
    if (declaringInterface == null) {
        throw new BindingException("Could not find interface with the given method " + method);
    }
    return declaringInterface;
}

From source file:com.eryansky.common.orm.mybatis.proxy.PaginationMapperRegistry.java

License:Apache License

@Override
public <T> T getMapper(Class<T> type, SqlSession sqlSession) {
    if (!hasMapper(type)) {
        throw new BindingException("Type " + type + " is not known to the MapperRegistry.");
    }/*from w ww  .  jav a 2 s .c o m*/
    try {
        return PaginationMapperProxy.newMapperProxy(type, sqlSession);
    } catch (Exception e) {
        throw new BindingException("Error getting mapper instance. Cause: " + e, e);
    }
}

From source file:com.funtl.framework.smoke.core.commons.persistence.proxy.PaginationMapperMethod.java

License:Apache License

/**
 * ?/*from www .  ja  va 2  s . com*/
 *
 * @param args ??
 * @return 
 */
@SuppressWarnings("unchecked")
public Object execute(Object[] args) {
    final Object param = getParam(args);
    Page<Object> page;
    RowBounds rowBounds;
    if (paginationIndex != null) {
        page = (Page<Object>) args[paginationIndex];
        rowBounds = new RowBounds(page.getFirstResult(), page.getMaxResults());
    } else if (rowBoundsIndex != null) {
        rowBounds = (RowBounds) args[rowBoundsIndex];
        page = new Page<Object>();
    } else {
        throw new BindingException(
                "Invalid bound statement (not found rowBounds or pagination in paramenters)");
    }
    page.setCount(executeForCount(param));
    page.setList(executeForList(param, rowBounds));
    return page;
}