简体   繁体   English

尝试从数据库输出到屏幕上约100个对象

[英]Try to output to the screen about 100 objects from database

Web application uses one Entity Bean (ejb 2.0) and has one page to output objects from database. Web应用程序使用一个Entity Bean(ejb 2.0),并具有一页从数据库输出对象的页面。 I implements all methods in entity been and checked all errors. 我在实体中实现了所有方法,并检查了所有错误。 I have a table in database and try to output first 100 objects (id's and their names). 我在数据库中有一个表,并尝试输出前100个对象(ID及其名称)。 But It takes 20 seconds for hundred objects, it' unreal slow:( Tried several implementations of Entity Bean, results are the same. 但是数百个对象要花费20秒的时间,这确实是缓慢的:(尝试了Entity Bean的几种实现,结果是相同的。

private void loadRow() throws SQLException, NamingException, Exception { 私人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, 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;
        }
    });
}

This is my loadRow method, that is called from ejbLoad. 这是我的loadRow方法,从ejbLoad调用。 I'm not sure, but maybe trouble is there? 我不确定,但是可能有麻烦吗?

Does your EJB method return 100 objects as a list, or do you make 100 calls, one per row? 您的EJB方法是否将100个对象作为列表返回,或者您进行100次调用(每行调用一次)?

EJB method calls are expensive. EJB方法调用很昂贵。 Try packing as much data as possible in one round-trip. 尝试在一次往返中打包尽可能多的数据。

Try timing (better yet, profiling) the code inside the EJB calls. 尝试计时(更好的是,分析)EJB调用中的代码。 Are you positive that the JDBC calls are lightning-fast? 您是否确定JDBC调用快如闪电?

(I'm not asking what makes you in 2012 use EJB instead of saner and lighter architectures; I hope it's just a legacy system.) (我不是在问什么让您在2012年使用EJB而不是更精简的体系结构;我希望它只是一个遗留系统。)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM