@@ -47,81 +47,6 @@ public BaseInsertProvider(Class<?> mapperClass, MapperHelper mapperHelper) {
47
47
super (mapperClass , mapperHelper );
48
48
}
49
49
50
- /*
51
- public SqlNode insert(MappedStatement ms) {
52
- Class<?> entityClass = getEntityClass(ms);
53
- StringBuilder sql = new StringBuilder();
54
- //获取全部列
55
- Set<EntityColumn> columnList = EntityHelper.getColumns(entityClass);
56
- //Identity列只能有一个
57
- Boolean hasIdentityKey = false;
58
- //处理所有的主键策略
59
- for (EntityColumn column : columnList) {
60
- //序列的情况,直接写入sql中,不需要额外的获取值
61
- if (StringUtil.isNotEmpty(column.getSequenceName())) {
62
- } else if (column.isIdentity()) {
63
- //这种情况下,如果原先的字段有值,需要先缓存起来,否则就一定会使用自动增长
64
- //这是一个bind节点
65
- sql.append(SqlHelper.getBindCache(column));
66
- //如果是Identity列,就需要插入selectKey
67
- //如果已经存在Identity列,抛出异常
68
- if (hasIdentityKey) {
69
- //jdbc类型只需要添加一次
70
- if (column.getGenerator() != null && column.getGenerator().equals("JDBC")) {
71
- continue;
72
- }
73
- throw new RuntimeException(ms.getId() + "对应的实体类" + entityClass.getCanonicalName() + "中包含多个MySql的自动增长列,最多只能有一个!");
74
- }
75
- //插入selectKey
76
- newSelectKeyMappedStatement(ms, column);
77
- hasIdentityKey = true;
78
- } else if (column.isUuid()) {
79
- //uuid的情况,直接插入bind节点
80
- sql.append(SqlHelper.getBindValue(column, getUUID()));
81
- }
82
- }
83
- sql.append("INSERT INTO ");
84
- sql.append(SqlHelper.getDynamicTableName(entityClass, tableName(entityClass)));
85
- sql.append("(");
86
- if(sql.charAt(sql.length() - 1) == ','){
87
- sql.setCharAt(sql.length() - 1, ')');
88
- } else {
89
-
90
- }
91
- //插入全部的(列名,列名...)
92
- sql.append("(").append(EntityHelper.getAllColumns(entityClass)).append(")");
93
- sql.append(" VALUES (");
94
- List<SqlNode> ifNodes = new ArrayList<SqlNode>();
95
- //处理所有的values(属性值,属性值...)
96
- for (EntityColumn column : columnList) {
97
- //优先使用传入的属性值,当原属性property!=null时,用原属性
98
- //自增的情况下,如果默认有值,就会备份到property_cache中,所以这里需要先判断备份的值是否存在
99
- if (column.isIdentity()) {
100
- sql.append(SqlHelper.getIfCacheNotNull(column, "#{" + column.getProperty() + "_cache },"));
101
- } else {
102
- //其他情况值仍然存在原property中
103
- sql.append(SqlHelper.getIfNotNull(column, column.getColumnHolder(), isNotEmpty())).append(",");
104
- }
105
- //当属性为null时,如果存在主键策略,会自动获取值,如果不存在,则使用null
106
- //序列的情况
107
- if (StringUtil.isNotEmpty(column.getSequenceName())) {
108
- sql.append(SqlHelper.getIfNotNull(column, column.getColumnHolder(), isNotEmpty())).append(",");
109
- ifNodes.add(getIfIsNull(column, new StaticTextSqlNode(getSeqNextVal(column) + " ,")));
110
- } else if (column.isIdentity()) {
111
- ifNodes.add(getIfCacheIsNull(column, new StaticTextSqlNode(column.getColumnHolder() + ",")));
112
- } else if (column.isUuid()) {
113
- ifNodes.add(getIfIsNull(column, new StaticTextSqlNode("#{" + column.getProperty() + "_bind },")));
114
- } else {
115
- //当null的时候,如果不指定jdbcType,oracle可能会报异常,指定VARCHAR不影响其他
116
- ifNodes.add(getIfIsNull(column, new StaticTextSqlNode(column.getColumnHolder() + ",")));
117
- }
118
- }
119
- //values(#{property},#{property}...)
120
- sqlNodes.add(new TrimSqlNode(ms.getConfiguration(), new MixedSqlNode(ifNodes), "VALUES (", null, ")", ","));
121
- return new MixedSqlNode(sqlNodes);
122
- }
123
- */
124
-
125
50
/**
126
51
* 插入全部
127
52
*
@@ -172,10 +97,10 @@ public SqlNode insert(MappedStatement ms) {
172
97
//优先使用传入的属性值,当原属性property!=null时,用原属性
173
98
//自增的情况下,如果默认有值,就会备份到property_cache中,所以这里需要先判断备份的值是否存在
174
99
if (column .isIdentity ()) {
175
- ifNodes .add (getIfCacheNotNull (column , new StaticTextSqlNode ("#{" + column .getProperty () + "_cache }," )));
100
+ ifNodes .add (getIfCacheNotNull (column , new StaticTextSqlNode (column .getColumnHolder ( null , "_cache" , "," ) )));
176
101
} else {
177
102
//其他情况值仍然存在原property中
178
- ifNodes .add (getIfNotNull (column , new StaticTextSqlNode (column .getColumnHolder () + "," )));
103
+ ifNodes .add (getIfNotNull (column , new StaticTextSqlNode (column .getColumnHolder (null , null , "," ) )));
179
104
}
180
105
//当属性为null时,如果存在主键策略,会自动获取值,如果不存在,则使用null
181
106
//序列的情况
@@ -184,10 +109,10 @@ public SqlNode insert(MappedStatement ms) {
184
109
} else if (column .isIdentity ()) {
185
110
ifNodes .add (getIfCacheIsNull (column , new StaticTextSqlNode (column .getColumnHolder () + "," )));
186
111
} else if (column .isUuid ()) {
187
- ifNodes .add (getIfIsNull (column , new StaticTextSqlNode ("#{" + column .getProperty () + "_bind }," )));
112
+ ifNodes .add (getIfIsNull (column , new StaticTextSqlNode (column .getColumnHolder ( null , "_bind" , "," ) )));
188
113
} else {
189
114
//当null的时候,如果不指定jdbcType,oracle可能会报异常,指定VARCHAR不影响其他
190
- ifNodes .add (getIfIsNull (column , new StaticTextSqlNode (column .getColumnHolder () + "," )));
115
+ ifNodes .add (getIfIsNull (column , new StaticTextSqlNode (column .getColumnHolder (null , null , "," ) )));
191
116
}
192
117
}
193
118
//values(#{property},#{property}...)
@@ -251,16 +176,16 @@ public SqlNode insertSelective(MappedStatement ms) {
251
176
//当参数中的属性值不为空的时候,使用传入的值
252
177
//自增的情况下,如果默认有值,就会备份到property_cache中
253
178
if (column .isIdentity ()) {
254
- ifNodes .add (new IfSqlNode (new StaticTextSqlNode ("#{" + column .getProperty () + "_cache }," ), column .getProperty () + "_cache != null " ));
179
+ ifNodes .add (new IfSqlNode (new StaticTextSqlNode (column .getColumnHolder ( null , "_cache" , "," ) ), column .getProperty () + "_cache != null " ));
255
180
} else {
256
- ifNodes .add (new IfSqlNode (new StaticTextSqlNode (column .getColumnHolder () + "," ), column .getProperty () + " != null " ));
181
+ ifNodes .add (new IfSqlNode (new StaticTextSqlNode (column .getColumnHolder (null , null , "," ) ), column .getProperty () + " != null " ));
257
182
}
258
183
if (StringUtil .isNotEmpty (column .getSequenceName ())) {
259
184
ifNodes .add (getIfIsNull (column , new StaticTextSqlNode (getSeqNextVal (column ) + " ," )));
260
185
} else if (column .isIdentity ()) {
261
- ifNodes .add (getIfCacheIsNull (column , new StaticTextSqlNode (column .getColumnHolder () + "," )));
186
+ ifNodes .add (getIfCacheIsNull (column , new StaticTextSqlNode (column .getColumnHolder (null , null , "," ) )));
262
187
} else if (column .isUuid ()) {
263
- ifNodes .add (getIfIsNull (column , new StaticTextSqlNode ("#{" + column .getProperty () + "_bind }," )));
188
+ ifNodes .add (getIfIsNull (column , new StaticTextSqlNode (column .getColumnHolder ( null , "_bind" , "," ) )));
264
189
}
265
190
}
266
191
//values(#{property},#{property}...)
0 commit comments