ibatis-user-java mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Tony Qian" <daqiqi...@aol.com>
Subject Re: performnace of iBATIS
Date Tue, 28 Feb 2006 17:39:34 GMT
Here are more codes:

public class SmurfSqlConfig {

      private static SqlMapClient sqlMap = null;
      private static Logger logger = Logger.getLogger(SmurfSqlConfig.class);
      private SmurfSqlConfig(){
          // empty
      }

      // The Java system property name to look for when leveling
      private static final String SYSTEM_PROPERTY_NAME = "Level";
      private static final String sqlMapConfig = "sqlMapConfig.xml";
      static String level = System.getProperty(SYSTEM_PROPERTY_NAME);
      static{
           try {
                String sqlMapConfigFile = null;
                if (level == null){
                    sqlMapConfigFile = sqlMapConfig;
                }else{
                    sqlMapConfigFile = level + sqlMapConfig;
                }
                Reader sqlMapConfigReader = 
Resources.getResourceAsReader(sqlMapConfigFile);
                sqlMap = 
SqlMapClientBuilder.buildSqlMapClient(sqlMapConfigReader);
           } catch (IOException e) {
                logger.fatal ("Cannot access to sqlMapConfig.xml file " +
                                     e.getMessage( ) );
           }
      }
      public static SqlMapClient getSqlMapInstance(){
           return sqlMap;
      }
  }


//DAO

public class SessionParameterDAO extends AbstractSessionParameterDAO {

     /*
      * Implementation note:
      * This class implements the Singleton design pattern.  The 
constructor is
      * made private so that nobody can create an instance with the "new"
      * operator, and there is a public static method that is used to get an
      * instance of this class.  This way we can guarantee that only one
      * instance of this class is ever created.
      */

     private static Logger logger = 
Logger.getLogger(SessionParameterDAO.class);

     // Hold the singleton instance
     private static SessionParameterDAO instance = new 
SessionParameterDAO();
     private static SqlMapClient sqlMap = 
SmurfSqlConfig.getSqlMapInstance();

     /* (non-javadoc)
      * Constructor is private
      */
     private SessionParameterDAO() {
         // empty
     }

     /**
      * Return an instance of this class.
      * @return an instance of the SessionParameterDAO
      */
     public static SessionParameterDAO getInstance() {
         return instance;
     }

     /**
      * @throws DAOException Thrown for all SQL errors
      * @throws NotFoundException Thrown when there are no SQL errors, 
but the ResultSet
      * does not have any rows
      */

     protected List doFindAll()
         throws DAOException, NotFoundException {
         List list = null;

         try{
             list  = sqlMap.queryForList("getSessionParameterList", null);
         } catch (SQLException ex) {
             String msg = "SQLException - doFindAll - " + ex.getMessage();
             logger.error(msg, ex);
             throw new DAOException(msg, ex);
         }
         if ( list == null || list.size() == 0){
             throw new NotFoundException ("No Session Parameters were 
found");
         }
         return list;
     }


// SimpleSessionParameterList class

    /**
      * Constructs an immutable AbstractList of SimpleSessionParameter 
objects as
      * obtained via the SessionParameterDAO.
      */
     public SimpleSessionParameterList()
         throws DAOException, NotFoundException {

         sessionParameters = 
DAOFactory.getDefaultDAOFactory().getSessionParameterDAO().findAll();
     }

thanks,
Tony


Brandon Goodin wrote on 2/28/2006, 11:15 AM:

 > Please post all the code you use to test jdbc and ibatis. There are a
 > few mistakes that people can often make. One is that you don't perform
 > the resultset to object translation. The next is that the test could
 > be loading the sqlmap each time it is run. iBATIS will have initial
 > overhead because it is parsing and loading the sqlmaps into memory.
 >
 > Brandon
 >
 > On 2/28/06, Tony Qian <daqiqian2@aol.com> wrote:
 > >       Clinton and all,
 > >
 > >  Let me first thank you guys for quick response. I believe we have
 > the best
 > > tech support among open source community, either from iBATIS team or
 > from
 > > iBATIS users.
 > >
 > >  I used a very simple query which fetches all records in the table (72
 > > rows).  Here are some info for my test.
 > >
 > >  database: MySql 5.0, query cache is turned on.
 > >  iBATIS setting:
 > >
 > >   <settings cacheModelsEnabled="true"       // but no cache is set
 > for query
 > >     enhancementEnabled="true"
 > >     lazyLoadingEnabled="false"
 > >     maxRequests="32"
 > >     maxSessions="10"
 > >     maxTransactions="5"
 > >     useStatementNamespaces="false" />
 > >   <property name="Pool.PingEnabled" value="false"/>
 > >
 > >  xml mapping for query:
 > >    <typeAlias alias="sessionParameter"
 > >
 > 
type="com.netscape.isp.business.management.session.SimpleSessionParameter"/> 

 >
 > >    <select id="getSessionParameterList"
 > resultClass="sessionParameter" >
 > >      SELECT
 > >        parameter_id as parameterId,
 > >        parameter_name as name,
 > >        description as description
 > >      FROM SESSION_PARAMETER ORDER by parameter_name
 > >    </select>
 > >
 > >  Java code:
 > >          try{
 > >              long stime = System.currentTimeMillis();
 > >              Context ctx = new InitialContext();
 > >              DataSource dataSource = (DataSource)
 > > ctx.lookup("java:comp/env/jdbc/quickstart");
 > >              Connection connection = dataSource.getConnection();
 > >              Statement stmt = connection.createStatement();
 > >              String sql = "SELECT parameter_id, parameter_name,
 > description
 > > FROM SESSION_PARAMETER;" ;
 > >              stmt.execute(sql);
 > >              ResultSet rS = stmt.getResultSet();
 > >              List list = new ArrayList();
 > >              if (rS.first()) {
 > >                   do {
 > >                       list.add(new SimpleSessionParameter(
 > >                                rS.getString("parameter_id"),
 > >                                rS.getString("parameter_name"),
 > >                                rS.getString("description")));
 > >              } while (rS.next());
 > >              } else {
 > >                  throw new NotFoundException("no records were found");
 > >              }
 > >              rS.close();
 > >              stmt.close();
 > >              out.println("executing time is " +
 > (System.currentTimeMillis()
 > > - stime) +
 > >                    " current time =" +System.currentTimeMillis() + "
 > > startTime = " + stime);
 > >              stime = System.currentTimeMillis();
 > >              List parameter = new SimpleSessionParameterList();   //
 > > basically it calls "list  =
 > sqlMap.queryForList("getSessionParameterList",
 > > null);"
 > >              out.println("Ibatis executing time is " +
 > > (System.currentTimeMillis() - stime) +
 > >                                 " current time ="
 > > +System.currentTimeMillis() + "startTime = " + stime);
 > >         }catch (Exception e){
 > >              out.println(" get exception" + e.getMessage());
 > >        }
 > >
 > >
 > >  Test results:
 > >  JDBC executing time is 30 current time =1141136720755 startTime =
 > > 1141136720725
 > >  Ibatis executing time is 100 current time =1141136720855startTime =
 > > 1141136720755
 > >
 > >  JDBC executing time is 40 current time =1141136723448 startTime =
 > > 1141136723408
 > >  Ibatis executing time is 110 current time =1141136723558startTime =
 > > 1141136723448
 > >
 > >  JDBC executing time is 20 current time =1141136725741 startTime =
 > > 1141136725721
 > >  Ibatis executing time is 100 current time =1141136725841startTime =
 > > 1141136725741
 > >
 > >  executing time is 30 current time =1141137529882 startTime =
 > 1141137529852
 > >  Ibatis executing time is 101 current time =1141137529983startTime =
 > > 1141137529882
 > >
 > >  I appreciate your help.
 > >  Tony
 > >
 > >  Clinton Begin wrote on 2/28/2006, 1:59 AM:
 > >
 > >
 > >  Post your test code, and I'll show you what's wrong with it.
 > >
 > >  Clinton
 > >
 > >
 > >
 > > On 2/27/06, DaqiQian2@aol.com <DaqiQian2@aol.com> wrote:
 > >
 > > Sven,
 > >
 > >   thanks for your response. I did some preliminary test on iBATIS'
 > > performance. For JDBC (MySql 5.0), i recorded time from establishing
 > > connection, result set, and mapping the result to objects. For list of
 > > simple objects, it seems to me that iBATIS (no caching and
 > lazyloading) is
 > > 3-5 times slower than using JDBC. Of course, i believe my xml
 > mapping has
 > > room to improve.
 > >
 > >   The reason I asked is that I need some stats to persuade myself and
 > > coworkers to accept iBATIS as a data persistence tool for our
 > relatively
 > > heavily loaded servers.
 > >
 > >   btw, we just pushed a project using iBATIS to QE. For that project,
 > > performance is not big issue.
 > >
 > >   Thanks,
 > >   Tony
 > >
 > >
 >



Mime
View raw message