This is an automated email from the ASF dual-hosted git repository.
Aias00 pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/shenyu.git
The following commit(s) were added to refs/heads/master by this push:
new 0c0dfb5b47 fix(admin): order Oracle operation logs before applying the
row limit (#7739) (#7758)
0c0dfb5b47 is described below
commit 0c0dfb5b47746f9067f335e3a79a7ac590cc49b8
Author: konlue <[email protected]>
AuthorDate: Mon Oct 19 15:32:29 2026 +0800
fix(admin): order Oracle operation logs before applying the row limit
(#7739) (#7758)
---
.../mappers/operation-record-log-sqlmap.xml | 11 ++--
.../OperationRecordLogSelectLimitSqlTest.java | 58 ++++++++++++++++++++++
2 files changed, 65 insertions(+), 4 deletions(-)
diff --git
a/shenyu-admin/src/main/resources/mappers/operation-record-log-sqlmap.xml
b/shenyu-admin/src/main/resources/mappers/operation-record-log-sqlmap.xml
index 6440e37611..5b196e221b 100644
--- a/shenyu-admin/src/main/resources/mappers/operation-record-log-sqlmap.xml
+++ b/shenyu-admin/src/main/resources/mappers/operation-record-log-sqlmap.xml
@@ -56,14 +56,17 @@
</select>
<select id="selectLimit" parameterType="java.lang.Integer"
resultMap="BaseResultMap" databaseId="oracle">
+ SELECT * FROM (
SELECT
<include refid="Base_Column_List"/>
FROM operation_record_log
- where rownum <![CDATA[<=]]> #{limit}
- <if test="username != null">
- and operator = #{username}
- </if>
+ <where>
+ <if test="username != null">
+ operator = #{username}
+ </if>
+ </where>
order by operation_time desc
+ ) WHERE ROWNUM <![CDATA[<=]]> #{limit}
</select>
<select id="selectByCondition"
resultType="org.apache.shenyu.admin.model.entity.OperationRecordLog">
diff --git
a/shenyu-admin/src/test/java/org/apache/shenyu/admin/mapper/OperationRecordLogSelectLimitSqlTest.java
b/shenyu-admin/src/test/java/org/apache/shenyu/admin/mapper/OperationRecordLogSelectLimitSqlTest.java
new file mode 100644
index 0000000000..cb1bbd70cf
--- /dev/null
+++
b/shenyu-admin/src/test/java/org/apache/shenyu/admin/mapper/OperationRecordLogSelectLimitSqlTest.java
@@ -0,0 +1,58 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * 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 org.apache.shenyu.admin.mapper;
+
+import org.apache.ibatis.builder.xml.XMLMapperBuilder;
+import org.apache.ibatis.io.Resources;
+import org.apache.ibatis.mapping.BoundSql;
+import org.apache.ibatis.session.Configuration;
+import org.junit.jupiter.api.Test;
+
+import java.io.InputStream;
+import java.util.HashMap;
+import java.util.Locale;
+import java.util.Map;
+
+import static org.junit.jupiter.api.Assertions.assertTrue;
+
+/**
+ * Verifies the Oracle limited operation-log query orders before limiting.
+ */
+public final class OperationRecordLogSelectLimitSqlTest {
+
+ @Test
+ public void testSelectLimitOrdersBeforeApplyingRowLimit() throws Exception
{
+ Configuration configuration = new Configuration();
+ configuration.setDatabaseId("oracle");
+ try (InputStream in =
Resources.getResourceAsStream("mappers/operation-record-log-sqlmap.xml")) {
+ new XMLMapperBuilder(in, configuration,
+ "mappers/operation-record-log-sqlmap.xml",
configuration.getSqlFragments()).parse();
+ }
+ Map<String, Object> parameters = new HashMap<>();
+ parameters.put("username", "username");
+ parameters.put("limit", 10);
+ BoundSql boundSql = configuration
+
.getMappedStatement("org.apache.shenyu.admin.mapper.OperationRecordLogMapper.selectLimit")
+ .getBoundSql(parameters);
+ String sql =
boundSql.getSql().toLowerCase(Locale.ROOT).replaceAll("\\s+", " ").trim();
+ assertTrue(sql.contains("rownum <= ?"), sql);
+ assertTrue(sql.startsWith("select * from ("), sql);
+ assertTrue(sql.indexOf("order by") < sql.indexOf("rownum"), sql);
+ assertTrue(sql.contains("operator = ?"), sql);
+ }
+}