[ 1711633 ] Speedup for main panel - don't look activities every time

This commit is contained in:
Heng Sin Low 2008-01-14 05:01:45 +00:00
parent 75080daea3
commit c937785ed0
2 changed files with 60 additions and 1 deletions

View File

@ -658,7 +658,7 @@ public final class AMenu extends CFrame
int notes = getNotes();
bNotes.setText(Msg.translate(m_ctx, "AD_Note_ID") + ": " + notes);
// Activities
int activities = wfActivity.loadActivities();
int activities = wfActivity.getActivitiesCount();
centerPane.setTitleAt(m_tabActivities, Msg.getMsg (m_ctx, "WorkflowActivities") + ": " + activities);
//
log.config(msg
@ -699,7 +699,10 @@ public final class AMenu extends CFrame
//updateInfo();
// show activities
if (centerPane.getSelectedIndex() == m_tabActivities)
{
wfActivity.loadActivities();
wfActivity.display();
}
} // stateChanged
public WindowManager getWindowManager() {

View File

@ -262,6 +262,62 @@ public class WFActivity extends CPanel
m_frame = null;
} // dispose
/**
* Get active activities count
* @return int
*/
public int getActivitiesCount()
{
int count = 0;
String sql = "SELECT count(*) FROM AD_WF_Activity a "
+ "WHERE a.Processed='N' AND a.WFState='OS' AND ("
// Owner of Activity
+ " a.AD_User_ID=?" // #1
// Invoker (if no invoker = all)
+ " OR EXISTS (SELECT * FROM AD_WF_Responsible r WHERE a.AD_WF_Responsible_ID=r.AD_WF_Responsible_ID"
+ " AND COALESCE(r.AD_User_ID,0)=0 AND COALESCE(r.AD_Role_ID,0)=0 AND (a.AD_User_ID=? OR a.AD_User_ID IS NULL))" // #2
// Responsible User
+ " OR EXISTS (SELECT * FROM AD_WF_Responsible r WHERE a.AD_WF_Responsible_ID=r.AD_WF_Responsible_ID"
+ " AND r.AD_User_ID=?)" // #3
// Responsible Role
+ " OR EXISTS (SELECT * FROM AD_WF_Responsible r INNER JOIN AD_User_Roles ur ON (r.AD_Role_ID=ur.AD_Role_ID)"
+ " WHERE a.AD_WF_Responsible_ID=r.AD_WF_Responsible_ID AND ur.AD_User_ID=?)" // #4
//
+ ") ORDER BY a.Priority DESC, Created";
int AD_User_ID = Env.getAD_User_ID(Env.getCtx());
PreparedStatement pstmt = null;
try
{
pstmt = DB.prepareStatement (sql, null);
pstmt.setInt (1, AD_User_ID);
pstmt.setInt (2, AD_User_ID);
pstmt.setInt (3, AD_User_ID);
pstmt.setInt (4, AD_User_ID);
ResultSet rs = pstmt.executeQuery ();
if (rs.next ()) {
count = rs.getInt(1);
}
rs.close();
}
catch (Exception e)
{
log.log(Level.SEVERE, sql, e);
}
try
{
if (pstmt != null)
pstmt.close ();
pstmt = null;
}
catch (Exception e)
{
pstmt = null;
}
return count;
}
/**
* Load Activities