org.apache.ibatis.mapping.MappedStatement

Here are the examples of the java api org.apache.ibatis.mapping.MappedStatement taken from open source projects. By voting up you can indicate which examples are most useful and appropriate.

648 Examples 7

19 Source : TriggerValue4SelectKeyGenerator.java
with Apache License 2.0
from zhouxx

/**
 * @author Zhou Xiaoxiang
 * @since 1.0
 */
public clreplaced TriggerValue4SelectKeyGenerator extends SelectKeyGenerator {

    private boolean executeBefore;

    private MappedStatement keyStatement;

    private Parameterreplacedistant parameterreplacedistant = new Parameterreplacedistant();

    public TriggerValue4SelectKeyGenerator(MappedStatement keyStatement, boolean executeBefore) {
        super(keyStatement, executeBefore);
        this.keyStatement = keyStatement;
        this.executeBefore = executeBefore;
    }

    @Override
    public void processBefore(Executor executor, MappedStatement mappedStatement, Statement stmt, Object parameterObject) {
        if (!(mappedStatement.getSqlCommandType() == SqlCommandType.INSERT || mappedStatement.getSqlCommandType() == SqlCommandType.UPDATE)) {
            return;
        }
        Collection<Object> parameters = parameterreplacedistant.getParameters(parameterObject);
        // trigger auto set value
        if (parameters != null) {
            for (Object parameter : parameters) {
                EnreplacedyMetaData enreplacedyMetaData = EnreplacedyMetaDataRegistry.getInstance().get(parameter.getClreplaced());
                parameterreplacedistant.populateKeyAndTriggerValue(mappedStatement, parameter, enreplacedyMetaData);
            }
        } else {
            EnreplacedyMetaData enreplacedyMetaData = EnreplacedyMetaDataRegistry.getInstance().get(parameterObject.getClreplaced());
            parameterreplacedistant.populateKeyAndTriggerValue(mappedStatement, parameterObject, enreplacedyMetaData);
        }
        // id select and set
        if (mappedStatement.getSqlCommandType() == SqlCommandType.INSERT) {
            if (executeBefore) {
                if (parameters != null) {
                    for (Object parameter : parameters) {
                        processGeneratedKeys(executor, mappedStatement, parameter);
                    }
                } else {
                    processGeneratedKeys(executor, mappedStatement, parameterObject);
                }
            }
        }
    }

    private void processGeneratedKeys(Executor executor, MappedStatement ms, Object parameter) {
        try {
            if (parameter != null && keyStatement != null && keyStatement.getKeyProperties() != null) {
                String[] keyProperties = keyStatement.getKeyProperties();
                final Configuration configuration = ms.getConfiguration();
                final MetaObject metaParam = configuration.newMetaObject(parameter);
                if (keyProperties != null) {
                    // Do not close keyExecutor.
                    // The transaction will be closed by parent executor.
                    Executor keyExecutor = configuration.newExecutor(executor.getTransaction(), ExecutorType.SIMPLE);
                    List<Object> values = keyExecutor.query(keyStatement, parameter, RowBounds.DEFAULT, Executor.NO_RESULT_HANDLER);
                    if (values.size() == 0) {
                        throw new ExecutorException("SelectKey returned no data.");
                    } else if (values.size() > 1) {
                        throw new ExecutorException("SelectKey returned more than one value.");
                    } else {
                        MetaObject metaResult = configuration.newMetaObject(values.get(0));
                        if (keyProperties.length == 1) {
                            if (metaResult.hasGetter(keyProperties[0])) {
                                setValue(metaParam, keyProperties[0], metaResult.getValue(keyProperties[0]));
                            } else {
                                // no getter for the property - maybe just a single value object
                                // so try that
                                setValue(metaParam, keyProperties[0], values.get(0));
                            }
                        } else {
                            handleMultipleProperties(keyProperties, metaParam, metaResult);
                        }
                    }
                }
            }
        } catch (ExecutorException e) {
            throw e;
        } catch (Exception e) {
            throw new ExecutorException("Error selecting key or setting result to parameter object. Cause: " + e, e);
        }
    }

    private void handleMultipleProperties(String[] keyProperties, MetaObject metaParam, MetaObject metaResult) {
        String[] keyColumns = keyStatement.getKeyColumns();
        if (keyColumns == null || keyColumns.length == 0) {
            // no key columns specified, just use the property names
            for (String keyProperty : keyProperties) {
                setValue(metaParam, keyProperty, metaResult.getValue(keyProperty));
            }
        } else {
            if (keyColumns.length != keyProperties.length) {
                throw new ExecutorException("If SelectKey has key columns, the number must match the number of key properties.");
            }
            for (int i = 0; i < keyProperties.length; i++) {
                setValue(metaParam, keyProperties[i], metaResult.getValue(keyColumns[i]));
            }
        }
    }

    private void setValue(MetaObject metaParam, String property, Object value) {
        if (metaParam.hreplacedetter(property)) {
            metaParam.setValue(property, value);
        } else {
            throw new ExecutorException("No setter found for the keyProperty '" + property + "' in " + metaParam.getOriginalObject().getClreplaced().getName() + ".");
        }
    }
}

19 Source : PermissionUtils.java
with Apache License 2.0
from zhaowb82

/**
 * 根据 StatementHandler 获取 注解对象
 *
 * @author GaoYuan
 * @date 2018/4/17 上午11:45
 */
public static PermissionAop getPermissionByDelegate(MappedStatement mappedStatement) {
    PermissionAop permissionAop = null;
    try {
        String id = mappedStatement.getId();
        String clreplacedName = id.substring(0, id.lastIndexOf("."));
        String methodName = id.substring(id.lastIndexOf(".") + 1, id.length());
        final Clreplaced cls = Clreplaced.forName(clreplacedName);
        final Method[] method = cls.getMethods();
        for (Method me : method) {
            if (me.getName().equals(methodName) && me.isAnnotationPresent(PermissionAop.clreplaced)) {
                permissionAop = me.getAnnotation(PermissionAop.clreplaced);
            }
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
    return permissionAop;
}

19 Source : ListParameterEnhancement.java
with MIT License
from zhang-rf

private boolean filter(MappedStatement mappedStatement) {
    return !(mappedStatement.getSqlSource() instanceof DynamicSqlSource) || filterCache.computeIfAbsent(mappedStatement.getId(), k -> filter(Collections.singletonList((SqlNode) MyBatisUtils.getMetaObject(mappedStatement.getSqlSource()).getValue("rootSqlNode"))));
}

19 Source : MetaObjectAssistant.java
with Apache License 2.0
from yuboon

public static MappedStatement getMappedStatement(MetaObject metaObject) {
    MappedStatement mappedStatement = (MappedStatement) metaObject.getValue("delegate.mappedStatement");
    return mappedStatement;
}

19 Source : HaloInterceptor.java
with MIT License
from yizzuide

private void invokeWithTable(String tableName, String matchTableName, String sql, MappedStatement mappedStatement, Object param, Object result, HaloType type) {
    if (!HaloContext.getTableNameMap().containsKey(matchTableName)) {
        return;
    }
    Map<String, List<HandlerMetaData>> tableNameMap = (type == HaloType.PRE) ? HaloContext.getPreTableNameMap() : HaloContext.getPostTableNameMap();
    List<HandlerMetaData> metaDataList = tableNameMap.get(matchTableName);
    if (CollectionUtils.isEmpty(metaDataList)) {
        return;
    }
    metaDataList.forEach(handlerMetaData -> invokeHandler(tableName, handlerMetaData, sql, mappedStatement, param, result));
}

19 Source : MybatisInterceptor.java
with MIT License
from Yirendai

public Object intercept(final Invocation invocation) throws Throwable {
    final MappedStatement mappedStatement = (MappedStatement) invocation.getArgs()[0];
    Object returnValue = null;
    final long start = System.currentTimeMillis();
    returnValue = invocation.proceed();
    final long end = System.currentTimeMillis();
    final String sqlId = mappedStatement.getId();
    final int lastIndex = sqlId.lastIndexOf('.');
    final String clreplacedName = sqlId.substring(0, lastIndex);
    final String methodName = sqlId.substring(lastIndex + 1);
    Tracer.getInstance().addBinaryAnnotation(clreplacedName, methodName, (int) (end - start));
    return returnValue;
}

19 Source : DynamicQueryProvider.java
with Apache License 2.0
from wz2cool

public String updateSelectiveByDynamicQuery(MappedStatement ms) {
    return updateByDynamicQuery(ms, true);
}

19 Source : DynamicQueryProvider.java
with Apache License 2.0
from wz2cool

public String selectRowBoundsByDynamicQuery(MappedStatement ms) {
    return selectByDynamicQuery(ms);
}

19 Source : DynamicQueryProvider.java
with Apache License 2.0
from wz2cool

public String updateByDynamicQuery(MappedStatement ms) {
    return updateByDynamicQuery(ms, false);
}

19 Source : OptionalSelectProvider.java
with Apache License 2.0
from open-hand

/**
 * 指定列查询
 *
 * @param ms 参数
 */
public void selectOptional(MappedStatement ms) {
    Clreplaced<?> enreplacedyClreplaced = getEnreplacedyClreplaced(ms);
    setResultType(ms, enreplacedyClreplaced);
}

19 Source : ConditionProvider.java
with Apache License 2.0
from open-hand

/**
 * 根据Condition查询
 *
 * @param ms
 * @return
 */
public String selectByConditionAndRowBounds(MappedStatement ms) {
    return selectByCondition(ms);
}

19 Source : SelectKeyGenerator.java
with Apache License 2.0
from open-hand

/**
 * SelectKeyGenerator
 *
 * @author Clinton Begin
 * @author Jeff Butler
 */
public clreplaced SelectKeyGenerator implements KeyGenerator {

    public static final String SELECT_KEY_SUFFIX = "!selectKey";

    private boolean executeBefore;

    private MappedStatement keyStatement;

    public SelectKeyGenerator(MappedStatement keyStatement, boolean executeBefore) {
        this.executeBefore = executeBefore;
        this.keyStatement = keyStatement;
    }

    @Override
    public void processBefore(Executor executor, MappedStatement ms, Statement stmt, Object parameter) {
        if (executeBefore) {
            processGeneratedKeys(executor, ms, parameter);
        }
    }

    @Override
    public void processAfter(Executor executor, MappedStatement ms, Statement stmt, Object parameter) {
        if (!executeBefore) {
            processGeneratedKeys(executor, ms, parameter);
        }
    }

    private void processGeneratedKeys(Executor executor, MappedStatement ms, Object parameter) {
        try {
            if (parameter != null && keyStatement != null && keyStatement.getKeyProperties() != null) {
                String[] keyProperties = keyStatement.getKeyProperties();
                final Configuration configuration = ms.getConfiguration();
                final MetaObject metaParam = configuration.newMetaObject(parameter);
                if (existsKeyValues(metaParam, keyProperties, parameter)) {
                    return;
                }
                if (keyProperties != null) {
                    // Do not close keyExecutor.
                    // The transaction will be closed by parent executor.
                    Executor keyExecutor = configuration.newExecutor(executor.getTransaction(), ExecutorType.SIMPLE);
                    List<Object> values = keyExecutor.query(keyStatement, parameter, RowBounds.DEFAULT, Executor.NO_RESULT_HANDLER);
                    if (values.size() == 0) {
                        throw new ExecutorException("SelectKey returned no data.");
                    } else if (values.size() > 1) {
                        throw new ExecutorException("SelectKey returned more than one value.");
                    } else {
                        MetaObject metaResult = configuration.newMetaObject(values.get(0));
                        if (keyProperties.length == 1) {
                            if (metaResult.hasGetter(keyProperties[0])) {
                                setValue(metaParam, keyProperties[0], metaResult.getValue(keyProperties[0]));
                            } else {
                                // no getter for the property - maybe just a single value object
                                // so try that
                                setValue(metaParam, keyProperties[0], values.get(0));
                            }
                        } else {
                            handleMultipleProperties(keyProperties, metaParam, metaResult);
                        }
                    }
                }
            }
        } catch (ExecutorException e) {
            throw e;
        } catch (Exception e) {
            throw new ExecutorException("Error selecting key or setting result to parameter object. Cause: " + e, e);
        }
    }

    private boolean existsKeyValues(MetaObject metaParam, String[] keyProperties, Object parameter) {
        if (keyProperties == null || keyProperties.length == 0) {
            return true;
        }
        for (String property : keyProperties) {
            if (metaParam.hasGetter(property)) {
                Object defaultValue = metaParam.getValue(property);
                if (defaultValue == null) {
                    return false;
                }
            }
        }
        return true;
    }

    private void handleMultipleProperties(String[] keyProperties, MetaObject metaParam, MetaObject metaResult) {
        String[] keyColumns = keyStatement.getKeyColumns();
        if (keyColumns == null || keyColumns.length == 0) {
            // no key columns specified, just use the property names
            for (String keyProperty : keyProperties) {
                setValue(metaParam, keyProperty, metaResult.getValue(keyProperty));
            }
        } else {
            if (keyColumns.length != keyProperties.length) {
                throw new ExecutorException("If SelectKey has key columns, the number must match the number of key properties.");
            }
            for (int i = 0; i < keyProperties.length; i++) {
                setValue(metaParam, keyProperties[i], metaResult.getValue(keyColumns[i]));
            }
        }
    }

    private void setValue(MetaObject metaParam, String property, Object value) {
        if (metaParam.hreplacedetter(property)) {
            if (metaParam.hasGetter(property)) {
                Object defaultValue = metaParam.getValue(property);
                if (defaultValue != null) {
                    return;
                }
            }
            metaParam.setValue(property, value);
        } else {
            throw new ExecutorException("No setter found for the keyProperty '" + property + "' in " + metaParam.getOriginalObject().getClreplaced().getName() + ".");
        }
    }
}

19 Source : MapperHelper.java
with Apache License 2.0
from open-hand

/**
 * 配置指定的接口
 *
 * @param configuration   configuration
 * @param mapperInterface mapperInterface
 */
public void processConfiguration(Configuration configuration, Clreplaced<?> mapperInterface) {
    String prefix;
    if (mapperInterface != null) {
        prefix = mapperInterface.getCanonicalName();
    } else {
        prefix = "";
    }
    new ArrayList<Object>(configuration.getMappedStatements()).forEach(object -> {
        if (object instanceof MappedStatement) {
            MappedStatement ms = (MappedStatement) object;
            if (ms.getId().startsWith(prefix) && isMapperMethod(ms.getId()) && ms.getSqlSource() instanceof ProviderSqlSource) {
                setSqlSource(ms);
            }
        }
    });
}

19 Source : CryptInterceptor.java
with MIT License
from miaoxinwei

@Override
public Object intercept(Invocation invocation) throws Throwable {
    Object[] args = invocation.getArgs();
    // 入参
    Object parameter = args[1];
    MappedStatement statement = (MappedStatement) args[0];
    // 判断是否需要解析
    if (!isNotCrypt(parameter)) {
        // 单参数 string
        if (parameter instanceof String) {
            args[1] = stringEncrypt((String) parameter, getParameterAnnotations(statement));
        // 单参数 list
        } else if (parameter instanceof DefaultSqlSession.StrictMap) {
            DefaultSqlSession.StrictMap<Object> strictMap = (DefaultSqlSession.StrictMap<Object>) parameter;
            for (Map.Entry<String, Object> entry : strictMap.entrySet()) {
                if (entry.getKey().contains(PARAM_TYPE_COLLECTION)) {
                    continue;
                }
                if (entry.getKey().contains(PARAM_TYPE_LIST)) {
                    Set<String> set = getParameterAnnotations(statement);
                    listEncrypt((List) entry.getValue(), !set.isEmpty());
                }
            }
        // 多参数
        } else if (parameter instanceof MapperMethod.ParamMap) {
            MapperMethod.ParamMap<Object> paramMap = (MapperMethod.ParamMap<Object>) parameter;
            Set<String> set = getParameterAnnotations(statement);
            boolean setEmpty = set.isEmpty();
            // 解析每一个参数
            for (Map.Entry<String, Object> entry : paramMap.entrySet()) {
                // 判断不需要解析的类型 不解析map
                if (isNotCrypt(entry.getValue()) || entry.getValue() instanceof Map || entry.getKey().contains(PARAM)) {
                    continue;
                }
                // 如果string
                if (entry.getValue() instanceof String) {
                    entry.setValue(stringEncrypt(entry.getKey(), (String) entry.getValue(), set));
                    continue;
                }
                boolean isSetValue = !setEmpty && set.contains(entry.getKey());
                // 如果 list
                if (entry.getValue() instanceof List) {
                    listEncrypt((List) entry.getValue(), isSetValue);
                    continue;
                }
                beanEncrypt(entry.getValue());
            }
        // bean
        } else {
            beanEncrypt(parameter);
        }
    }
    // 获得出参
    Object returnValue = invocation.proceed();
    // 出参解密
    if (isNotCrypt(returnValue)) {
        return returnValue;
    }
    Boolean bo = getMethodAnnotations(statement);
    if (returnValue instanceof String && bo) {
        return stringDecrypt((String) returnValue);
    }
    if (returnValue instanceof List) {
        listDecrypt((List) returnValue, bo);
        return returnValue;
    }
    return returnValue;
}

19 Source : PageListHelper.java
with Apache License 2.0
from lightbatis

@Override
public boolean skip(MappedStatement ms, Object parameterObject, RowBounds rowBounds) {
    return super.skip(ms, parameterObject, rowBounds);
}

19 Source : MapperUtils.java
with Apache License 2.0
from lightbatis

/**
 * 获取执行的方法名
 *
 * @param ms
 * @return
 */
public static String getMethodName(MappedStatement ms) {
    return getMethodName(ms.getId());
}

19 Source : BaseMapperProvider.java
with Apache License 2.0
from lightbatis

/**
 * 通过主键更新全部字段
 *
 * @param ms
 */
public String updateByPrimaryKey(MappedStatement ms) throws IOException {
    Clreplaced<?> enreplacedyClreplaced = getEnreplacedyClreplaced(ms);
    return updateEnreplacedyByPrimaryKey(enreplacedyClreplaced);
}

19 Source : PageListInterceptor.java
with Apache License 2.0
from lightbatis

/**
 * 基于数据的附加操作,多表的操作
 */
private void enreplacedyPlus(Object result, EnreplacedyMeta enreplacedyMeta, Connection conn, MappedStatement ms) throws Exception {
    // 检查需要处理哪些附表
    HashMap<String, SecondTableMeta> tables = enreplacedyMeta.getSecondTables();
    Iterator<SecondTableMeta> secondIterator = tables.values().iterator();
    for (; secondIterator.hasNext(); ) {
        SecondTableMeta tableMeta = secondIterator.next();
        // 如果是普通类型,一次性加载数据,并且添加到属性上去
        // 处理一对一的关系的数据
        if (!tableMeta.getPrimitiveColumns().isEmpty()) {
            loadPrimitiveData(conn, result, enreplacedyMeta, tableMeta, ms);
        } else {
            // 如果是 List 类型的数据,处理一对多的关系的数据
            loadListData(conn, result, enreplacedyMeta, tableMeta, ms);
        }
    }
}

19 Source : SplitTableHandler.java
with Apache License 2.0
from justice-code

public boolean needSplit(MappedStatement mappedStatement) {
    return false;
}

19 Source : SelectKeyGenerator.java
with Apache License 2.0
from huifer

/**
 * @author Clinton Begin
 * @author Jeff Butler
 */
public clreplaced SelectKeyGenerator implements KeyGenerator {

    public static final String SELECT_KEY_SUFFIX = "!selectKey";

    private final boolean executeBefore;

    private final MappedStatement keyStatement;

    public SelectKeyGenerator(MappedStatement keyStatement, boolean executeBefore) {
        this.executeBefore = executeBefore;
        this.keyStatement = keyStatement;
    }

    @Override
    public void processBefore(Executor executor, MappedStatement ms, Statement stmt, Object parameter) {
        if (executeBefore) {
            processGeneratedKeys(executor, ms, parameter);
        }
    }

    @Override
    public void processAfter(Executor executor, MappedStatement ms, Statement stmt, Object parameter) {
        if (!executeBefore) {
            processGeneratedKeys(executor, ms, parameter);
        }
    }

    private void processGeneratedKeys(Executor executor, MappedStatement ms, Object parameter) {
        try {
            if (parameter != null && keyStatement != null && keyStatement.getKeyProperties() != null) {
                String[] keyProperties = keyStatement.getKeyProperties();
                final Configuration configuration = ms.getConfiguration();
                final MetaObject metaParam = configuration.newMetaObject(parameter);
                // Do not close keyExecutor.
                // The transaction will be closed by parent executor.
                Executor keyExecutor = configuration.newExecutor(executor.getTransaction(), ExecutorType.SIMPLE);
                List<Object> values = keyExecutor.query(keyStatement, parameter, RowBounds.DEFAULT, Executor.NO_RESULT_HANDLER);
                if (values.size() == 0) {
                    throw new ExecutorException("SelectKey returned no data.");
                } else if (values.size() > 1) {
                    throw new ExecutorException("SelectKey returned more than one value.");
                } else {
                    MetaObject metaResult = configuration.newMetaObject(values.get(0));
                    if (keyProperties.length == 1) {
                        if (metaResult.hasGetter(keyProperties[0])) {
                            setValue(metaParam, keyProperties[0], metaResult.getValue(keyProperties[0]));
                        } else {
                            // no getter for the property - maybe just a single value object
                            // so try that
                            setValue(metaParam, keyProperties[0], values.get(0));
                        }
                    } else {
                        handleMultipleProperties(keyProperties, metaParam, metaResult);
                    }
                }
            }
        } catch (ExecutorException e) {
            throw e;
        } catch (Exception e) {
            throw new ExecutorException("Error selecting key or setting result to parameter object. Cause: " + e, e);
        }
    }

    private void handleMultipleProperties(String[] keyProperties, MetaObject metaParam, MetaObject metaResult) {
        String[] keyColumns = keyStatement.getKeyColumns();
        if (keyColumns == null || keyColumns.length == 0) {
            // no key columns specified, just use the property names
            for (String keyProperty : keyProperties) {
                setValue(metaParam, keyProperty, metaResult.getValue(keyProperty));
            }
        } else {
            if (keyColumns.length != keyProperties.length) {
                throw new ExecutorException("If SelectKey has key columns, the number must match the number of key properties.");
            }
            for (int i = 0; i < keyProperties.length; i++) {
                setValue(metaParam, keyProperties[i], metaResult.getValue(keyColumns[i]));
            }
        }
    }

    private void setValue(MetaObject metaParam, String property, Object value) {
        if (metaParam.hreplacedetter(property)) {
            metaParam.setValue(property, value);
        } else {
            throw new ExecutorException("No setter found for the keyProperty '" + property + "' in " + metaParam.getOriginalObject().getClreplaced().getName() + ".");
        }
    }
}

19 Source : DialectDynamicFactory.java
with Apache License 2.0
from hengboy

/**
 * 动态获取方言实例
 *
 * @param dialect   方言实现类
 * @param statement mappedStatement对象
 * @return 获取数据库方言
 */
public static Dialect newInstance(MappedStatement statement, String dialect) {
    try {
        // 如果没有传递枚举参数
        // 则自动根据数据库
        if (dialect == null) {
            return newAutoInstance(statement);
        }
        // 反射获取方言实现实例
        return (Dialect) Clreplaced.forName(dialect).newInstance();
    }// 遇到异常后抛出方言暂未支持异常
     catch (Exception e) {
        throw new PageableException(ErrorMsgEnum.DIALECT_NOT_FOUND);
    }
}

19 Source : OrmUpdateDslProvider.java
with MIT License
from hengboy

/**
 * 根据指定的更新sql,重载SqlSource
 *
 * @param statement MappedStatement对象
 */
public void updateBySql(MappedStatement statement) {
    reloadSqlSource(statement, "${sql}");
}

19 Source : OrmSelectDslProvider.java
with MIT License
from hengboy

/**
 * 根据指定的查询sql装载sqlSource
 *
 * @param statement MappedStatement对象实例
 */
public void selectBySql(MappedStatement statement) {
    reloadSqlSource(statement, "${sql}");
}

19 Source : OrmDeleteDslProvider.java
with MIT License
from hengboy

/**
 * 根据传递的sql重载sqlSource
 *
 * @param statement MappedStatement对象
 */
public void deleteBySql(MappedStatement statement) {
    // 重新装载sql
    reloadSqlSource(statement, "${sql}");
}

19 Source : BaseProvider.java
with MIT License
from hengboy

/**
 * 执行NamedProvider内的方法
 * 实现重载SqlSource
 *
 * @param ms MappedStatement对象实例
 */
public void invokeNamedProviderMethod(MappedStatement ms) {
    invokeProviderMethod(NAMED_PROVIDER_METHOD_NAME, ms);
}

19 Source : SqlServerProvider.java
with MIT License
from godlike110

/**
 * 插入不为null的字段
 *
 * @param ms
 * @return
 */
public String insertSelective(MappedStatement ms) {
    Clreplaced<?> enreplacedyClreplaced = getEnreplacedyClreplaced(ms);
    StringBuilder sql = new StringBuilder();
    sql.append(SqlHelper.insertIntoTable(enreplacedyClreplaced, tableName(enreplacedyClreplaced)));
    sql.append(SqlHelper.insertColumns(enreplacedyClreplaced, true, true, isNotEmpty()));
    sql.append(SqlHelper.insertValuesColumns(enreplacedyClreplaced, true, true, isNotEmpty()));
    return sql.toString();
}

19 Source : SqlServerProvider.java
with MIT License
from godlike110

/**
 * 插入
 *
 * @param ms
 */
public String insert(MappedStatement ms) {
    final Clreplaced<?> enreplacedyClreplaced = getEnreplacedyClreplaced(ms);
    // 开始拼sql
    StringBuilder sql = new StringBuilder();
    sql.append(SqlHelper.insertIntoTable(enreplacedyClreplaced, tableName(enreplacedyClreplaced)));
    sql.append(SqlHelper.insertColumns(enreplacedyClreplaced, true, false, false));
    sql.append(SqlHelper.insertValuesColumns(enreplacedyClreplaced, true, false, false));
    return sql.toString();
}

19 Source : ExampleProvider.java
with MIT License
from godlike110

/**
 * 根据Example查询
 *
 * @param ms
 * @return
 */
public String selectByExampleAndRowBounds(MappedStatement ms) {
    return selectByExample(ms);
}

19 Source : ConditionProvider.java
with MIT License
from godlike110

/**
 * 根据Example更新非null字段
 *
 * @param ms
 * @return
 */
public String updateByConditionSelective(MappedStatement ms) {
    return exampleProvider.updateByExampleSelective(ms);
}

19 Source : ConditionProvider.java
with MIT License
from godlike110

/**
 * 根据Condition更新
 *
 * @param ms
 * @return
 */
public String updateByCondition(MappedStatement ms) {
    return exampleProvider.updateByExample(ms);
}

19 Source : ConditionProvider.java
with MIT License
from godlike110

/**
 * 根据Condition查询
 *
 * @param ms
 * @return
 */
public String selectByConditionAndRowBounds(MappedStatement ms) {
    return exampleProvider.selectByExample(ms);
}

19 Source : ConditionProvider.java
with MIT License
from godlike110

/**
 * 根据Condition查询总数
 *
 * @param ms
 * @return
 */
public String selectCountByCondition(MappedStatement ms) {
    return exampleProvider.selectCountByExample(ms);
}

19 Source : ConditionProvider.java
with MIT License
from godlike110

/**
 * 根据Condition查询
 *
 * @param ms
 * @return
 */
public String selectByCondition(MappedStatement ms) {
    return exampleProvider.selectByExample(ms);
}

19 Source : ConditionProvider.java
with MIT License
from godlike110

/**
 * 根据Condition删除
 *
 * @param ms
 * @return
 */
public String deleteByCondition(MappedStatement ms) {
    return exampleProvider.deleteByExample(ms);
}

19 Source : BaseSelectProvider.java
with MIT License
from godlike110

/**
 * 查询
 *
 * @param ms
 * @return
 */
public String selectByRowBounds(MappedStatement ms) {
    return select(ms);
}

19 Source : SelectKeyGenerator.java
with MIT License
from godlike110

/**
 * @author Clinton Begin
 * @author Jeff Butler
 */
public clreplaced SelectKeyGenerator implements KeyGenerator {

    public static final String SELECT_KEY_SUFFIX = "!selectKey";

    private boolean executeBefore;

    private MappedStatement keyStatement;

    public SelectKeyGenerator(MappedStatement keyStatement, boolean executeBefore) {
        this.executeBefore = executeBefore;
        this.keyStatement = keyStatement;
    }

    @Override
    public void processBefore(Executor executor, MappedStatement ms, Statement stmt, Object parameter) {
        if (executeBefore) {
            processGeneratedKeys(executor, ms, parameter);
        }
    }

    @Override
    public void processAfter(Executor executor, MappedStatement ms, Statement stmt, Object parameter) {
        if (!executeBefore) {
            processGeneratedKeys(executor, ms, parameter);
        }
    }

    private void processGeneratedKeys(Executor executor, MappedStatement ms, Object parameter) {
        try {
            if (parameter != null && keyStatement != null && keyStatement.getKeyProperties() != null) {
                String[] keyProperties = keyStatement.getKeyProperties();
                final Configuration configuration = ms.getConfiguration();
                final MetaObject metaParam = configuration.newMetaObject(parameter);
                if (keyProperties != null) {
                    // Do not close keyExecutor.
                    // The transaction will be closed by parent executor.
                    Executor keyExecutor = configuration.newExecutor(executor.getTransaction(), ExecutorType.SIMPLE);
                    List<Object> values = keyExecutor.query(keyStatement, parameter, RowBounds.DEFAULT, Executor.NO_RESULT_HANDLER);
                    if (values.size() == 0) {
                        throw new ExecutorException("SelectKey returned no data.");
                    } else if (values.size() > 1) {
                        throw new ExecutorException("SelectKey returned more than one value.");
                    } else {
                        MetaObject metaResult = configuration.newMetaObject(values.get(0));
                        if (keyProperties.length == 1) {
                            if (metaResult.hasGetter(keyProperties[0])) {
                                setValue(metaParam, keyProperties[0], metaResult.getValue(keyProperties[0]));
                            } else {
                                // no getter for the property - maybe just a single value object
                                // so try that
                                setValue(metaParam, keyProperties[0], values.get(0));
                            }
                        } else {
                            handleMultipleProperties(keyProperties, metaParam, metaResult);
                        }
                    }
                }
            }
        } catch (ExecutorException e) {
            throw e;
        } catch (Exception e) {
            throw new ExecutorException("Error selecting key or setting result to parameter object. Cause: " + e, e);
        }
    }

    private void handleMultipleProperties(String[] keyProperties, MetaObject metaParam, MetaObject metaResult) {
        String[] keyColumns = keyStatement.getKeyColumns();
        if (keyColumns == null || keyColumns.length == 0) {
            // no key columns specified, just use the property names
            for (String keyProperty : keyProperties) {
                setValue(metaParam, keyProperty, metaResult.getValue(keyProperty));
            }
        } else {
            if (keyColumns.length != keyProperties.length) {
                throw new ExecutorException("If SelectKey has key columns, the number must match the number of key properties.");
            }
            for (int i = 0; i < keyProperties.length; i++) {
                setValue(metaParam, keyProperties[i], metaResult.getValue(keyColumns[i]));
            }
        }
    }

    private void setValue(MetaObject metaParam, String property, Object value) {
        if (metaParam.hreplacedetter(property)) {
            if (metaParam.hasGetter(property)) {
                Object defaultValue = metaParam.getValue(property);
                if (defaultValue != null) {
                    return;
                }
            }
            metaParam.setValue(property, value);
        } else {
            throw new ExecutorException("No setter found for the keyProperty '" + property + "' in " + metaParam.getOriginalObject().getClreplaced().getName() + ".");
        }
    }
}

19 Source : MapperHelper.java
with MIT License
from godlike110

/**
 * 配置指定的接口
 *
 * @param configuration
 * @param mapperInterface
 */
public void processConfiguration(Configuration configuration, Clreplaced<?> mapperInterface) {
    String prefix;
    if (mapperInterface != null) {
        prefix = mapperInterface.getCanonicalName();
    } else {
        prefix = "";
    }
    for (Object object : new ArrayList<Object>(configuration.getMappedStatements())) {
        if (object instanceof MappedStatement) {
            MappedStatement ms = (MappedStatement) object;
            if (ms.getId().startsWith(prefix) && isMapperMethod(ms.getId())) {
                if (ms.getSqlSource() instanceof ProviderSqlSource) {
                    setSqlSource(ms);
                }
            }
        }
    }
}

19 Source : CustomHandlerInterceptor.java
with Apache License 2.0
from Frodez

@Override
public Object intercept(Invocation invocation) throws Throwable {
    Object[] args = invocation.getArgs();
    MappedStatement ms = (MappedStatement) args[0];
    Object parameter = args[1];
    if (args[3] != null) {
        return invocation.proceed();
    }
    // 用自定义handler
    CustomHandler handler = HandlerResolver.resolve(ms, parameter);
    if (handler == null) {
        return invocation.proceed();
    }
    args[3] = handler;
    invocation.proceed();
    return handler.getResult();
}

19 Source : SelectPartialMapperProvider.java
with Apache License 2.0
from Frodez

public String partialOneIn(MappedStatement ms) {
    return partialIn(ms);
}

19 Source : SelectPartialMapperProvider.java
with Apache License 2.0
from Frodez

public String partialOneEqual(MappedStatement ms) {
    return partialEqual(ms);
}

19 Source : InMapperProvider.java
with Apache License 2.0
from Frodez

public String selectOneIn(MappedStatement ms) {
    return selectIn(ms);
}

19 Source : EqualMapperProvider.java
with Apache License 2.0
from Frodez

public String selectOneEqual(MappedStatement ms) {
    return selectEqual(ms);
}

19 Source : PaginationHandler.java
with GNU Lesser General Public License v3.0
from fangjinuo

private boolean isPagingRequest(final MappedStatement statement) {
    return MybatisUtils.isPreparedStatement(statement) && PAGING_CONTEXT.isPagingRequest();
}

19 Source : DefaultConfiguration.java
with Apache License 2.0
from easycodebox

public static void setCurMappedStatement(MappedStatement ms) {
    CUR_MAPPED_STATEMENT.set(ms);
}

19 Source : DefaultConfiguration.java
with Apache License 2.0
from easycodebox

@Override
public MappedStatement getMappedStatement(String id, boolean validateIncompleteStatements) {
    if (validateIncompleteStatements) {
        buildAllStatements();
    }
    MappedStatement ms;
    try {
        ms = mappedStatements.get(id);
    } catch (Exception e) {
        ms = getCurMappedStatement();
        if (ms == null)
            throw new BaseException("没有对应的映射sql", e);
    }
    return ms;
}

19 Source : MSUtils.java
with Apache License 2.0
from chenlijia1111

/**
 * 新建count查询的MappedStatement
 *
 * @param ms
 * @return
 */
public static MappedStatement newCountMappedStatement(MappedStatement ms) {
    return newCountMappedStatement(ms, ms.getId() + COUNT);
}

19 Source : PageAutoDialect.java
with MIT License
from aoju

/**
 * 多数据动态获取时,每次需要初始化
 *
 * @param ms 执行映射的语句
 */
public void initDelegateDialect(MappedStatement ms) {
    if (delegate == null) {
        if (autoDialect) {
            this.delegate = getDialect(ms);
        } else {
            dialectThreadLocal.set(getDialect(ms));
        }
    }
}

19 Source : CountMappedStatement.java
with MIT License
from aoju

/**
 * 新建count查询的MappedStatement
 *
 * @param ms MappedStatement
 * @return mappedStatement
 */
public static MappedStatement newCountMappedStatement(MappedStatement ms) {
    return newCountMappedStatement(ms, ms.getId() + COUNT);
}

19 Source : AbstractSqlDialect.java
with MIT License
from aoju

@Override
public boolean beforeCount(MappedStatement ms, Object parameterObject, org.apache.ibatis.session.RowBounds rowBounds) {
    Page page = getLocalPage();
    return !page.isOrderByOnly() && page.isCount();
}

19 Source : AbstractSqlDialect.java
with MIT License
from aoju

@Override
public boolean beforePage(MappedStatement ms, Object parameterObject, org.apache.ibatis.session.RowBounds rowBounds) {
    Page page = getLocalPage();
    if (page.isOrderByOnly() || page.getPageSize() > 0) {
        return true;
    }
    return false;
}

See More Examples