Search in sources :

Example 16 with ParameterMapping

use of org.apache.ibatis.mapping.ParameterMapping in project mybatis-paginator by HuQingmiao.

the class Dialect method setPageParameter.

protected void setPageParameter(String name, Object value, Class type) {
    ParameterMapping parameterMapping = new ParameterMapping.Builder(mappedStatement.getConfiguration(), name, type).build();
    parameterMappings.add(parameterMapping);
    pageParameters.put(name, value);
}
Also used : ParameterMapping(org.apache.ibatis.mapping.ParameterMapping)

Example 17 with ParameterMapping

use of org.apache.ibatis.mapping.ParameterMapping in project mybatis-paginator by HuQingmiao.

the class DefaultParameterHandler method setParameters.

public void setParameters(PreparedStatement ps) throws SQLException {
    ErrorContext.instance().activity("setting parameters").object(mappedStatement.getParameterMap().getId());
    List<ParameterMapping> parameterMappings = boundSql.getParameterMappings();
    if (parameterMappings != null) {
        MetaObject metaObject = parameterObject == null ? null : configuration.newMetaObject(parameterObject);
        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 {
                    value = metaObject == null ? null : metaObject.getValue(propertyName);
                }
                TypeHandler typeHandler = parameterMapping.getTypeHandler();
                if (typeHandler == null) {
                    throw new ExecutorException("There was no TypeHandler found for parameter " + propertyName + " of statement " + mappedStatement.getId());
                }
                JdbcType jdbcType = parameterMapping.getJdbcType();
                if (value == null && jdbcType == null)
                    jdbcType = configuration.getJdbcTypeForNull();
                typeHandler.setParameter(ps, i + 1, value, jdbcType);
            }
        }
    }
}
Also used : ExecutorException(org.apache.ibatis.executor.ExecutorException) ParameterMapping(org.apache.ibatis.mapping.ParameterMapping) MetaObject(org.apache.ibatis.reflection.MetaObject) JdbcType(org.apache.ibatis.type.JdbcType) MetaObject(org.apache.ibatis.reflection.MetaObject) TypeHandler(org.apache.ibatis.type.TypeHandler)

Aggregations

ParameterMapping (org.apache.ibatis.mapping.ParameterMapping)17 TypeHandlerRegistry (org.apache.ibatis.type.TypeHandlerRegistry)9 StaticSqlSource (org.apache.ibatis.builder.StaticSqlSource)8 MappedStatement (org.apache.ibatis.mapping.MappedStatement)8 ArrayList (java.util.ArrayList)6 MetaObject (org.apache.ibatis.reflection.MetaObject)5 Section (org.apache.ibatis.domain.blog.Section)3 JdbcType (org.apache.ibatis.type.JdbcType)3 TypeHandler (org.apache.ibatis.type.TypeHandler)3 ResultMap (org.apache.ibatis.mapping.ResultMap)2 SQLException (java.sql.SQLException)1 HashMap (java.util.HashMap)1 List (java.util.List)1 Map (java.util.Map)1 CacheKey (org.apache.ibatis.cache.CacheKey)1 Author (org.apache.ibatis.domain.blog.Author)1 ExecutorException (org.apache.ibatis.executor.ExecutorException)1 SelectKeyGenerator (org.apache.ibatis.executor.keygen.SelectKeyGenerator)1 ParameterMap (org.apache.ibatis.mapping.ParameterMap)1 ParameterMode (org.apache.ibatis.mapping.ParameterMode)1