|
@@ -18,6 +18,9 @@ package com.baomidou.mybatisplus.extension;
|
|
|
import com.baomidou.mybatisplus.core.toolkit.StringUtils;
|
|
|
import com.baomidou.mybatisplus.extension.plugins.handler.TableNameHandler;
|
|
|
import net.sf.jsqlparser.schema.Table;
|
|
|
+import net.sf.jsqlparser.statement.create.index.CreateIndex;
|
|
|
+import net.sf.jsqlparser.statement.create.view.CreateView;
|
|
|
+import net.sf.jsqlparser.statement.drop.Drop;
|
|
|
import net.sf.jsqlparser.util.TablesNamesFinder;
|
|
|
|
|
|
import java.util.HashSet;
|
|
@@ -28,6 +31,7 @@ import java.util.Set;
|
|
|
* <p>1.无法保留sql注释(例如 select * from test; --这是个查询 处理完会变成 select * from test)</p>
|
|
|
* <p>2.无法保留语句分隔符;(例如 select * from test; 处理完会变成 select * from test )</p>
|
|
|
* <p>3.如果使用转义符包裹了表名需要自行处理</p>
|
|
|
+ * <p>4.select * from dual (不处理这个,自行忽略)</p>
|
|
|
*
|
|
|
* @author nieqiurong
|
|
|
* @since 3.5.11
|
|
@@ -46,6 +50,27 @@ public class DynamicTableNameHandler extends TablesNamesFinder<Void> {
|
|
|
init(false);
|
|
|
}
|
|
|
|
|
|
+ @Override
|
|
|
+ public <S> Void visit(CreateIndex createIndex, S context) {
|
|
|
+ return this.visit(createIndex.getTable(), context);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public <S> Void visit(Drop drop, S context) {
|
|
|
+ if(StringUtils.isNotBlank(drop.getType())){
|
|
|
+ String type = drop.getType().toUpperCase();
|
|
|
+ if ("TABLE".equals(type)) {
|
|
|
+ return super.visit(drop, context);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public <S> Void visit(CreateView createView, S context) {
|
|
|
+ return super.visit(createView.getSelect(), context);
|
|
|
+ }
|
|
|
+
|
|
|
@Override
|
|
|
protected String extractTableName(Table table) {
|
|
|
String originalTableName = table.getName();
|