Web 应用程序使用一个实体 Bean (ejb 2.0) 并有一个页面来从数据库中输出对象。我实现了实体中的所有方法,并检查了所有错误。我在数据库中有一个表并尝试输出前 100 个对象(id 及其名称)。但是一百个对象需要20秒,慢得不真实:(尝试了Entity Bean的几种实现,结果是一样的。
私有 void loadRow() 抛出 SQLException、NamingException、异常 {
try {
String selectStatement =
"select parent_id, object_type_id, object_class_id, project_id, picture_id, name, description, attr_schema_id, order_number, source_object_id, version\n"+
"from nc_objects where object_id = ?";
Map results = (Map) JDBCExecutor.execute(selectStatement, Arrays.asList(new Object[]{new BigDecimal(objectId)}), new ResultSetHandler() {
public Object onResultSet(ResultSet rs) throws Exception {
Map results = new HashMap();
if (rs.next()) {
results.put("parent_id", checkedValue(rs, 1));
results.put("object_type_id", checkedValue(rs, 2));
results.put("object_class_id", checkedValue(rs, 3));
results.put("project_id", checkedValue(rs, 4));
results.put("picture_id", checkedValue(rs, 5));
results.put("name", rs.getString(6));
results.put("description", rs.getString(7));
results.put("attr_schema_id", checkedValue(rs, 8));
results.put("order_number", checkedValue(rs, 9));
results.put("source_object_id", checkedValue(rs, 10));
results.put("version", checkedValue(rs, 11));
}
return results;
}
});
this.parentId = (BigInteger) results.get("parent_id");
this.objectTypeId = (BigInteger) results.get("object_type_id");
this.objectClassId = (BigInteger) results.get("object_class_id");
this.projectId = (BigInteger) results.get("project_id");
this.pictureId = (BigInteger) results.get("picture_id");
this.name = (String) results.get("name");
this.description = (String) results.get("description");
this.attrSchemaId = (BigInteger) results.get("attr_schema_id");
this.orderNumber = (BigInteger) results.get("order_number");
this.sourceObjectId = (BigInteger) results.get("source_object_id");
this.version = (BigInteger) results.get("version");
}
catch(Exception ex){
throw new Exception("My EXCEPTION; cannot load object_id = " + objectId, ex);
}
String selectStatement = "select object_id, attr_id, value, date_value, list_value_id, data "
+ " from nc_params\n"
+ "where object_id = ?";
params = (Map) JDBCExecutor.execute(selectStatement, Arrays.asList(new Object[]{new BigDecimal(objectId)}), new ResultSetHandler() {
public Object onResultSet(ResultSet rs) throws Exception {
Map results = new HashMap();
while(rs.next()){
if(rs.getString(3) != null)
results.put(checkedValue(rs, "attr_id"), rs.getString(3));
}
return results;
}
});
}
这是我的 loadRow 方法,它是从 ejbLoad 调用的。我不确定,但也许有麻烦吗?