Skip to content

Commit

Permalink
结构调整
Browse files Browse the repository at this point in the history
  • Loading branch information
Caratacus committed Apr 24, 2017
1 parent 81c28ae commit 8c7aecd
Show file tree
Hide file tree
Showing 11 changed files with 126 additions and 126 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -143,13 +143,14 @@ public boolean isEmpty() {
* SQL条件类
*/
private static class SQLCondition implements Serializable {
int[] limit = null;

final List<String> where = new ArrayList<>();
final List<String> having = new ArrayList<>();
final List<String> groupBy = new ArrayList<>();
final List<String> orderBy = new ArrayList<>();
List<String> lastList = new ArrayList<>();
final List<String> andOr = new ArrayList<>();
int[] limit = null;
List<String> lastList = new ArrayList<>();

public SQLCondition() {
andOr.add(AND);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ public void addMappedStatement(MappedStatement ms) {
logger.debug("addMappedStatement: " + ms.getId());
if (GlobalConfiguration.getGlobalConfig(ms.getConfiguration()).isRefresh()) {
/*
* 支持是否自动刷新 XML 变更内容,开发环境使用【 注:生产环境勿用!】
* 支持是否自动刷新 XML 变更内容,开发环境使用【 注:生产环境勿用!】
*/
this.mappedStatements.remove(ms.getId());
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,19 @@ public class MybatisDefaultParameterHandler extends DefaultParameterHandler {
* @see org.apache.ibatis.mapping.BoundSql
*/
private static final Field additionalParametersField = getAdditionalParametersField();
private final TypeHandlerRegistry typeHandlerRegistry;
private final MappedStatement mappedStatement;
private final Object parameterObject;
private BoundSql boundSql;
private Configuration configuration;
public MybatisDefaultParameterHandler(MappedStatement mappedStatement, Object parameterObject, BoundSql boundSql) {
super(mappedStatement, processBatch(mappedStatement, parameterObject), boundSql);
this.mappedStatement = mappedStatement;
this.configuration = mappedStatement.getConfiguration();
this.typeHandlerRegistry = mappedStatement.getConfiguration().getTypeHandlerRegistry();
this.parameterObject = parameterObject;
this.boundSql = boundSql;
}

/**
* 反射获取BoundSql中additionalParameters参数字段
Expand All @@ -79,21 +92,6 @@ private static Field getAdditionalParametersField() {
return null;
}

private final TypeHandlerRegistry typeHandlerRegistry;
private final MappedStatement mappedStatement;
private final Object parameterObject;
private BoundSql boundSql;
private Configuration configuration;

public MybatisDefaultParameterHandler(MappedStatement mappedStatement, Object parameterObject, BoundSql boundSql) {
super(mappedStatement, processBatch(mappedStatement, parameterObject), boundSql);
this.mappedStatement = mappedStatement;
this.configuration = mappedStatement.getConfiguration();
this.typeHandlerRegistry = mappedStatement.getConfiguration().getTypeHandlerRegistry();
this.parameterObject = parameterObject;
this.boundSql = boundSql;
}

/**
* <p>
* 批量(填充主键 ID)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,17 +15,18 @@
*/
package com.baomidou.mybatisplus;

import com.baomidou.mybatisplus.entity.GlobalConfiguration;
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;

import org.apache.ibatis.binding.BindingException;
import org.apache.ibatis.binding.MapperProxyFactory;
import org.apache.ibatis.binding.MapperRegistry;
import org.apache.ibatis.session.Configuration;
import org.apache.ibatis.session.SqlSession;

import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
import com.baomidou.mybatisplus.entity.GlobalConfiguration;

/**
* <p>
Expand All @@ -36,6 +37,7 @@
* @since 2017-04-19
*/
public class MybatisMapperRegistry extends MapperRegistry {

private final Map<Class<?>, MapperProxyFactory<?>> knownMappers = new HashMap<>();
private final Configuration config;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@
* ActiveRecord 模式 CRUD
* </p>
*
* @author hubin
* @param <T>
* @author hubin
* @Date 2016-11-06
*/
@SuppressWarnings({"rawtypes"})
Expand Down Expand Up @@ -78,7 +78,7 @@ public boolean insertOrUpdate() {
return insert();
} else {
/*
* 更新成功直接返回,失败执行插入逻辑
* 更新成功直接返回,失败执行插入逻辑
*/
return updateById() || insert();
}
Expand All @@ -89,8 +89,7 @@ public boolean insertOrUpdate() {
* 根据 ID 删除
* </p>
*
* @param id
* 主键ID
* @param id 主键ID
* @return
*/
@Transactional
Expand Down Expand Up @@ -118,10 +117,8 @@ public boolean deleteById() {
* 删除记录
* </p>
*
* @param whereClause
* 查询条件
* @param args
* 查询条件值
* @param whereClause 查询条件
* @param args 查询条件值
* @return
*/
@Transactional
Expand Down Expand Up @@ -178,10 +175,8 @@ public boolean updateAllColumnById() {
* 执行 SQL 更新
* </p>
*
* @param whereClause
* 查询条件
* @param args
* 查询条件值
* @param whereClause 查询条件
* @param args 查询条件值
* @return
*/
@Transactional
Expand Down Expand Up @@ -223,8 +218,7 @@ public List<T> selectAll() {
* 根据 ID 查询
* </p>
*
* @param id
* 主键ID
* @param id 主键ID
* @return
*/
public T selectById(Serializable id) {
Expand Down Expand Up @@ -303,8 +297,7 @@ public T selectOne(String whereClause, Object... args) {
* 翻页查询
* </p>
*
* @param page
* 翻页查询条件
* @param page 翻页查询条件
* @param wrapper
* @return
*/
Expand Down Expand Up @@ -337,10 +330,8 @@ public Page<T> selectPage(Page<T> page, String whereClause, Object... args) {
* 查询总数
* </p>
*
* @param whereClause
* 查询条件
* @param args
* 查询条件值
* @param whereClause 查询条件
* @param args 查询条件值
* @return
*/
public int selectCount(String whereClause, Object... args) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,10 @@
*/
package com.baomidou.mybatisplus.entity;

import com.baomidou.mybatisplus.mapper.MetaObjectHandler;
import org.apache.ibatis.reflection.MetaObject;

import com.baomidou.mybatisplus.mapper.MetaObjectHandler;

/**
* <p>
* 默认填充器关闭操作
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@
import com.baomidou.mybatisplus.enums.IdType;
import com.baomidou.mybatisplus.exceptions.MybatisPlusException;
import com.baomidou.mybatisplus.mapper.AutoSqlInjector;
import com.baomidou.mybatisplus.mapper.MetaObjectHandler;
import com.baomidou.mybatisplus.mapper.ISqlInjector;
import com.baomidou.mybatisplus.mapper.MetaObjectHandler;
import com.baomidou.mybatisplus.toolkit.IOUtils;
import com.baomidou.mybatisplus.toolkit.JdbcUtils;
import com.baomidou.mybatisplus.toolkit.SqlReservedWords;
Expand All @@ -53,20 +53,21 @@
* @since 2016-12-06
*/
public class GlobalConfiguration implements Cloneable {
// 日志
private static final Log logger = LogFactory.getLog(GlobalConfiguration.class);

/**
* 默认参数
*/
public static final GlobalConfiguration DEFAULT = new GlobalConfiguration();
// 逻辑删除全局值
private String logicDeleteValue = null;
// 逻辑未删除全局值
private String logicNotDeleteValue = null;
// 日志
private static final Log logger = LogFactory.getLog(GlobalConfiguration.class);
/**
* 缓存全局信息
*/
private static final Map<String, GlobalConfiguration> GLOBAL_CONFIG = new ConcurrentHashMap<>();
// 逻辑删除全局值
private String logicDeleteValue = null;
// 逻辑未删除全局值
private String logicNotDeleteValue = null;
// 数据库类型(默认 MySql)
private DBType dbType = DBType.MYSQL;
// 主键类型(默认 ID_WORKER)
Expand Down Expand Up @@ -176,23 +177,7 @@ public static GlobalConfiguration getGlobalConfig(String configMark) {
return cache;
}

public String getLogicDeleteValue() {
return logicDeleteValue;
}

public void setLogicDeleteValue(String logicDeleteValue) {
this.logicDeleteValue = logicDeleteValue;
}

public String getLogicNotDeleteValue() {
return logicNotDeleteValue;
}

public void setLogicNotDeleteValue(String logicNotDeleteValue) {
this.logicNotDeleteValue = logicNotDeleteValue;
}

public static DBType getDbType(Configuration configuration) {
public static DBType getDbType(Configuration configuration) {
return getGlobalConfig(configuration).getDbType();
}

Expand Down Expand Up @@ -235,9 +220,9 @@ public static Set<String> getMapperRegistryCache(Configuration configuration) {
return getGlobalConfig(configuration).getMapperRegistryCache();
}

public static String getIdentifierQuote(Configuration configuration) {
return getGlobalConfig(configuration).getIdentifierQuote();
}
public static String getIdentifierQuote(Configuration configuration) {
return getGlobalConfig(configuration).getIdentifierQuote();
}

public static SqlSession getSqlSession(Configuration configuration) {
return getGlobalConfig(configuration).getSqlSession();
Expand Down Expand Up @@ -267,6 +252,22 @@ public static void setMetaData(DataSource dataSource, GlobalConfiguration global
}
}

public String getLogicDeleteValue() {
return logicDeleteValue;
}

public void setLogicDeleteValue(String logicDeleteValue) {
this.logicDeleteValue = logicDeleteValue;
}

public String getLogicNotDeleteValue() {
return logicNotDeleteValue;
}

public void setLogicNotDeleteValue(String logicNotDeleteValue) {
this.logicNotDeleteValue = logicNotDeleteValue;
}

public DBType getDbType() {
return dbType;
}
Expand Down Expand Up @@ -361,7 +362,7 @@ public void setCapitalMode(boolean isCapitalMode) {
this.isCapitalMode = isCapitalMode;
}

public String getIdentifierQuote() {
public String getIdentifierQuote() {
if (null == identifierQuote) {
return dbType.getQuote();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,14 @@
*/
public class ConfigBuilder {

/**
* 模板路径配置信息
*/
private final TemplateConfig template;
/**
* 数据库配置
*/
private final DataSourceConfig dataSourceConfig;
/**
* SQL连接
*/
Expand All @@ -68,7 +76,6 @@ public class ConfigBuilder {
* 数据库表信息
*/
private List<TableInfo> tableInfoList;

/**
* 包配置详情
*/
Expand All @@ -77,17 +84,6 @@ public class ConfigBuilder {
* 路径配置信息
*/
private Map<String, String> pathInfo;

/**
* 模板路径配置信息
*/
private final TemplateConfig template;

/**
* 数据库配置
*/
private final DataSourceConfig dataSourceConfig;

/**
* 策略配置
*/
Expand Down Expand Up @@ -399,7 +395,7 @@ private List<TableInfo> getTablesInfo(StrategyConfig config) {
tableList.removeAll(excludeTableList);
includeTableList = tableList;
}
if (!isInclude && !isExclude){
if (!isInclude && !isExclude) {
includeTableList = tableList;
}
} catch (SQLException e) {
Expand Down Expand Up @@ -445,11 +441,11 @@ private boolean isKeyIdentity(ResultSet results) throws SQLException {
* @param strategy 命名策略
* @return 表信息
*/
private List<TableField> getListFields(String tableName, NamingStrategy strategy){
private List<TableField> getListFields(String tableName, NamingStrategy strategy) {
boolean haveId = false;
List<TableField> fieldList = new ArrayList<>();
try (PreparedStatement pstate = connection.prepareStatement(String.format(querySQL.getTableFieldsSql(), tableName));
ResultSet results = pstate.executeQuery()){
ResultSet results = pstate.executeQuery()) {
while (results.next()) {
TableField field = new TableField();
String key = results.getString(querySQL.getFieldKey());
Expand Down Expand Up @@ -477,8 +473,8 @@ private List<TableField> getListFields(String tableName, NamingStrategy strategy
field.setComment(results.getString(querySQL.getFieldComment()));
fieldList.add(field);
}
}catch (SQLException e){
System.err.println("SQL Exception:"+e.getMessage());
} catch (SQLException e) {
System.err.println("SQL Exception:" + e.getMessage());
}
return fieldList;
}
Expand Down
Loading

0 comments on commit 8c7aecd

Please sign in to comment.