-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 
Author Message
 Post subject: Need help or best practice for optimizing a query
PostPosted: Thu May 06, 2010 12:20 pm 
Newbie

Joined: Thu May 06, 2010 12:04 pm
Posts: 1
Hi,

I have the following function:

Code:
   @SuppressWarnings("unchecked")
   public List<MenuDO> getMenuItems(Long groupID, Long userID, String filter)
   {
      System.out.println("-!-!-!- begin getMenuItems DAO -!-!-!-");
      List<MenuDO> result = new ArrayList<MenuDO>();
      Session session = null;
       try {
          session = getSession();
          int entityTypeUser = userID == 0 ? 0 : 2;
          int entityTypeGroup = groupID == 0 ? 0 : 1;
              
          Criteria crit = session.createCriteria(MenuDO.class);
          if (filter != "all") {
             boolean filterMe = filter.equalsIgnoreCase("t") ? true : false;
             crit = crit.add(Restrictions.eq("protectMe", filterMe));
          }
          crit = crit.createCriteria("commandOptionDO");
          Criterion entityUser = Restrictions.and(Restrictions.eq("entityID", userID),Restrictions.eq("entityTypeID", new Long(entityTypeUser)));
          Criterion entityGroup = Restrictions.and(Restrictions.eq("entityID", groupID),Restrictions.eq("entityTypeID", new Long(entityTypeGroup)));
          LogicalExpression orExp = Restrictions.or(entityUser,entityGroup);
          
          if (entityTypeUser != 0 && entityTypeGroup != 0) {
             crit.add(orExp);
          }
          else {
             if (entityTypeUser != 0) {
                crit.add(entityUser);
             }
             if (entityTypeGroup != 0) {
                crit.add(entityGroup);
             }
          }
          crit = crit.createCriteria("commandDO");
          crit = crit.createCriteria("applicationDO");
          crit = crit.add(Restrictions.eq("purchased", true));
          result = crit.list();
         session.close();
      }
       catch (DataAccessException ex) {
          session.close();
            logger.error("DataAccessException=" + ex);
            throw new PersistenceException(ex);          
       } 
       System.out.println("-!-!-!- end getMenuItems DAO -!-!-!-");
      return result;
   }


I have around 100,000 rows in my main table and the query takes around 3 seconds to run. I was just wondering if there is a better way to do this and achieve the same result faster.

Thanks


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.