[英]How to sort strings in OQL
I have tried: 我努力了:
select sort(obj.displayName, 'lhs < rhs') from my.org.BusinessClass obj
and 和
select sort(obj.displayName, 'lhs.toString() < rhs.toString()') from my.org.BusinessClass obj
Both give me character array results, but none of them are sorted by String. 两者都给我字符数组结果,但是它们都没有按String排序。 I think it's sorting by object id. 我认为它是按对象ID排序的。
I have also tried: 我也尝试过:
select sort(obj.displayName, lhs < rhs) from my.org.BusinessClass obj
select sort(obj.displayName, lhs.toString() < rhs.toString()) from my.org.BusinessClass obj
But these result in errors because sort second argument is suppose to a string expression. 但是这些会导致错误,因为第二个参数必须放在字符串表达式中。
The examples on the VisualVM documentation are only for numbers: Analyzing a Heap Dump Using Object Query Language (OQL) VisualVM文档上的示例仅用于数字: 使用对象查询语言(OQL)分析堆转储
The class is structured as follows: 该类的结构如下:
package my.org;
public class BusinessClass {
private String displayName;
// rest of class omitted for brevity
}
You can use the following query to sort strings in OQL: 您可以使用以下查询对OQL中的字符串进行排序:
select sort(heap.objects('java.lang.String'), 'lhs.toString().localeCompare(rhs.toString())')
in your case use this OQL query to sort your business object by displayName: 在您的情况下,请使用以下OQL查询按displayName对业务对象进行排序:
select sort(heap.objects('my.org.BusinessClass'), 'lhs.displayName.toString().localeCompare(rhs.displayName.toString())')
if you want to see your business object and actual displayName in the output use this OQL query: 如果要在输出中查看业务对象和实际的displayName,请使用以下OQL查询:
select map(sort(heap.objects('my.org.BusinessClass'), 'lhs.displayName.toString().localeCompare(rhs.displayName.toString())'), 'toHtml(it)+" "+it.displayName.toString()')
This is the workaround I used: 这是我使用的解决方法:
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.