|
20 | 20 | import com.github.mygreen.sqlmapper.core.id.IdentityIdGenerator;
|
21 | 21 | import com.github.mygreen.sqlmapper.core.meta.PropertyMeta;
|
22 | 22 | import com.github.mygreen.sqlmapper.core.meta.PropertyValueInvoker;
|
| 23 | +import com.github.mygreen.sqlmapper.core.query.InsertClause; |
23 | 24 | import com.github.mygreen.sqlmapper.core.query.JdbcTemplateBuilder;
|
24 | 25 | import com.github.mygreen.sqlmapper.core.type.ValueType;
|
25 | 26 | import com.github.mygreen.sqlmapper.core.util.NumberConvertUtils;
|
@@ -51,6 +52,11 @@ public class AutoBatchInsertExecutor {
|
51 | 52 | */
|
52 | 53 | private final SqlMapperContext context;
|
53 | 54 |
|
| 55 | + /** |
| 56 | + * INSERT句 - SQLログ出力のために使用する。 |
| 57 | + */ |
| 58 | + private InsertClause insertClause = new InsertClause(); |
| 59 | + |
54 | 60 | /**
|
55 | 61 | * クエリのパラメータ - エンティティごとの設定
|
56 | 62 | */
|
@@ -153,6 +159,10 @@ private void prepareSqlParam() {
|
153 | 159 | // IDENTITYの主キーでない場合は通常カラムとして追加
|
154 | 160 | if(!usingIdentityKeyColumnNames.contains(columnName)) {
|
155 | 161 | usingColumnNames.add(columnName);
|
| 162 | + |
| 163 | + if(context.getSqlLogger().getProp().isEnabled()) { |
| 164 | + insertClause.addSql(columnName, "?"); |
| 165 | + } |
156 | 166 | }
|
157 | 167 |
|
158 | 168 | }
|
@@ -247,6 +257,19 @@ public int[] execute() {
|
247 | 257 |
|
248 | 258 | prepare();
|
249 | 259 |
|
| 260 | + if(context.getSqlLogger().getProp().isEnabled()) { |
| 261 | + String executedSql = "insert into " |
| 262 | + + query.getEntityMeta().getTableMeta().getFullName() |
| 263 | + + insertClause.toIntoSql() |
| 264 | + + insertClause.toValuesSql(); |
| 265 | + |
| 266 | + List<Object[]> batchArgs = new ArrayList<>(batchParams.length); |
| 267 | + for(MapSqlParameterSource paramSource : batchParams) { |
| 268 | + batchArgs.add(paramSource.getValues().values().toArray()); |
| 269 | + } |
| 270 | + context.getSqlLogger().outBatch(executedSql, batchArgs); |
| 271 | + } |
| 272 | + |
250 | 273 | if(this.usingIdentityKeyColumnNames.isEmpty()) {
|
251 | 274 | // 主キーがIDENTITYによる生成でない場合
|
252 | 275 | return insertOperation.executeBatch(batchParams);
|
|
0 commit comments