|
|
@@ -1,30 +1,47 @@
|
|
|
package com.tzld.videoVector.config.mybatis;
|
|
|
|
|
|
-import org.apache.ibatis.executor.statement.StatementHandler;
|
|
|
-import org.apache.ibatis.plugin.Interceptor;
|
|
|
-import org.apache.ibatis.plugin.Intercepts;
|
|
|
-import org.apache.ibatis.plugin.Invocation;
|
|
|
-import org.apache.ibatis.plugin.Signature;
|
|
|
+import org.apache.ibatis.executor.Executor;
|
|
|
+import org.apache.ibatis.mapping.MappedStatement;
|
|
|
+import org.apache.ibatis.plugin.*;
|
|
|
+import org.apache.ibatis.session.ResultHandler;
|
|
|
+import org.apache.ibatis.session.RowBounds;
|
|
|
+import org.slf4j.Logger;
|
|
|
+import org.slf4j.LoggerFactory;
|
|
|
|
|
|
import java.sql.Connection;
|
|
|
import java.sql.Statement;
|
|
|
+import java.util.Properties;
|
|
|
|
|
|
@Intercepts({
|
|
|
- @Signature(type = StatementHandler.class, method = "prepare", args = {Connection.class, Integer.class})
|
|
|
+ @Signature(type = Executor.class, method = "query",
|
|
|
+ args = {MappedStatement.class, Object.class, RowBounds.class, ResultHandler.class})
|
|
|
})
|
|
|
public class HnswEfSearchInterceptor implements Interceptor {
|
|
|
|
|
|
+ private static final Logger log = LoggerFactory.getLogger(HnswEfSearchInterceptor.class);
|
|
|
+
|
|
|
+ private volatile boolean logged;
|
|
|
+
|
|
|
@Override
|
|
|
public Object intercept(Invocation invocation) throws Throwable {
|
|
|
- Connection connection = (Connection) invocation.getArgs()[0];
|
|
|
+ Executor executor = (Executor) invocation.getTarget();
|
|
|
+ Connection connection = executor.getTransaction().getConnection();
|
|
|
try (Statement stmt = connection.createStatement()) {
|
|
|
stmt.execute("SET hnsw.ef_search = 200");
|
|
|
}
|
|
|
+ if (!logged) {
|
|
|
+ logged = true;
|
|
|
+ log.info("HnswEfSearchInterceptor activated: hnsw.ef_search = 200");
|
|
|
+ }
|
|
|
return invocation.proceed();
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
public Object plugin(Object target) {
|
|
|
- return org.apache.ibatis.plugin.Plugin.wrap(target, this);
|
|
|
+ return Plugin.wrap(target, this);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void setProperties(Properties properties) {
|
|
|
}
|
|
|
}
|