Skip to content

Commit

Permalink
Fix issues encountered during functional testing
Browse files Browse the repository at this point in the history
Signed-off-by: hanbingleixue <[email protected]>
  • Loading branch information
hanbingleixue committed Mar 4, 2024
1 parent 481ae23 commit b36861b
Show file tree
Hide file tree
Showing 18 changed files with 253 additions and 179 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
import com.huaweicloud.sermant.opengaussv30.utils.QueryExecutorImplEnhancementHelper;

/**
* SQL执行器增强声明器
* QueryExecutorImpl declarer
*
* @author zhp
* @since 2024-02-04
Expand All @@ -35,6 +35,6 @@ public ClassMatcher getClassMatcher() {

@Override
public InterceptDeclarer[] getInterceptDeclarers(ClassLoader classLoader) {
return new InterceptDeclarer[]{QueryExecutorImplEnhancementHelper.getSendQueryInterceptDeclarer()};
return new InterceptDeclarer[]{QueryExecutorImplEnhancementHelper.getSendOneQueryInterceptDeclarer()};
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,15 @@
import com.huaweicloud.sermant.database.handler.DatabaseHandler;
import com.huaweicloud.sermant.database.interceptor.AbstractDatabaseInterceptor;

import org.opengauss.core.ParameterList;
import org.opengauss.core.Query;
import org.opengauss.core.v3.QueryExecutorImpl;
import org.opengauss.util.HostSpec;

import java.util.logging.Logger;

/**
* 执行SQL操作的拦截器
* Interceptor for QueryExecutorImpl sendOneQuery method
*
* @author zhp
* @since 2024-02-04
Expand All @@ -40,15 +41,15 @@ public class QueryExecutorImplInterceptor extends AbstractDatabaseInterceptor {
private static final Logger LOGGER = LoggerFactory.getLogger();

/**
* 无参构造方法
* Non-parametric construction method
*/
public QueryExecutorImplInterceptor() {
}

/**
* 有参构造方法
* Parameterized construction method
*
* @param handler 写操作处理器
* @param handler Write operation handler
*/
public QueryExecutorImplInterceptor(DatabaseHandler handler) {
this.handler = handler;
Expand All @@ -59,7 +60,7 @@ public ExecuteContext doBefore(ExecuteContext context) {
DatabaseInfo databaseInfo = getDataBaseInfo(context);
String database = databaseInfo.getDatabaseName();
Query query = (Query) context.getArguments()[0];
String sql = query.getNativeSql();
String sql = query.toString((ParameterList) context.getArguments()[1]);
handleWriteOperationIfWriteDisabled(sql, database,
DatabaseWriteProhibitionManager.getOpenGaussProhibitionDatabases(), context);
return context;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,67 +23,61 @@
import com.huaweicloud.sermant.opengaussv30.interceptors.QueryExecutorImplInterceptor;

/**
* postgresql拦截点辅助类
* Helper class for openGauss3.0.x
*
* @author zhp
* @since 2024-02-04
**/
public class QueryExecutorImplEnhancementHelper {
private static final String EXECUTE_METHOD_NAME = "sendQuery";
private static final String EXECUTE_METHOD_NAME = "sendOneQuery";

private static final String ENHANCE_CLASS_NAME = "org.opengauss.core.v3.QueryExecutorImpl";

private static final String INT_CLASS_NAME = "int";

private static final String QUERY_CLASS_NAME = "org.opengauss.core.Query";
private static final String SIMPLE_QUERY_CLASS_NAME = "org.opengauss.core.v3.SimpleQuery";

private static final String V3_PARAMETER_LIST_CLASS_NAME = "org.opengauss.core.v3.V3ParameterList";

private static final String RESULT_HANDLER_CLASS_NAME = "org.opengauss.core.ResultHandler";

private static final String BATCH_RESULT_HANDLER_CLASS_NAME = "org.opengauss.jdbc.BatchResultHandler";
private static final String SIMPLE_PARAMETER_LIST_CLASS_NAME = "org.opengauss.core.v3.SimpleParameterList";

private static final String[] EXECUTE_INTERNAL_METHOD_PARAMS_TYPE = {
QUERY_CLASS_NAME,
V3_PARAMETER_LIST_CLASS_NAME,
INT_CLASS_NAME,
SIMPLE_QUERY_CLASS_NAME,
SIMPLE_PARAMETER_LIST_CLASS_NAME,
INT_CLASS_NAME,
INT_CLASS_NAME,
RESULT_HANDLER_CLASS_NAME,
BATCH_RESULT_HANDLER_CLASS_NAME
INT_CLASS_NAME
};

private QueryExecutorImplEnhancementHelper() {
}

private static MethodMatcher getSendQueryMethodMatcher() {
private static MethodMatcher getSendOneQueryMethodMatcher() {
return MethodMatcher.nameEquals(EXECUTE_METHOD_NAME)
.and(MethodMatcher.paramTypesEqual(EXECUTE_INTERNAL_METHOD_PARAMS_TYPE));
}

/**
* 获取QueryExecutorImpl sendQuery方法有参拦截声明器
* Get the parameterized interceptor declarer for the QueryExecutorImpl sendOneQuery method
*
* @param handler 数据库自定义处理器
* @return InterceptDeclarer QueryExecutorImpl sendQuery方法有参拦截声明器
* @param handler Database custom handler
* @return InterceptDeclarer The parameterized interceptor declarer for the QueryExecutorImpl sendOneQuery method
*/
public static InterceptDeclarer getSendQueryInterceptDeclarer(DatabaseHandler handler) {
return InterceptDeclarer.build(getSendQueryMethodMatcher(), new QueryExecutorImplInterceptor(handler));
public static InterceptDeclarer getSendOneQueryInterceptDeclarer(DatabaseHandler handler) {
return InterceptDeclarer.build(getSendOneQueryMethodMatcher(), new QueryExecutorImplInterceptor(handler));
}

/**
* 获取QueryExecutorImpl sendQuery方法无参拦截声明器
* Get the non-parameter interceptor declarer for the QueryExecutorImpl sendOneQuery method
*
* @return InterceptDeclarer QueryExecutorImpl sendQuery方法无参拦截声明器
* @return InterceptDeclarer The non-parameter interceptor declarer for the QueryExecutorImpl sendOneQuery method
*/
public static InterceptDeclarer getSendQueryInterceptDeclarer() {
return InterceptDeclarer.build(getSendQueryMethodMatcher(), new QueryExecutorImplInterceptor());
public static InterceptDeclarer getSendOneQueryInterceptDeclarer() {
return InterceptDeclarer.build(getSendOneQueryMethodMatcher(), new QueryExecutorImplInterceptor());
}

/**
* 获取QueryExecutorImpl类的ClassMatcher
* Get the ClassMatcher of the QueryExecutorImpl class
*
* @return ClassMatcher 类匹配器
* @return ClassMatcher Class matcher
*/
public static ClassMatcher getQueryExecutorImplClassMatcher() {
return ClassMatcher.nameEquals(ENHANCE_CLASS_NAME);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
import com.huaweicloud.sermant.opengaussv31.utils.QueryExecutorImplEnhancementHelper;

/**
* SQL执行器增强声明器
* QueryExecutorImpl declarer
*
* @author zhp
* @since 2024-02-04
Expand All @@ -35,6 +35,6 @@ public ClassMatcher getClassMatcher() {

@Override
public InterceptDeclarer[] getInterceptDeclarers(ClassLoader classLoader) {
return new InterceptDeclarer[]{QueryExecutorImplEnhancementHelper.getSendQueryInterceptDeclarer()};
return new InterceptDeclarer[]{QueryExecutorImplEnhancementHelper.getSendOneQueryInterceptDeclarer()};
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,15 @@
import com.huaweicloud.sermant.database.handler.DatabaseHandler;
import com.huaweicloud.sermant.database.interceptor.AbstractDatabaseInterceptor;

import org.postgresql.core.ParameterList;
import org.postgresql.core.Query;
import org.postgresql.core.v3.QueryExecutorImpl;
import org.postgresql.util.HostSpec;

import java.util.logging.Logger;

/**
* 执行SQL操作的拦截器
* Interceptor for QueryExecutorImpl sendOneQuery method
*
* @author zhp
* @since 2024-02-04
Expand All @@ -40,15 +41,15 @@ public class QueryExecutorImplInterceptor extends AbstractDatabaseInterceptor {
private static final Logger LOGGER = LoggerFactory.getLogger();

/**
* 无参构造方法
* Non-parametric construction method
*/
public QueryExecutorImplInterceptor() {
}

/**
* 有参构造方法
* Parameterized construction method
*
* @param handler 写操作处理器
* @param handler Write operation handler
*/
public QueryExecutorImplInterceptor(DatabaseHandler handler) {
this.handler = handler;
Expand All @@ -59,7 +60,7 @@ public ExecuteContext doBefore(ExecuteContext context) {
DatabaseInfo databaseInfo = getDataBaseInfo(context);
String database = databaseInfo.getDatabaseName();
Query query = (Query) context.getArguments()[0];
String sql = query.getNativeSql();
String sql = query.toString((ParameterList) context.getArguments()[1]);
handleWriteOperationIfWriteDisabled(sql, database,
DatabaseWriteProhibitionManager.getOpenGaussProhibitionDatabases(), context);
return context;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,67 +23,61 @@
import com.huaweicloud.sermant.opengaussv31.interceptors.QueryExecutorImplInterceptor;

/**
* openGauss3.1.x拦截点辅助类
* Helper class for openGauss3.1.x
*
* @author zhp
* @since 2024-02-04
**/
public class QueryExecutorImplEnhancementHelper {
private static final String EXECUTE_METHOD_NAME = "sendQuery";
private static final String EXECUTE_METHOD_NAME = "sendOneQuery";

private static final String ENHANCE_CLASS_NAME = "org.postgresql.core.v3.QueryExecutorImpl";

private static final String INT_CLASS_NAME = "int";

private static final String QUERY_CLASS_NAME = "org.postgresql.core.Query";
private static final String SIMPLE_QUERY_CLASS_NAME = "org.postgresql.core.v3.SimpleQuery";

private static final String V3_PARAMETER_LIST_CLASS_NAME = "org.postgresql.core.v3.V3ParameterList";

private static final String RESULT_HANDLER_CLASS_NAME = "org.postgresql.core.ResultHandler";

private static final String BATCH_RESULT_HANDLER_CLASS_NAME = "org.postgresql.jdbc.BatchResultHandler";
private static final String SIMPLE_PARAMETER_LIST_CLASS_NAME = "org.postgresql.core.v3.SimpleParameterList";

private static final String[] EXECUTE_INTERNAL_METHOD_PARAMS_TYPE = {
QUERY_CLASS_NAME,
V3_PARAMETER_LIST_CLASS_NAME,
INT_CLASS_NAME,
SIMPLE_QUERY_CLASS_NAME,
SIMPLE_PARAMETER_LIST_CLASS_NAME,
INT_CLASS_NAME,
INT_CLASS_NAME,
RESULT_HANDLER_CLASS_NAME,
BATCH_RESULT_HANDLER_CLASS_NAME
INT_CLASS_NAME
};

private QueryExecutorImplEnhancementHelper() {
}

private static MethodMatcher getSendQueryMethodMatcher() {
private static MethodMatcher getSendOneQueryMethodMatcher() {
return MethodMatcher.nameEquals(EXECUTE_METHOD_NAME)
.and(MethodMatcher.paramTypesEqual(EXECUTE_INTERNAL_METHOD_PARAMS_TYPE));
}

/**
* 获取QueryExecutorImpl sendQuery方法有参拦截声明器
* Get the parameterized interceptor declarer for the QueryExecutorImpl sendOneQuery method
*
* @param handler 数据库自定义处理器
* @return InterceptDeclarer QueryExecutorImpl sendQuery方法有参拦截声明器
* @param handler Database custom handler
* @return InterceptDeclarer The parameterized interceptor declarer for the QueryExecutorImpl sendOneQuery method
*/
public static InterceptDeclarer getSendQueryInterceptDeclarer(DatabaseHandler handler) {
return InterceptDeclarer.build(getSendQueryMethodMatcher(), new QueryExecutorImplInterceptor(handler));
public static InterceptDeclarer getSendOneQueryInterceptDeclarer(DatabaseHandler handler) {
return InterceptDeclarer.build(getSendOneQueryMethodMatcher(), new QueryExecutorImplInterceptor(handler));
}

/**
* 获取QueryExecutorImpl sendQuery方法无参拦截声明器
* Get the non-parameter interceptor declarer for the QueryExecutorImpl sendOneQuery method
*
* @return InterceptDeclarer QueryExecutorImpl sendQuery方法无参拦截声明器
* @return InterceptDeclarer The non-parameter interceptor declarer for the QueryExecutorImpl sendOneQuery method
*/
public static InterceptDeclarer getSendQueryInterceptDeclarer() {
return InterceptDeclarer.build(getSendQueryMethodMatcher(), new QueryExecutorImplInterceptor());
public static InterceptDeclarer getSendOneQueryInterceptDeclarer() {
return InterceptDeclarer.build(getSendOneQueryMethodMatcher(), new QueryExecutorImplInterceptor());
}

/**
* 获取QueryExecutorImpl类的ClassMatcher
* Get the ClassMatcher of the QueryExecutorImpl class
*
* @return ClassMatcher 类匹配器
* @return ClassMatcher Class matcher
*/
public static ClassMatcher getQueryExecutorImplClassMatcher() {
return ClassMatcher.nameEquals(ENHANCE_CLASS_NAME);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
import com.huaweicloud.sermant.postgresqlv42.utils.QueryExecutorImplEnhancementHelper;

/**
* SQL执行器增强声明器
* QueryExecutorImpl declarer
*
* @author zhp
* @since 2024-02-04
Expand All @@ -35,6 +35,6 @@ public ClassMatcher getClassMatcher() {

@Override
public InterceptDeclarer[] getInterceptDeclarers(ClassLoader classLoader) {
return new InterceptDeclarer[]{QueryExecutorImplEnhancementHelper.getSendQueryInterceptDeclarer()};
return new InterceptDeclarer[]{QueryExecutorImplEnhancementHelper.getSendOneQueryInterceptDeclarer()};
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,15 @@
import com.huaweicloud.sermant.database.handler.DatabaseHandler;
import com.huaweicloud.sermant.database.interceptor.AbstractDatabaseInterceptor;

import org.postgresql.core.ParameterList;
import org.postgresql.core.Query;
import org.postgresql.core.v3.QueryExecutorImpl;
import org.postgresql.util.HostSpec;

import java.util.logging.Logger;

/**
* 执行SQL操作拦截器的测试类
* Interceptor for QueryExecutorImpl sendOneQuery method
*
* @author zhp
* @since 2024-02-04
Expand All @@ -40,15 +41,15 @@ public class QueryExecutorImplInterceptor extends AbstractDatabaseInterceptor {
private static final Logger LOGGER = LoggerFactory.getLogger();

/**
* 无参构造方法
* Non-parametric construction method
*/
public QueryExecutorImplInterceptor() {
}

/**
* 有参构造方法
* Parameterized construction method
*
* @param handler 写操作处理器
* @param handler Write operation handler
*/
public QueryExecutorImplInterceptor(DatabaseHandler handler) {
this.handler = handler;
Expand All @@ -59,7 +60,7 @@ public ExecuteContext doBefore(ExecuteContext context) {
DatabaseInfo databaseInfo = getDataBaseInfo(context);
String database = databaseInfo.getDatabaseName();
Query query = (Query) context.getArguments()[0];
String sql = query.toString();
String sql = query.toString((ParameterList) context.getArguments()[1]);
handleWriteOperationIfWriteDisabled(sql, database,
DatabaseWriteProhibitionManager.getPostgreSqlProhibitionDatabases(), context);
return context;
Expand Down
Loading

0 comments on commit b36861b

Please sign in to comment.