2012-03-21 11 views
0

Webアプリケーションは、Entity Bean(ejb 2.0)を1つ使用し、データベースからオブジェクトを出力するページを1つ持っています。私はエンティティのすべてのメソッドを実装し、すべてのエラーをチェックしました。データベースにテーブルがあり、最初の100個のオブジェクト(IDとその名前)を出力しようとします。しかし、それは、エンティティBeanのそれは非現実的に遅い:( しようとしたいくつかの実装、百個のオブジェクトのための20秒を要し、結果は同じです。データベースから約100個のオブジェクトを画面に出力してください。

ます。private 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から呼び出されています。わかりませんが、おそらく問題はありますか?

+0

それとも誰もがよくwrightenエンティティBeanの例を与えることができますか?ベストプラクティスのようなsmt – golgofa

答えて

0

EJBメソッドは100オブジェクトをリストとして返しますか、 ?

EJ Bメソッド呼び出しは高価です。できるだけ多くのデータを1回の往復で梱包してください。

EJBコール内のコードをタイミングよく(より良い形でプロファイリングする)試行してください。あなたはJDBC呼び出しが高速であることを肯定しますか?

(私が代わりに正気と軽量化アーキテクチャの2012使用EJBであなたを作るものが求めていないよ、私はそれだけでレガシーシステム願っています)

関連する問題