Skip to content

Commit 4ab6997

Browse files
committed
fix:context,maria json
1 parent db5a672 commit 4ab6997

3 files changed

Lines changed: 35 additions & 11 deletions

File tree

backend/framework/src/main/java/org/jumpserver/chen/framework/console/QueryConsole.java

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -84,15 +84,10 @@ public void onConnect(Connect connect) {
8484
try {
8585
var currentContext = this.getSqlActuator().getCurrentSchema();
8686

87-
if (StringUtils.isEmpty(currentContext) && !StringUtils.isEmpty(context)) {
87+
if (!StringUtils.isEmpty(context) && !StringUtils.equals(currentContext, context)) {
8888
this.getSqlActuator().changeSchema(context);
89-
this.getState().setCurrentContext(context);
90-
} else {
91-
if (!StringUtils.isEmpty(context) && !currentContext.equals(context)) {
92-
this.getSqlActuator().changeSchema(context);
93-
this.getState().setCurrentContext(context);
94-
}
9589
}
90+
this.getState().setCurrentContext(StringUtils.defaultIfEmpty(context, currentContext));
9691

9792
var schemas = this.getSqlActuator().getSchemas();
9893
this.getState().setContexts(schemas);

backend/framework/src/main/java/org/jumpserver/chen/framework/datasource/base/BaseSQLActuator.java

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,7 @@ private void executeStatement(SQLExecutePlan plan, Statement statement, SQLQuery
195195
List<Object> fs = new ArrayList<>();
196196
for (int i = 1; i <= columnCount; i++) {
197197
try {
198-
fs.add(this.normalizeJdbcValue(resultSet.getObject(i)));
198+
fs.add(this.normalizeJdbcValue(resultSet, i));
199199
} catch (NoClassDefFoundError e) {
200200
log.error(e.getMessage());
201201
}
@@ -222,11 +222,19 @@ private void executeStatement(SQLExecutePlan plan, Statement statement, SQLQuery
222222
}
223223
}
224224

225+
protected Object normalizeJdbcValue(ResultSet resultSet, int columnIndex) throws SQLException {
226+
return this.normalizeJdbcValue(resultSet.getObject(columnIndex));
227+
}
228+
225229
protected Object normalizeJdbcValue(Object value) throws SQLException {
226230
if (value == null) {
227231
return null;
228232
}
229233

234+
if (value.getClass().getName().equals("oracle.sql.TIMESTAMPTZ")) {
235+
return this.normalizeOracleTimestampWithTimeZone(value);
236+
}
237+
230238
var temporalValue = this.formatTemporalValue(value);
231239
if (temporalValue != null) {
232240
return temporalValue;
@@ -257,9 +265,6 @@ protected Object normalizeJdbcValue(Object value) throws SQLException {
257265
}
258266

259267
if (value instanceof Blob blob) {
260-
if (blob.getClass().getName().equals("oracle.sql.BLOB")) {
261-
return blob.toString();
262-
}
263268
return HexUtils.bytesToHex(blob.getBytes(1, (int) blob.length()));
264269
}
265270

@@ -274,6 +279,19 @@ protected Object normalizeJdbcValue(Object value) throws SQLException {
274279
return value;
275280
}
276281

282+
private String normalizeOracleTimestampWithTimeZone(Object value) throws SQLException {
283+
try {
284+
var offsetDateTime = value.getClass().getMethod("toOffsetDateTime").invoke(value);
285+
return OFFSET_DATE_TIME_DISPLAY_FORMATTER.format((OffsetDateTime) offsetDateTime);
286+
} catch (ReflectiveOperationException | ClassCastException e) {
287+
var cause = e.getCause() == null ? e : e.getCause();
288+
if (cause instanceof SQLException sqlException) {
289+
throw sqlException;
290+
}
291+
throw new SQLException("normalize Oracle TIMESTAMP WITH TIME ZONE failed", cause);
292+
}
293+
}
294+
277295
private String formatTemporalValue(Object value) {
278296
if (value instanceof Timestamp timestamp) {
279297
return LOCAL_DATE_TIME_DISPLAY_FORMATTER.format(timestamp.toLocalDateTime());

backend/modules/src/main/java/org.jumpserver.chen.modules/mariadb/MariaDBActuator.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
import org.jumpserver.chen.modules.mysql.MysqlActuator;
55

66
import java.sql.Connection;
7+
import java.sql.ResultSet;
8+
import java.sql.SQLException;
79

810
public class MariaDBActuator extends MysqlActuator {
911
public MariaDBActuator(ConnectionManager connectionManager) {
@@ -12,4 +14,13 @@ public MariaDBActuator(ConnectionManager connectionManager) {
1214
public MariaDBActuator(MariaDBActuator sqlActuator, Connection connection) {
1315
super(sqlActuator, connection);
1416
}
17+
18+
@Override
19+
protected Object normalizeJdbcValue(ResultSet resultSet, int columnIndex) throws SQLException {
20+
var columnTypeName = resultSet.getMetaData().getColumnTypeName(columnIndex);
21+
if ("JSON".equalsIgnoreCase(columnTypeName) || "MYSQL_JSON".equalsIgnoreCase(columnTypeName)) {
22+
return resultSet.getString(columnIndex);
23+
}
24+
return super.normalizeJdbcValue(resultSet, columnIndex);
25+
}
1526
}

0 commit comments

Comments
 (0)