|
@@ -0,0 +1,63 @@
|
|
|
+/*
|
|
|
+ * Copyright (c) 2011-2019, hubin (jobob@qq.com).
|
|
|
+ * <p>
|
|
|
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not
|
|
|
+ * use this file except in compliance with the License. You may obtain a copy of
|
|
|
+ * the License at
|
|
|
+ * <p>
|
|
|
+ * https://www.apache.org/licenses/LICENSE-2.0
|
|
|
+ * <p>
|
|
|
+ * Unless required by applicable law or agreed to in writing, software
|
|
|
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
|
|
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
|
|
+ * License for the specific language governing permissions and limitations under
|
|
|
+ * the License.
|
|
|
+ */
|
|
|
+
|
|
|
+package com.baomidou.mybatisplus.core.executor;
|
|
|
+
|
|
|
+import org.apache.ibatis.executor.SimpleExecutor;
|
|
|
+import org.apache.ibatis.executor.statement.StatementHandler;
|
|
|
+import org.apache.ibatis.mapping.BoundSql;
|
|
|
+import org.apache.ibatis.mapping.MappedStatement;
|
|
|
+import org.apache.ibatis.session.Configuration;
|
|
|
+import org.apache.ibatis.session.ResultHandler;
|
|
|
+import org.apache.ibatis.session.RowBounds;
|
|
|
+import org.apache.ibatis.transaction.Transaction;
|
|
|
+
|
|
|
+import java.sql.Connection;
|
|
|
+import java.sql.SQLException;
|
|
|
+import java.sql.Statement;
|
|
|
+import java.util.Collections;
|
|
|
+import java.util.List;
|
|
|
+
|
|
|
+/**
|
|
|
+ * 重写执行器
|
|
|
+ *
|
|
|
+ * @author nieqiurong 2019/4/14.
|
|
|
+ */
|
|
|
+public class MybatisSimpleExecutor extends SimpleExecutor {
|
|
|
+
|
|
|
+ public MybatisSimpleExecutor(Configuration configuration, Transaction transaction) {
|
|
|
+ super(configuration, transaction);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public <E> List<E> doQuery(MappedStatement ms, Object parameter, RowBounds rowBounds, ResultHandler resultHandler, BoundSql boundSql) throws SQLException {
|
|
|
+ Statement stmt = null;
|
|
|
+ try {
|
|
|
+ Configuration configuration = ms.getConfiguration();
|
|
|
+ StatementHandler handler = configuration.newStatementHandler(wrapper, ms, parameter, rowBounds, resultHandler, boundSql);
|
|
|
+ Connection connection = getConnection(ms.getStatementLog());
|
|
|
+ stmt = handler.prepare(connection, transaction.getTimeout());
|
|
|
+ if (stmt == null) {
|
|
|
+ return Collections.emptyList();
|
|
|
+ }
|
|
|
+ handler.parameterize(stmt);
|
|
|
+ return handler.query(stmt, resultHandler);
|
|
|
+ } finally {
|
|
|
+ closeStatement(stmt);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+}
|