Web应用程序使用一个实体Bean(ejb 2.0),并有一个页面从数据库输出对象。我实现了实体中的所有方法,并检查了所有错误。我在数据库中有一个表,并尝试输出前100个对象(id和它们的名称)。但一百个物体需要20秒,速度很慢:(尝试了实体Bean的几个实现,结果是相同的。
private void loadRow()引发SQLException、NamingException、Exception{
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, versionn"+
"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_paramsn"
+ "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调用的。我不确定,但也许有麻烦?
EJB方法是以列表形式返回100个对象,还是每行调用100个?
EJB方法调用非常昂贵。尝试在一次往返中打包尽可能多的数据。
尝试对EJB调用中的代码进行计时(更好的是,对其进行分析)。你肯定JDBC调用是闪电般的快吗?
(我不是在问是什么让你在2012年使用EJB而不是更健康、更轻的体系结构;我希望它只是一个遗留系统。)