Skip to content

Commit

Permalink
升级 2.0 正式版
Browse files Browse the repository at this point in the history
  • Loading branch information
= committed Dec 11, 2016
1 parent 7a1ce9c commit 8b76749
Show file tree
Hide file tree
Showing 5 changed files with 61 additions and 31 deletions.
2 changes: 1 addition & 1 deletion mybatis-plus/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>com.baomidou</groupId>
<artifactId>mybatis-plus</artifactId>
<version>2.0-rc</version>
<version>2.0</version>
<packaging>jar</packaging>

<name>mybatis-plus</name>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,15 @@
*/
package com.baomidou.mybatisplus.activerecord;

import java.io.Serializable;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.apache.ibatis.logging.Log;
import org.apache.ibatis.logging.LogFactory;
import org.apache.ibatis.session.SqlSession;

import com.baomidou.mybatisplus.enums.SqlMethod;
import com.baomidou.mybatisplus.exceptions.MybatisPlusException;
import com.baomidou.mybatisplus.mapper.Condition;
Expand All @@ -24,14 +33,6 @@
import com.baomidou.mybatisplus.plugins.Page;
import com.baomidou.mybatisplus.toolkit.CollectionUtils;
import com.baomidou.mybatisplus.toolkit.StringUtils;
import org.apache.ibatis.logging.Log;
import org.apache.ibatis.logging.LogFactory;
import org.apache.ibatis.session.SqlSession;

import java.io.Serializable;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
* <p>
Expand Down Expand Up @@ -92,6 +93,9 @@ public boolean deleteById(Serializable id) {
* @return
*/
public boolean deleteById() {
if (null == this.pkVal()) {
throw new MybatisPlusException("deleteById primaryKey is null.");
}
return deleteById(this.pkVal());
}

Expand Down Expand Up @@ -134,7 +138,7 @@ public boolean delete(Wrapper wrapper) {
*/
public boolean updateById() {
if (null == this.pkVal()) {
throw new MybatisPlusException("primaryKey is null.");
throw new MybatisPlusException("updateById primaryKey is null.");
}
// updateById
return SqlHelper.retBool(sqlSession().update(sqlStatement(SqlMethod.UPDATE_BY_ID), this));
Expand Down Expand Up @@ -204,6 +208,9 @@ public T selectById(Serializable id) {
* @return
*/
public T selectById() {
if (null == this.pkVal()) {
throw new MybatisPlusException("selectById primaryKey is null.");
}
return selectById(this.pkVal());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,24 +15,25 @@
*/
package com.baomidou.mybatisplus.mapper;

import java.util.Collections;
import java.util.List;
import java.util.Map;

import org.apache.ibatis.logging.Log;
import org.apache.ibatis.logging.LogFactory;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;

import com.baomidou.mybatisplus.entity.GlobalConfiguration;
import com.baomidou.mybatisplus.entity.TableInfo;
import com.baomidou.mybatisplus.plugins.pagination.Pagination;
import com.baomidou.mybatisplus.toolkit.CollectionUtils;
import com.baomidou.mybatisplus.toolkit.StringUtils;
import com.baomidou.mybatisplus.toolkit.TableInfoHelper;
import org.apache.ibatis.logging.Log;
import org.apache.ibatis.logging.LogFactory;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;

import java.util.Collections;
import java.util.List;
import java.util.Map;

/**
* <p>
* SQLQuery直接执行SQL
* SqlQuery 执行 SQL
* </p>
*
* @author Caratacus
Expand All @@ -41,7 +42,7 @@
public class SqlQuery {
private static final Log logger = LogFactory.getLog(SqlQuery.class);
// 单例Query
public static final SqlQuery query = new SqlQuery();
public static final SqlQuery SQL_QUERY = new SqlQuery();
private SqlSessionFactory sqlSessionFactory;
private TableInfo tableInfo;

Expand All @@ -54,8 +55,7 @@ public SqlQuery() {

public SqlQuery(Class<?> clazz) {
this.tableInfo = SqlHelper.table(clazz);
String configMark = tableInfo.getConfigMark();
GlobalConfiguration globalConfiguration = GlobalConfiguration.GlobalConfig(configMark);
GlobalConfiguration globalConfiguration = GlobalConfiguration.GlobalConfig(tableInfo.getConfigMark());
this.sqlSessionFactory = globalConfiguration.getSqlSessionFactory();
}

Expand Down Expand Up @@ -104,7 +104,7 @@ public List<Map<String, Object>> selectPage(Pagination page, String sql, Object.
* @return
*/
public static SqlQuery db() {
return query;
return SQL_QUERY;
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,19 @@ protected SqlSession sqlSessionBatch() {
return SqlHelper.sqlSessionBatch(currentModleClass());
}

/**
* <p>
* 判断数据库操作是否成功
* </p>
*
* @param result
* 数据库操作返回影响条数
* @return boolean
*/
public boolean retBool(int result) {
return result >= 1;
}

/**
* <p>
* TableId 注解存在更新记录,否插入一条记录
Expand Down Expand Up @@ -104,7 +117,7 @@ public boolean insertOrUpdate(T entity) {
}

public boolean insert(T entity) {
return SqlHelper.retBool(baseMapper.insert(entity));
return retBool(baseMapper.insert(entity));
}

public boolean insertBatch(List<T> entityList) {
Expand Down Expand Up @@ -166,30 +179,30 @@ public boolean insertBatch(List<T> entityList, int batchSize) {
}

public boolean deleteById(Serializable id) {
return SqlHelper.retBool(baseMapper.deleteById(id));
return retBool(baseMapper.deleteById(id));
}

public boolean deleteByMap(Map<String, Object> columnMap) {
if (MapUtils.isEmpty(columnMap)) {
throw new MybatisPlusException("deleteByMap columnMap is empty.");
}
return SqlHelper.retBool(baseMapper.deleteByMap(columnMap));
return retBool(baseMapper.deleteByMap(columnMap));
}

public boolean delete(Wrapper<T> wrapper) {
return SqlHelper.retBool(baseMapper.delete(wrapper));
return retBool(baseMapper.delete(wrapper));
}

public boolean deleteBatchIds(List<? extends Serializable> idList) {
return SqlHelper.retBool(baseMapper.deleteBatchIds(idList));
return retBool(baseMapper.deleteBatchIds(idList));
}

public boolean updateById(T entity) {
return SqlHelper.retBool(baseMapper.updateById(entity));
return retBool(baseMapper.updateById(entity));
}

public boolean update(T entity, Wrapper<T> wrapper) {
return SqlHelper.retBool(baseMapper.update(entity, wrapper));
return retBool(baseMapper.update(entity, wrapper));
}

public boolean updateBatchById(List<T> entityList) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@
import java.util.HashMap;
import java.util.Map;

import com.baomidou.mybatisplus.generator.InjectionConfig;
import com.baomidou.mybatisplus.generator.AutoGenerator;
import com.baomidou.mybatisplus.generator.InjectionConfig;
import com.baomidou.mybatisplus.generator.config.DataSourceConfig;
import com.baomidou.mybatisplus.generator.config.GlobalConfig;
import com.baomidou.mybatisplus.generator.config.PackageConfig;
Expand Down Expand Up @@ -116,6 +116,16 @@ public void initMap() {
};
mpg.setCfg(cfg);

// 自定义模板配置
// TemplateConfig tc = new TemplateConfig();
// tc.setController("...");
// tc.setEntity("...");
// tc.setMapper("...");
// tc.setXml("...");
// tc.setService("...");
// tc.setServiceImpl("...");
// mpg.setTemplate(tc);

// 执行生成
mpg.execute();

Expand Down

0 comments on commit 8b76749

Please sign in to comment.