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