我有一个内存转储文件,其中包含特定对象的近5000个实例。这些对象将被写入数据库,而我执行此操作的方式是在jvisualvm中编写OQL查询以生成将用作例如SQL插入的字符串
select "insert into trades (id, tradeNumber) values ("+ x.id+ ", " + x.tradeNumber +");" from com.test.application.TradeObject x;
当我通过OQL运行此命令时,会得到如下结果集-
<code>
insert into trades (id, tradeNumber) values (1,12345);
insert into trades (id, tradeNumber) values (2,123456);
insert into trades (id, tradeNumber) values (3,123457); </code>
等等
但是,由于实例总数很大(大约5000个),因此JvisualVM仅显示其中的100个。然后出现错误消息“结果太多。请优化查询”。
我无法优化查询,因为我必须以这种方式解析所有实例。
有没有一种方法可以要求JvisualVM向我显示所有实例,而不限制结果的数量?
我还看到Jvisual vm显示了前100个实例,没有任何过滤器,是否可以通过OQL查询获取后100个实例,依此类推?
谢谢
最佳答案
我找不到jvisualVm中的任何设置来增加结果集的大小。可能不是那样的。
它看起来像Jvisualvm代码库中的硬编码限制。参考:http://visualvm.sourcearchive.com/documentation/1.3/OQLController_8java-source.html
在下面找到以下代码片段:
final AtomicInteger counter = new AtomicInteger(100);
和
if (counter.get() == 0) {
sb.append("<tr><td><h4>Too many results. Please, refine your query.</h4></td></tr>" );
} else if (counter.get() == 100) {
sb.append("<tr><td><h4>"); // NOI18N
sb.append(NbBundle.getMessage(OQLController.class, "OQL_NO_RESULTS_MSG")); // NOI18N
sb.append("</h4></td></tr>" ); // NOI18N
}
现在,有趣的部分是解决您的问题的方法。
考虑下面的类:
package com.demo.test;
class Xyz {
int idXyz;// intentionally not set as id
String value;
public Xyz(int idXyz, String value) {
this.idXyz = idXyz;
this.value = value;
}
}
现在说我有105个该类的对象,存储在类似以下的列表中:
static List<Xyz> lst = new ArrayList<>();
for (int i = 0; i < 105; i++) {
lst.add(new Xyz( i,"xyz value-" + i));
}
我需要实现您的工作。
现在要显示这105个对象,而不是列出所有结果集,我宁愿遍历所有对象并创建一个包含所有用新行分隔的SQL查询的字符串。为此,您需要在
Query Editor
中调用类似的OQL脚本。function fun(objEnumeration){
var res =" ";
while (objEnumeration.hasMoreElements()) {
var itr = objEnumeration.nextElement();
var v = "insert into table_Xyz (idXyz, value) values ("+ itr.idXyz.toString()+ ", " + itr.value.toString() +");\n"
res = res + v;
}
return res;
}
fun(heap.objects("com.demo.test.Xyz"));
并且
Query Results
选项卡中的结果将是:insert into table_Xyz (idXyz, value) values (104, xyz value-104);
insert into table_Xyz (idXyz, value) values (103, xyz value-103);
insert into table_Xyz (idXyz, value) values (102, xyz value-102);
insert into table_Xyz (idXyz, value) values (101, xyz value-101);
insert into table_Xyz (idXyz, value) values (100, xyz value-100);
insert into table_Xyz (idXyz, value) values (99, xyz value-99);
insert into table_Xyz (idXyz, value) values (98, xyz value-98);
insert into table_Xyz (idXyz, value) values (97, xyz value-97);
insert into table_Xyz (idXyz, value) values (96, xyz value-96);
insert into table_Xyz (idXyz, value) values (95, xyz value-95);
insert into table_Xyz (idXyz, value) values (94, xyz value-94);
insert into table_Xyz (idXyz, value) values (93, xyz value-93);
insert into table_Xyz (idXyz, value) values (92, xyz value-92);
insert into table_Xyz (idXyz, value) values (91, xyz value-91);
insert into table_Xyz (idXyz, value) values (90, xyz value-90);
insert into table_Xyz (idXyz, value) values (89, xyz value-89);
insert into table_Xyz (idXyz, value) values (88, xyz value-88);
insert into table_Xyz (idXyz, value) values (87, xyz value-87);
insert into table_Xyz (idXyz, value) values (86, xyz value-86);
insert into table_Xyz (idXyz, value) values (85, xyz value-85);
insert into table_Xyz (idXyz, value) values (84, xyz value-84);
insert into table_Xyz (idXyz, value) values (83, xyz value-83);
insert into table_Xyz (idXyz, value) values (82, xyz value-82);
insert into table_Xyz (idXyz, value) values (81, xyz value-81);
insert into table_Xyz (idXyz, value) values (80, xyz value-80);
insert into table_Xyz (idXyz, value) values (79, xyz value-79);
insert into table_Xyz (idXyz, value) values (78, xyz value-78);
insert into table_Xyz (idXyz, value) values (77, xyz value-77);
insert into table_Xyz (idXyz, value) values (76, xyz value-76);
insert into table_Xyz (idXyz, value) values (75, xyz value-75);
insert into table_Xyz (idXyz, value) values (74, xyz value-74);
insert into table_Xyz (idXyz, value) values (73, xyz value-73);
insert into table_Xyz (idXyz, value) values (72, xyz value-72);
insert into table_Xyz (idXyz, value) values (71, xyz value-71);
insert into table_Xyz (idXyz, value) values (70, xyz value-70);
insert into table_Xyz (idXyz, value) values (69, xyz value-69);
insert into table_Xyz (idXyz, value) values (68, xyz value-68);
insert into table_Xyz (idXyz, value) values (67, xyz value-67);
insert into table_Xyz (idXyz, value) values (66, xyz value-66);
insert into table_Xyz (idXyz, value) values (65, xyz value-65);
insert into table_Xyz (idXyz, value) values (64, xyz value-64);
insert into table_Xyz (idXyz, value) values (63, xyz value-63);
insert into table_Xyz (idXyz, value) values (62, xyz value-62);
insert into table_Xyz (idXyz, value) values (61, xyz value-61);
insert into table_Xyz (idXyz, value) values (60, xyz value-60);
insert into table_Xyz (idXyz, value) values (59, xyz value-59);
insert into table_Xyz (idXyz, value) values (58, xyz value-58);
insert into table_Xyz (idXyz, value) values (57, xyz value-57);
insert into table_Xyz (idXyz, value) values (56, xyz value-56);
insert into table_Xyz (idXyz, value) values (55, xyz value-55);
insert into table_Xyz (idXyz, value) values (54, xyz value-54);
insert into table_Xyz (idXyz, value) values (53, xyz value-53);
insert into table_Xyz (idXyz, value) values (52, xyz value-52);
insert into table_Xyz (idXyz, value) values (51, xyz value-51);
insert into table_Xyz (idXyz, value) values (50, xyz value-50);
insert into table_Xyz (idXyz, value) values (49, xyz value-49);
insert into table_Xyz (idXyz, value) values (48, xyz value-48);
insert into table_Xyz (idXyz, value) values (47, xyz value-47);
insert into table_Xyz (idXyz, value) values (46, xyz value-46);
insert into table_Xyz (idXyz, value) values (45, xyz value-45);
insert into table_Xyz (idXyz, value) values (44, xyz value-44);
insert into table_Xyz (idXyz, value) values (43, xyz value-43);
insert into table_Xyz (idXyz, value) values (42, xyz value-42);
insert into table_Xyz (idXyz, value) values (41, xyz value-41);
insert into table_Xyz (idXyz, value) values (40, xyz value-40);
insert into table_Xyz (idXyz, value) values (39, xyz value-39);
insert into table_Xyz (idXyz, value) values (38, xyz value-38);
insert into table_Xyz (idXyz, value) values (37, xyz value-37);
insert into table_Xyz (idXyz, value) values (36, xyz value-36);
insert into table_Xyz (idXyz, value) values (35, xyz value-35);
insert into table_Xyz (idXyz, value) values (34, xyz value-34);
insert into table_Xyz (idXyz, value) values (33, xyz value-33);
insert into table_Xyz (idXyz, value) values (32, xyz value-32);
insert into table_Xyz (idXyz, value) values (31, xyz value-31);
insert into table_Xyz (idXyz, value) values (30, xyz value-30);
insert into table_Xyz (idXyz, value) values (29, xyz value-29);
insert into table_Xyz (idXyz, value) values (28, xyz value-28);
insert into table_Xyz (idXyz, value) values (27, xyz value-27);
insert into table_Xyz (idXyz, value) values (26, xyz value-26);
insert into table_Xyz (idXyz, value) values (25, xyz value-25);
insert into table_Xyz (idXyz, value) values (24, xyz value-24);
insert into table_Xyz (idXyz, value) values (23, xyz value-23);
insert into table_Xyz (idXyz, value) values (22, xyz value-22);
insert into table_Xyz (idXyz, value) values (21, xyz value-21);
insert into table_Xyz (idXyz, value) values (20, xyz value-20);
insert into table_Xyz (idXyz, value) values (19, xyz value-19);
insert into table_Xyz (idXyz, value) values (18, xyz value-18);
insert into table_Xyz (idXyz, value) values (17, xyz value-17);
insert into table_Xyz (idXyz, value) values (16, xyz value-16);
insert into table_Xyz (idXyz, value) values (15, xyz value-15);
insert into table_Xyz (idXyz, value) values (14, xyz value-14);
insert into table_Xyz (idXyz, value) values (13, xyz value-13);
insert into table_Xyz (idXyz, value) values (12, xyz value-12);
insert into table_Xyz (idXyz, value) values (11, xyz value-11);
insert into table_Xyz (idXyz, value) values (10, xyz value-10);
insert into table_Xyz (idXyz, value) values (9, xyz value-9);
insert into table_Xyz (idXyz, value) values (8, xyz value-8);
insert into table_Xyz (idXyz, value) values (7, xyz value-7);
insert into table_Xyz (idXyz, value) values (6, xyz value-6);
insert into table_Xyz (idXyz, value) values (5, xyz value-5);
insert into table_Xyz (idXyz, value) values (4, xyz value-4);
insert into table_Xyz (idXyz, value) values (3, xyz value-3);
insert into table_Xyz (idXyz, value) values (2, xyz value-2);
insert into table_Xyz (idXyz, value) values (1, xyz value-1);
insert into table_Xyz (idXyz, value) values (0, xyz value-0);
只需修改OQL脚本即可满足您的要求。
注意:在类Xyz中,字段idXyz是
intentionally not set as id
,因为在这种情况下itr.id
将返回与该实例关联的对象ID。有关OQL方法的更多信息,请参考:http://visualvm.java.net/oqlhelp.html#toHtml