tk.mybatis.mapper.MapperException Java Examples

The following examples show how to use tk.mybatis.mapper.MapperException. 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: OGNL.java    From Mapper with MIT License 6 votes vote down vote up
/**
 * 检查 paremeter 对象中指定的 fields 是否全是 null,如果是则抛出异常
 *
 * @param parameter
 * @return
 */
public static boolean exampleHasAtLeastOneCriteriaCheck(Object parameter) {
    if (parameter != null) {
        try {
            if (parameter instanceof Example) {
                List<Example.Criteria> criteriaList = ((Example) parameter).getOredCriteria();
                if (criteriaList != null && criteriaList.size() > 0) {
                    return true;
                }
            } else {
                Method getter = parameter.getClass().getDeclaredMethod("getOredCriteria");
                Object list = getter.invoke(parameter);
                if(list != null && list instanceof List && ((List) list).size() > 0){
                    return true;
                }
            }
        } catch (Exception e) {
            throw new MapperException(SAFE_DELETE_ERROR, e);
        }
    }
    throw new MapperException(SAFE_DELETE_EXCEPTION);
}
 
Example #2
Source File: FieldHelper.java    From tk-mybatis with MIT License 6 votes vote down vote up
/**
 * 通过方法获取属性
 *
 * @param entityClass
 * @return
 */
public List<EntityField> getProperties(Class<?> entityClass) {
    List<EntityField> entityFields = new ArrayList<EntityField>();
    BeanInfo beanInfo = null;
    try {
        beanInfo = Introspector.getBeanInfo(entityClass);
    } catch (IntrospectionException e) {
        throw new MapperException(e);
    }
    PropertyDescriptor[] descriptors = beanInfo.getPropertyDescriptors();
    for (PropertyDescriptor desc : descriptors) {
        if (!desc.getName().equals("class")) {
            entityFields.add(new EntityField(null, desc));
        }
    }
    return entityFields;
}
 
Example #3
Source File: IdsMapperProvider.java    From BlogManagePlatform with Apache License 2.0 6 votes vote down vote up
/**
 * 批量查询
 * @author Frodez
 * @date 2019-12-25
 */
public String selectByIds(MappedStatement ms) {
	final Class<?> entityClass = getEntityClass(ms);
	//将返回值修改为实体类型
	setResultType(ms, entityClass);
	StringBuilder sql = new StringBuilder();
	sql.append(SqlHelper.selectAllColumns(entityClass));
	sql.append(SqlHelper.fromTable(entityClass, tableName(entityClass)));
	Set<EntityColumn> columnList = EntityHelper.getPKColumns(entityClass);
	if (columnList.size() == 1) {
		EntityColumn column = columnList.iterator().next();
		sql.append(" where ");
		sql.append(column.getColumn());
		sql.append(" in ");
		sql.append("<foreach collection=\"ids\" item=\"item\" index=\"index\" open=\"(\" close=\")\" separator=\",\">");
		sql.append(" #{item} ");
		sql.append("</foreach>");
	} else {
		throw new MapperException("继承 selectByIds 方法的实体类[" + entityClass.getCanonicalName() + "]中必须有且只有一个带有 @Id 注解的字段");
	}
	return sql.toString();
}
 
Example #4
Source File: SelectPartialMapperProvider.java    From BlogManagePlatform with Apache License 2.0 6 votes vote down vote up
public String partialByIds(MappedStatement ms) {
	final Class<?> entityClass = getEntityClass(ms);
	String tableName = tableName(entityClass);
	StringBuilder sql = new StringBuilder();
	sql.append("SELECT ");
	sql.append(tableName).append(".${fieldName} ");
	sql.append(SqlHelper.fromTable(entityClass, tableName));
	Set<EntityColumn> columnList = EntityHelper.getPKColumns(entityClass);
	if (columnList.size() == 1) {
		EntityColumn column = columnList.iterator().next();
		sql.append(" where ");
		sql.append(column.getColumn());
		sql.append(" in ");
		sql.append("<foreach collection=\"ids\" item=\"item\" index=\"index\" open=\"(\" close=\")\" separator=\",\">");
		sql.append(" #{item} ");
		sql.append("</foreach>");
	} else {
		throw new MapperException("继承 selectByIds 方法的实体类[" + entityClass.getCanonicalName() + "]中必须有且只有一个带有 @Id 注解的字段");
	}
	return sql.toString();
}
 
Example #5
Source File: IdsMapperProvider.java    From BlogManagePlatform with Apache License 2.0 6 votes vote down vote up
/**
 * 批量删除
 * @author Frodez
 * @date 2019-12-25
 */
public String deleteByIds(MappedStatement ms) {
	final Class<?> entityClass = getEntityClass(ms);
	StringBuilder sql = new StringBuilder();
	sql.append(SqlHelper.deleteFromTable(entityClass, tableName(entityClass)));
	Set<EntityColumn> columnList = EntityHelper.getPKColumns(entityClass);
	if (columnList.size() == 1) {
		EntityColumn column = columnList.iterator().next();
		sql.append(" where ");
		sql.append(column.getColumn());
		sql.append(" in ");
		sql.append("<foreach collection=\"ids\" item=\"item\" index=\"index\" open=\"(\" close=\")\" separator=\",\">");
		sql.append(" #{item} ");
		sql.append("</foreach>");
	} else {
		throw new MapperException("继承 deleteByIds 方法的实体类[" + entityClass.getCanonicalName() + "]中必须有且只有一个带有 @Id 注解的字段");
	}
	return sql.toString();
}
 
Example #6
Source File: MapperTemplate.java    From tk-mybatis with MIT License 6 votes vote down vote up
/**
 * 获取返回值类型 - 实体类型
 *
 * @param ms
 * @return
 */
public Class<?> getEntityClass(MappedStatement ms) {
    String msId = ms.getId();
    if (entityClassMap.containsKey(msId)) {
        return entityClassMap.get(msId);
    } else {
        Class<?> mapperClass = getMapperClass(msId);
        Type[] types = mapperClass.getGenericInterfaces();
        for (Type type : types) {
            if (type instanceof ParameterizedType) {
                ParameterizedType t = (ParameterizedType) type;
                if (t.getRawType() == this.mapperClass || this.mapperClass.isAssignableFrom((Class<?>) t.getRawType())) {
                    Class<?> returnType = (Class<?>) t.getActualTypeArguments()[0];
                    //获取该类型后,第一次对该类型进行初始化
                    EntityHelper.initEntityNameMap(returnType, mapperHelper.getConfig());
                    entityClassMap.put(msId, returnType);
                    return returnType;
                }
            }
        }
    }
    throw new MapperException("无法获取Mapper<T>泛型类型:" + msId);
}
 
Example #7
Source File: IdsProvider.java    From tk-mybatis with MIT License 6 votes vote down vote up
/**
 * 根据主键字符串进行删除,类中只有存在一个带有@Id注解的字段
 *
 * @param ms
 * @return
 */
public String deleteByIds(MappedStatement ms) {
    final Class<?> entityClass = getEntityClass(ms);
    StringBuilder sql = new StringBuilder();
    sql.append(SqlHelper.deleteFromTable(entityClass, tableName(entityClass)));
    Set<EntityColumn> columnList = EntityHelper.getPKColumns(entityClass);
    if (columnList.size() == 1) {
        EntityColumn column = columnList.iterator().next();
        sql.append(" where ");
        sql.append(column.getColumn());
        sql.append(" in (${_parameter})");
    } else {
        throw new MapperException("继承 deleteByIds 方法的实体类[" + entityClass.getCanonicalName() + "]中必须只有一个带有 @Id 注解的字段");
    }
    return sql.toString();
}
 
Example #8
Source File: IdsProvider.java    From tk-mybatis with MIT License 6 votes vote down vote up
/**
 * 根据主键字符串进行查询,类中只有存在一个带有@Id注解的字段
 *
 * @param ms
 * @return
 */
public String selectByIds(MappedStatement ms) {
    final Class<?> entityClass = getEntityClass(ms);
    //将返回值修改为实体类型
    setResultType(ms, entityClass);
    StringBuilder sql = new StringBuilder();
    sql.append(SqlHelper.selectAllColumns(entityClass));
    sql.append(SqlHelper.fromTable(entityClass, tableName(entityClass)));
    Set<EntityColumn> columnList = EntityHelper.getPKColumns(entityClass);
    if (columnList.size() == 1) {
        EntityColumn column = columnList.iterator().next();
        sql.append(" where ");
        sql.append(column.getColumn());
        sql.append(" in (${_parameter})");
    } else {
        throw new MapperException("继承 selectByIds 方法的实体类[" + entityClass.getCanonicalName() + "]中必须只有一个带有 @Id 注解的字段");
    }
    return sql.toString();
}
 
Example #9
Source File: IdsProvider.java    From Mapper with MIT License 6 votes vote down vote up
/**
 * 根据主键字符串进行删除,类中只有存在一个带有@Id注解的字段
 *
 * @param ms
 * @return
 */
public String deleteByIds(MappedStatement ms) {
    final Class<?> entityClass = getEntityClass(ms);
    StringBuilder sql = new StringBuilder();
    sql.append(SqlHelper.deleteFromTable(entityClass, tableName(entityClass)));
    Set<EntityColumn> columnList = EntityHelper.getPKColumns(entityClass);
    if (columnList.size() == 1) {
        EntityColumn column = columnList.iterator().next();
        sql.append(" where ");
        sql.append(column.getColumn());
        sql.append(" in (${_parameter})");
    } else {
        throw new MapperException("继承 deleteByIds 方法的实体类[" + entityClass.getCanonicalName() + "]中必须只有一个带有 @Id 注解的字段");
    }
    return sql.toString();
}
 
Example #10
Source File: IdsProvider.java    From Mapper with MIT License 6 votes vote down vote up
/**
 * 根据主键字符串进行查询,类中只有存在一个带有@Id注解的字段
 *
 * @param ms
 * @return
 */
public String selectByIds(MappedStatement ms) {
    final Class<?> entityClass = getEntityClass(ms);
    //将返回值修改为实体类型
    setResultType(ms, entityClass);
    StringBuilder sql = new StringBuilder();
    sql.append(SqlHelper.selectAllColumns(entityClass));
    sql.append(SqlHelper.fromTable(entityClass, tableName(entityClass)));
    Set<EntityColumn> columnList = EntityHelper.getPKColumns(entityClass);
    if (columnList.size() == 1) {
        EntityColumn column = columnList.iterator().next();
        sql.append(" where ");
        sql.append(column.getColumn());
        sql.append(" in (${_parameter})");
    } else {
        throw new MapperException("继承 selectByIds 方法的实体类[" + entityClass.getCanonicalName() + "]中必须只有一个带有 @Id 注解的字段");
    }
    return sql.toString();
}
 
Example #11
Source File: TestSelectByExample.java    From Mapper with MIT License 6 votes vote down vote up
@Test
public void testSelectColumnsByExample() {
    exception.expect(MapperException.class);
    exception.expectMessage("类 Country 不包含属性 'hehe',或该属性被@Transient注释!");
    SqlSession sqlSession = MybatisHelper.getSqlSession();
    try {
        CountryMapper mapper = sqlSession.getMapper(CountryMapper.class);
        Example example = new Example(Country.class);
        example.createCriteria().andGreaterThan("id", 100).andLessThan("id", 151);
        example.or().andLessThan("id", 41);
        example.selectProperties("id", "countryname", "hehe");
        List<Country> countries = mapper.selectByExample(example);
        //查询总数
        Assert.assertEquals(90, countries.size());
    } finally {
        sqlSession.close();
    }
}
 
Example #12
Source File: TestSelectByExample.java    From Mapper with MIT License 6 votes vote down vote up
/**
 * 指定查询字段拼写错误或不存在
 */
@Test
public void testSelectPropertisCheckSpellWrong() {
    exception.expect(MapperException.class);
    exception.expectMessage("类 Country 不包含属性 'countrymame',或该属性被@Transient注释!");
    SqlSession sqlSession = MybatisHelper.getSqlSession();
    try {
        CountryMapper mapper = sqlSession.getMapper(CountryMapper.class);
        Example example = new Example(Country.class);
        example.selectProperties(new String[]{"countrymame"});
        example.createCriteria().andEqualTo("id", 35);
        List<Country> country2 = mapper.selectByExample(example);
        Assert.assertEquals(null, country2.get(0).getId());
        Assert.assertEquals("China", country2.get(0).getCountryname());
        Assert.assertEquals(null, country2.get(0).getCountrycode());
    } finally {
        sqlSession.close();
    }
}
 
Example #13
Source File: TestSelectByExample.java    From Mapper with MIT License 6 votes vote down vote up
/**
 * 指定查询字段为@Transient注释字段
 */
@Test
public void testSelectPropertisCheckTransient2() {
    exception.expect(MapperException.class);
    exception.expectMessage("类 Country 不包含属性 'dynamicTableName123',或该属性被@Transient注释!");
    SqlSession sqlSession = MybatisHelper.getSqlSession();
    try {
        CountryMapper mapper = sqlSession.getMapper(CountryMapper.class);
        Example example = new Example(Country.class);
        example.selectProperties(new String[]{"dynamicTableName123"});
        example.createCriteria().andEqualTo("id", 35);
        List<Country> country = mapper.selectByExample(example);
    } finally {
        sqlSession.close();
    }
}
 
Example #14
Source File: TestSelectByExample.java    From Mapper with MIT License 6 votes vote down vote up
/**
 * 指定排除的查询字段不存在或拼写错误
 */
@Test
public void testExcludePropertisCheckWrongSpell() {
    exception.expect(MapperException.class);
    exception.expectMessage("类 Country 不包含属性 'countrymame',或该属性被@Transient注释!");
    SqlSession sqlSession = MybatisHelper.getSqlSession();
    try {
        CountryMapper mapper = sqlSession.getMapper(CountryMapper.class);
        Example example = new Example(Country.class);
        example.excludeProperties(new String[]{"countrymame"});
        example.createCriteria().andEqualTo("id", 35);
        List<Country> country = mapper.selectByExample(example);
    } finally {
        sqlSession.close();
    }
}
 
Example #15
Source File: TestSelectByExample.java    From Mapper with MIT License 6 votes vote down vote up
/**
 * 指定排除的查询字段为@Transient注释字段
 */
@Test
public void testExcludePropertisCheckTransient() {
    exception.expect(MapperException.class);
    exception.expectMessage("类 Country 不包含属性 'dynamicTableName123',或该属性被@Transient注释!");
    SqlSession sqlSession = MybatisHelper.getSqlSession();
    try {
        CountryMapper mapper = sqlSession.getMapper(CountryMapper.class);
        Example example = new Example(Country.class);
        example.excludeProperties(new String[]{"dynamicTableName123"});
        example.createCriteria().andEqualTo("id", 35);
        List<Country> country = mapper.selectByExample(example);
    } finally {
        sqlSession.close();
    }
}
 
Example #16
Source File: IdListProvider.java    From Mapper with MIT License 6 votes vote down vote up
/**
 * 拼接条件
 *
 * @param sql
 * @param entityClass
 */
private void appendWhereIdList(StringBuilder sql, Class<?> entityClass, boolean notEmpty){
    Set<EntityColumn> columnList = EntityHelper.getPKColumns(entityClass);
    if (columnList.size() == 1) {
        EntityColumn column = columnList.iterator().next();
        if(notEmpty){
            sql.append("<bind name=\"notEmptyListCheck\" value=\"@tk.mybatis.mapper.additional.idlist.IdListProvider@notEmpty(");
            sql.append("idList, 'idList 不能为空')\"/>");
        }
        sql.append("<where>");
        sql.append("<foreach collection=\"idList\" item=\"id\" separator=\",\" open=\"");
        sql.append(column.getColumn());
        sql.append(" in ");
        sql.append("(\" close=\")\">");
        sql.append("#{id}");
        sql.append("</foreach>");
        sql.append("</where>");
    } else {
        throw new MapperException("继承 ByIdList 方法的实体类[" + entityClass.getCanonicalName() + "]中必须只有一个带有 @Id 注解的字段");
    }
}
 
Example #17
Source File: Example.java    From Mapper with MIT License 6 votes vote down vote up
/**
 * 排除查询字段,优先级低于 selectProperties
 *
 * @param properties 属性名的可变参数
 * @return
 */
public Example excludeProperties(String... properties) {
    if (properties != null && properties.length > 0) {
        if (this.excludeColumns == null) {
            this.excludeColumns = new LinkedHashSet<String>();
        }
        for (String property : properties) {
            if (propertyMap.containsKey(property)) {
                this.excludeColumns.add(propertyMap.get(property).getColumn());
            } else {
                throw new MapperException("类 " + entityClass.getSimpleName() + " 不包含属性 \'" + property + "\',或该属性被@Transient注释!");
            }
        }
    }
    return this;
}
 
Example #18
Source File: Example.java    From Mapper with MIT License 6 votes vote down vote up
/**
 * 指定要查询的属性列 - 这里会自动映射到表字段
 *
 * @param properties
 * @return
 */
public Example selectProperties(String... properties) {
    if (properties != null && properties.length > 0) {
        if (this.selectColumns == null) {
            this.selectColumns = new LinkedHashSet<String>();
        }
        for (String property : properties) {
            if (propertyMap.containsKey(property)) {
                this.selectColumns.add(propertyMap.get(property).getColumn());
            } else {
                throw new MapperException("类 " + entityClass.getSimpleName() + " 不包含属性 \'" + property + "\',或该属性被@Transient注释!");
            }
        }
    }
    return this;
}
 
Example #19
Source File: TestSelectByExample.java    From Mapper with MIT License 6 votes vote down vote up
/**
 * 指定查询字段为@Transient注释字段
 */
@Test
public void testSelectPropertisCheckTransient1() {
    exception.expect(MapperException.class);
    exception.expectMessage("类 Country 不包含属性 'name',或该属性被@Transient注释!");
    SqlSession sqlSession = MybatisHelper.getSqlSession();
    try {
        CountryMapper mapper = sqlSession.getMapper(CountryMapper.class);
        Example example = new Example(Country.class);
        example.selectProperties(new String[]{"name"});
        example.createCriteria().andEqualTo("id", 35);
        List<Country> country = mapper.selectByExample(example);
    } finally {
        sqlSession.close();
    }
}
 
Example #20
Source File: MapperHelper.java    From Mapper with MIT License 6 votes vote down vote up
/**
 * 设置通用Mapper配置
 *
 * @param config
 */
public void setConfig(Config config) {
    this.config = config;
    if(config.getResolveClass() != null){
        try {
            EntityHelper.setResolve(config.getResolveClass().newInstance());
        } catch (Exception e) {
            log.error("创建 " + config.getResolveClass().getCanonicalName()
                + " 实例失败,请保证该类有默认的构造方法!", e);
            throw new MapperException("创建 " + config.getResolveClass().getCanonicalName()
                    + " 实例失败,请保证该类有默认的构造方法!", e);
        }
    }
    if(config.getMappers() != null && config.getMappers().size() > 0){
        for (Class mapperClass : config.getMappers()) {
            registerMapper(mapperClass);
        }
    }
}
 
Example #21
Source File: FieldHelper.java    From Mapper with MIT License 6 votes vote down vote up
/**
 * 通过方法获取属性
 *
 * @param entityClass
 * @return
 */
@Override
public List<EntityField> getProperties(Class<?> entityClass) {
    List<EntityField> entityFields = new ArrayList<EntityField>();
    BeanInfo beanInfo = null;
    try {
        beanInfo = Introspector.getBeanInfo(entityClass);
    } catch (IntrospectionException e) {
        throw new MapperException(e);
    }
    PropertyDescriptor[] descriptors = beanInfo.getPropertyDescriptors();
    for (PropertyDescriptor desc : descriptors) {
        if (!"class".equals(desc.getName())) {
            entityFields.add(new EntityField(null, desc));
        }
    }
    return entityFields;
}
 
Example #22
Source File: MapperTemplate.java    From Mapper with MIT License 6 votes vote down vote up
/**
 * 获取返回值类型 - 实体类型
 *
 * @param ms
 * @return
 */
public Class<?> getEntityClass(MappedStatement ms) {
    String msId = ms.getId();
    if (entityClassMap.containsKey(msId)) {
        return entityClassMap.get(msId);
    } else {
        Class<?> mapperClass = getMapperClass(msId);
        Type[] types = mapperClass.getGenericInterfaces();
        for (Type type : types) {
            if (type instanceof ParameterizedType) {
                ParameterizedType t = (ParameterizedType) type;
                if (t.getRawType() == this.mapperClass || this.mapperClass.isAssignableFrom((Class<?>) t.getRawType())) {
                    Class<?> returnType = (Class<?>) t.getActualTypeArguments()[0];
                    //获取该类型后,第一次对该类型进行初始化
                    EntityHelper.initEntityNameMap(returnType, mapperHelper.getConfig());
                    entityClassMap.put(msId, returnType);
                    return returnType;
                }
            }
        }
    }
    throw new MapperException("无法获取 " + msId + " 方法的泛型信息!");
}
 
Example #23
Source File: OGNL.java    From Mapper with MIT License 6 votes vote down vote up
/**
 * 检查 paremeter 对象中指定的 fields 是否全是 null,如果是则抛出异常
 *
 * @param parameter
 * @param fields
 * @return
 */
public static boolean notAllNullParameterCheck(Object parameter, String fields) {
    if (parameter != null) {
        try {
            Set<EntityColumn> columns = EntityHelper.getColumns(parameter.getClass());
            Set<String> fieldSet = new HashSet<String>(Arrays.asList(fields.split(",")));
            for (EntityColumn column : columns) {
                if (fieldSet.contains(column.getProperty())) {
                    Object value = column.getEntityField().getValue(parameter);
                    if (value != null) {
                        return true;
                    }
                }
            }
        } catch (Exception e) {
            throw new MapperException(SAFE_DELETE_ERROR, e);
        }
    }
    throw new MapperException(SAFE_DELETE_EXCEPTION);
}
 
Example #24
Source File: CountMapperProvider.java    From BlogManagePlatform with Apache License 2.0 6 votes vote down vote up
/**
 * 批量删除
 * @author Frodez
 * @date 2019-12-25
 */
public String countByIds(MappedStatement ms) {
	final Class<?> entityClass = getEntityClass(ms);
	StringBuilder sql = new StringBuilder();
	sql.append(SqlHelper.selectCount(entityClass));
	sql.append(SqlHelper.fromTable(entityClass, tableName(entityClass)));
	Set<EntityColumn> columnList = EntityHelper.getPKColumns(entityClass);
	if (columnList.size() == 1) {
		EntityColumn column = columnList.iterator().next();
		sql.append(" where ");
		sql.append(column.getColumn());
		sql.append(" in ");
		sql.append("<foreach collection=\"ids\" item=\"item\" index=\"index\" open=\"(\" close=\")\" separator=\",\">");
		sql.append(" #{item} ");
		sql.append("</foreach>");
	} else {
		throw new MapperException("继承 deleteByIds 方法的实体类[" + entityClass.getCanonicalName() + "]中必须有且只有一个带有 @Id 注解的字段");
	}
	return sql.toString();
}
 
Example #25
Source File: Example.java    From Mapper with MIT License 5 votes vote down vote up
protected void addOrCriterion(String condition, Object value1, Object value2, String property) {
    if (value1 == null || value2 == null) {
        if (notNull) {
            throw new MapperException("Between values for " + property + " cannot be null");
        } else {
            return;
        }
    }
    if (property == null) {
        return;
    }
    criteria.add(new Criterion(condition, value1, value2, true));
}
 
Example #26
Source File: SimpleTypeUtil.java    From Mapper with MIT License 5 votes vote down vote up
/**
 * 注册新的类型
 *
 * @param classes
 */
public static void registerSimpleType(String classes){
    if(StringUtil.isNotEmpty(classes)){
        String[] cls = classes.split(",");
        for (String c : cls) {
            try {
                SIMPLE_TYPE_SET.add(Class.forName(c));
            } catch (ClassNotFoundException e) {
                throw new MapperException("注册类型出错:" + c, e);
            }
        }
    }
}
 
Example #27
Source File: Example.java    From Mapper with MIT License 5 votes vote down vote up
public Builder select(String... properties) {
    if (properties != null && properties.length > 0) {
        if (this.selectColumns == null) {
            this.selectColumns = new LinkedHashSet<String>();
        }
        for (String property : properties) {
            if (this.propertyMap.containsKey(property)) {
                this.selectColumns.add(propertyMap.get(property).getColumn());
            } else {
                throw new MapperException("当前实体类不包含名为" + property + "的属性!");
            }
        }
    }
    return this;
}
 
Example #28
Source File: MapperHelper.java    From Mapper with MIT License 5 votes vote down vote up
/**
 * 注册通用Mapper接口
 *
 * @param mapperClass
 */
public void registerMapper(String mapperClass) {
    try {
        registerMapper(Class.forName(mapperClass));
    } catch (ClassNotFoundException e) {
        log.error("注册通用Mapper[" + mapperClass + "]失败,找不到该通用Mapper!", e);
        throw new MapperException("注册通用Mapper[" + mapperClass + "]失败,找不到该通用Mapper!");
    }
}
 
Example #29
Source File: Example.java    From Mapper with MIT License 5 votes vote down vote up
protected void addOrCriterion(String condition, Object value, String property) {
    if (value == null) {
        if (notNull) {
            throw new MapperException("Value for " + property + " cannot be null");
        } else {
            return;
        }
    }
    if (property == null) {
        return;
    }
    criteria.add(new Criterion(condition, value, true));
}
 
Example #30
Source File: MapperHelper.java    From Mapper with MIT License 5 votes vote down vote up
/**
 * 配置属性
 *
 * @param properties
 */
public void setProperties(Properties properties) {
    config.setProperties(properties);
    //注册解析器
    if (properties != null) {
        String resolveClass = properties.getProperty("resolveClass");
        if (StringUtil.isNotEmpty(resolveClass)) {
            try {
                EntityHelper.setResolve((EntityResolve) Class.forName(resolveClass).newInstance());
            } catch (Exception e) {
                log.error("创建 " + resolveClass + " 实例失败!", e);
                throw new MapperException("创建 " + resolveClass + " 实例失败!", e);
            }
        }
    }
    //注册通用接口
    if (properties != null) {
        String mapper = properties.getProperty("mappers");
        if (StringUtil.isNotEmpty(mapper)) {
            String[] mappers = mapper.split(",");
            for (String mapperClass : mappers) {
                if (mapperClass.length() > 0) {
                    registerMapper(mapperClass);
                }
            }
        }
    }
}