IDEMPIERE-530 improve performance to enable attachments and chat buttons (Thanks to Juliana Corredor)

This commit is contained in:
Carlos Ruiz 2012-12-17 17:00:28 -05:00
parent 2e5fb7c33f
commit 565b5b0dca
9 changed files with 77 additions and 148 deletions

View File

@ -0,0 +1,6 @@
CREATE UNIQUE INDEX cm_chat_record ON cm_chat (ad_table_id, record_id);
SELECT register_migration_script('201212131100_IDEMPIERE-530.sql') FROM dual
;

View File

@ -0,0 +1,6 @@
CREATE UNIQUE INDEX cm_chat_record ON cm_chat (ad_table_id, record_id);
SELECT register_migration_script('201212131100_IDEMPIERE-530.sql') FROM dual
;

View File

@ -28,7 +28,6 @@ import java.sql.SQLException;
import java.sql.Timestamp; import java.sql.Timestamp;
import java.text.MessageFormat; import java.text.MessageFormat;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Properties; import java.util.Properties;
import java.util.StringTokenizer; import java.util.StringTokenizer;
@ -111,7 +110,7 @@ public class GridTab implements DataStatusListener, Evaluatee, Serializable
/** /**
* *
*/ */
private static final long serialVersionUID = 336562925897569888L; private static final long serialVersionUID = -1638364577972806113L;
public static final String DEFAULT_STATUS_MESSAGE = "NavigateOrUpdate"; public static final String DEFAULT_STATUS_MESSAGE = "NavigateOrUpdate";
@ -163,10 +162,6 @@ public class GridTab implements DataStatusListener, Evaluatee, Serializable
private String m_parentColumnName = ""; private String m_parentColumnName = "";
private String m_extendedWhere; private String m_extendedWhere;
/** Attachments */
private HashMap<Integer,Integer> m_Attachments = null;
/** Chats */
private HashMap<Integer,Integer> m_Chats = null;
/** Locks */ /** Locks */
private ArrayList<Integer> m_Lock = null; private ArrayList<Integer> m_Lock = null;
@ -333,12 +328,6 @@ public class GridTab implements DataStatusListener, Evaluatee, Serializable
// //
m_depOnField.clear(); m_depOnField.clear();
m_depOnField = null; m_depOnField = null;
if (m_Attachments != null)
m_Attachments.clear();
m_Attachments = null;
if (m_Chats != null)
m_Chats.clear();
m_Chats = null;
// //
if (m_vo.isInitFields()) if (m_vo.isInitFields())
m_vo.getFields().clear(); m_vo.getFields().clear();
@ -2034,43 +2023,6 @@ public class GridTab implements DataStatusListener, Evaluatee, Serializable
} // loadDependentInfo } // loadDependentInfo
/**************************************************************************
* Load Attachments for this table
*/
public void loadAttachments()
{
log.fine("#" + m_vo.TabNo);
if (!canHaveAttachment())
return;
String SQL = "SELECT AD_Attachment_ID, Record_ID FROM AD_Attachment "
+ "WHERE AD_Table_ID=?";
try
{
if (m_Attachments == null)
m_Attachments = new HashMap<Integer,Integer>();
else
m_Attachments.clear();
PreparedStatement pstmt = DB.prepareStatement(SQL, null);
pstmt.setInt(1, m_vo.AD_Table_ID);
ResultSet rs = pstmt.executeQuery();
while (rs.next())
{
Integer key = new Integer(rs.getInt(2));
Integer value = new Integer(rs.getInt(1));
m_Attachments.put(key, value);
}
rs.close();
pstmt.close();
}
catch (SQLException e)
{
log.log(Level.SEVERE, "loadAttachments", e);
}
log.config("#" + m_Attachments.size());
} // loadAttachment
/** /**
* Can this tab have Attachments?. * Can this tab have Attachments?.
* <p> * <p>
@ -2091,13 +2043,7 @@ public class GridTab implements DataStatusListener, Evaluatee, Serializable
*/ */
public boolean hasAttachment() public boolean hasAttachment()
{ {
if (m_Attachments == null) return getAD_AttachmentID() > 0;
loadAttachments();
if (m_Attachments == null || m_Attachments.isEmpty())
return false;
//
Integer key = new Integer(m_mTable.getKeyID (m_currentRow));
return m_Attachments.containsKey(key);
} // hasAttachment } // hasAttachment
/** /**
@ -2106,54 +2052,11 @@ public class GridTab implements DataStatusListener, Evaluatee, Serializable
*/ */
public int getAD_AttachmentID() public int getAD_AttachmentID()
{ {
if (m_Attachments == null)
loadAttachments();
if (m_Attachments.isEmpty())
return 0;
//
Integer key = new Integer(m_mTable.getKeyID (m_currentRow));
Integer value = (Integer)m_Attachments.get(key);
if (value == null)
return 0;
else
return value.intValue();
} // getAttachmentID
/**************************************************************************
* Load Chats for this table
*/
public void loadChats()
{
log.fine("#" + m_vo.TabNo);
if (!canHaveAttachment()) if (!canHaveAttachment())
return; return 0;
int recordID = m_mTable.getKeyID(m_currentRow);
String sql = "SELECT CM_Chat_ID, Record_ID FROM CM_Chat " return MAttachment.getID(m_vo.AD_Table_ID, recordID);
+ "WHERE AD_Table_ID=?"; } // getAttachmentID
try
{
if (m_Chats == null)
m_Chats = new HashMap<Integer,Integer>();
else
m_Chats.clear();
PreparedStatement pstmt = DB.prepareStatement(sql, null);
pstmt.setInt(1, m_vo.AD_Table_ID);
ResultSet rs = pstmt.executeQuery();
while (rs.next())
{
Integer key = new Integer(rs.getInt(2)); // Record_ID
Integer value = new Integer(rs.getInt(1)); // CM_Chat_ID
m_Chats.put(key, value);
}
rs.close();
pstmt.close();
}
catch (SQLException e)
{
log.log(Level.SEVERE, sql, e);
}
log.config("#" + m_Chats.size());
} // loadChats
/** /**
* Returns true, if current row has a Chat * Returns true, if current row has a Chat
@ -2161,13 +2064,7 @@ public class GridTab implements DataStatusListener, Evaluatee, Serializable
*/ */
public boolean hasChat() public boolean hasChat()
{ {
if (m_Chats == null) return getCM_ChatID() > 0;
loadChats();
if (m_Chats == null || m_Chats.isEmpty())
return false;
//
Integer key = new Integer(m_mTable.getKeyID (m_currentRow));
return m_Chats.containsKey(key);
} // hasChat } // hasChat
/** /**
@ -2176,17 +2073,10 @@ public class GridTab implements DataStatusListener, Evaluatee, Serializable
*/ */
public int getCM_ChatID() public int getCM_ChatID()
{ {
if (m_Chats == null) if (!canHaveAttachment())
loadChats();
if (m_Chats.isEmpty())
return 0; return 0;
// int recordID = m_mTable.getKeyID(m_currentRow);
Integer key = new Integer(m_mTable.getKeyID (m_currentRow)); return MChat.getID(m_vo.AD_Table_ID, recordID);
Integer value = (Integer)m_Chats.get(key);
if (value == null)
return 0;
else
return value.intValue();
} // getCM_ChatID } // getCM_ChatID

View File

@ -26,6 +26,7 @@ import java.util.Properties;
import java.util.logging.Level; import java.util.logging.Level;
import org.compiere.util.CLogger; import org.compiere.util.CLogger;
import org.compiere.util.DB;
import org.compiere.util.Env; import org.compiere.util.Env;
import org.compiere.util.MimeType; import org.compiere.util.MimeType;
@ -47,7 +48,7 @@ public class MAttachment extends X_AD_Attachment
/** /**
* *
*/ */
private static final long serialVersionUID = -8013716602070647299L; private static final long serialVersionUID = -8261865873158774665L;
/** /**
* Get Attachment (if there are more than one attachment it gets the first in no specific order) * Get Attachment (if there are more than one attachment it gets the first in no specific order)
@ -94,9 +95,7 @@ public class MAttachment extends X_AD_Attachment
*/ */
public MAttachment(Properties ctx, int AD_Table_ID, int Record_ID, String trxName) public MAttachment(Properties ctx, int AD_Table_ID, int Record_ID, String trxName)
{ {
this (ctx this (ctx, MAttachment.getID(AD_Table_ID, Record_ID) > 0 ? MAttachment.getID(AD_Table_ID, Record_ID) : 0, trxName);
, MAttachment.get(ctx, AD_Table_ID, Record_ID) == null ? 0 : MAttachment.get(ctx, AD_Table_ID, Record_ID).get_ID()
, trxName);
if (get_ID() == 0) { if (get_ID() == 0) {
setAD_Table_ID (AD_Table_ID); setAD_Table_ID (AD_Table_ID);
setRecord_ID (Record_ID); setRecord_ID (Record_ID);
@ -598,4 +597,17 @@ public class MAttachment extends X_AD_Attachment
return true; return true;
} }
/**
* IDEMPIERE-530
* Get the attachment ID based on table_id and record_id
* @param AD_Table_ID
* @param Record_ID
* @return AD_Attachment_ID
*/
public static int getID(int Table_ID, int Record_ID) {
String sql="SELECT AD_Attachment_ID FROM AD_Attachment WHERE AD_Table_ID=? AND Record_ID=?";
int attachid = DB.getSQLValue(null, sql, Table_ID, Record_ID);
return attachid;
}
} // MAttachment } // MAttachment

View File

@ -44,8 +44,7 @@ public class MChat extends X_CM_Chat
/** /**
* *
*/ */
private static final long serialVersionUID = -5053130533036069784L; private static final long serialVersionUID = 9165439123618441913L;
/** /**
* Get Chats Of Table - of client in context * Get Chats Of Table - of client in context
@ -242,5 +241,17 @@ public class MChat extends X_CM_Chat
return history; return history;
} // getHistory } // getHistory
/**
* IDEMPIERE-530
* Get the chat ID based on table_id and record_id
* @param AD_Table_ID
* @param Record_ID
* @return CM_Chat_ID
*/
public static int getID(int Table_ID, int Record_ID) {
String sql="SELECT CM_Chat_ID FROM CM_Chat WHERE AD_Table_ID=? AND Record_ID=?";
int chatID = DB.getSQLValueEx(null, sql, Table_ID, Record_ID);
return chatID;
}
} // MChat } // MChat

View File

@ -2304,11 +2304,10 @@ public final class APanel extends CPanel
return; return;
} }
// Attachment va = @SuppressWarnings("unused")
new Attachment (AEnv.getFrame(this), m_curWindowNo, Attachment va = new Attachment (AEnv.getFrame(this), m_curWindowNo,
m_curTab.getAD_AttachmentID(), m_curTab.getAD_Table_ID(), record_ID, null); m_curTab.getAD_AttachmentID(), m_curTab.getAD_Table_ID(), record_ID, null);
// //
m_curTab.loadAttachments(); // reload
aAttachment.setPressed(m_curTab.hasAttachment()); aAttachment.setPressed(m_curTab.hasAttachment());
} // attachment } // attachment
@ -2345,7 +2344,6 @@ public final class APanel extends CPanel
m_curTab.getCM_ChatID(), m_curTab.getAD_Table_ID(), record_ID, m_curTab.getCM_ChatID(), m_curTab.getAD_Table_ID(), record_ID,
description, null); description, null);
// //
m_curTab.loadChats(); // reload
aChat.setPressed(m_curTab.hasChat()); aChat.setPressed(m_curTab.hasChat());
} // chat } // chat
@ -2368,7 +2366,6 @@ public final class APanel extends CPanel
else else
{ {
m_curTab.lock (Env.getCtx(), record_ID, aLock.getButton().isSelected()); m_curTab.lock (Env.getCtx(), record_ID, aLock.getButton().isSelected());
m_curTab.loadAttachments(); // reload
} }
aLock.setPressed(m_curTab.isLocked()); aLock.setPressed(m_curTab.isLocked());
} // lock } // lock

View File

@ -78,7 +78,7 @@ public final class Attachment extends CDialog
int AD_Table_ID, int Record_ID, String trxName) int AD_Table_ID, int Record_ID, String trxName)
{ {
super (frame, Msg.getMsg(Env.getCtx(), "Attachment"), true); super (frame, Msg.getMsg(Env.getCtx(), "Attachment"), true);
// needs to be modal otherwise APanel does not recongize change. // needs to be modal otherwise APanel does not recognize change.
log.config("ID=" + AD_Attachment_ID log.config("ID=" + AD_Attachment_ID
+ ", Table=" + AD_Table_ID + ", Record=" + Record_ID); + ", Table=" + AD_Table_ID + ", Record=" + Record_ID);
// //
@ -93,10 +93,10 @@ public final class Attachment extends CDialog
log.log(Level.SEVERE, "", ex); log.log(Level.SEVERE, "", ex);
} }
// Create Model // Create Model
if (AD_Attachment_ID == 0) if (AD_Attachment_ID > 0)
m_attachment = new MAttachment (Env.getCtx(), AD_Table_ID, Record_ID, trxName);
else
m_attachment = new MAttachment (Env.getCtx(), AD_Attachment_ID, trxName); m_attachment = new MAttachment (Env.getCtx(), AD_Attachment_ID, trxName);
else
m_attachment = new MAttachment (Env.getCtx(), AD_Table_ID, Record_ID, trxName);
loadAttachments(); loadAttachments();
// //
try try
@ -112,7 +112,7 @@ public final class Attachment extends CDialog
/** Window No */ /** Window No */
private int m_WindowNo; private int m_WindowNo;
/** Attachment */ /** Attachment */
private MAttachment m_attachment; private MAttachment m_attachment = null;
/** Change */ /** Change */
private boolean m_change = false; private boolean m_change = false;
/** Logger */ /** Logger */
@ -380,7 +380,10 @@ public final class Attachment extends CDialog
} }
} }
else else
{
m_attachment.delete(true); m_attachment.delete(true);
m_attachment = null;
}
dispose(); dispose();
} }
// Cancel // Cancel
@ -468,8 +471,10 @@ public final class Attachment extends CDialog
private void deleteAttachment() private void deleteAttachment()
{ {
log.info(""); log.info("");
if (ADialog.ask(m_WindowNo, this, "AttachmentDelete?")) if (ADialog.ask(m_WindowNo, this, "AttachmentDelete?")) {
m_attachment.delete(true); m_attachment.delete(true);
m_attachment = null;
}
} // deleteAttachment } // deleteAttachment
/** /**

View File

@ -801,7 +801,7 @@ public abstract class AbstractADWindowContent extends AbstractUIPart implements
public void onEvent(Event event) throws Exception public void onEvent(Event event) throws Exception
{ {
adTabbox.getSelectedGridTab().lock(Env.getCtx(), adTabbox.getSelectedGridTab().getRecord_ID(), !toolbar.getButton("Lock").isPressed()); adTabbox.getSelectedGridTab().lock(Env.getCtx(), adTabbox.getSelectedGridTab().getRecord_ID(), !toolbar.getButton("Lock").isPressed());
adTabbox.getSelectedGridTab().loadAttachments(); // reload adTabbox.getSelectedGridTab().loadLocks(); // reload
toolbar.lock(adTabbox.getSelectedGridTab().isLocked()); toolbar.lock(adTabbox.getSelectedGridTab().isLocked());
} }
@ -851,7 +851,6 @@ public abstract class AbstractADWindowContent extends AbstractUIPart implements
@Override @Override
public void onEvent(Event event) throws Exception { public void onEvent(Event event) throws Exception {
adTabbox.getSelectedGridTab().loadAttachments(); // reload
toolbar.getButton("Attachment").setPressed(adTabbox.getSelectedGridTab().hasAttachment()); toolbar.getButton("Attachment").setPressed(adTabbox.getSelectedGridTab().hasAttachment());
focusToActivePanel(); focusToActivePanel();
} }
@ -900,7 +899,6 @@ public abstract class AbstractADWindowContent extends AbstractUIPart implements
chat.addEventListener(DialogEvents.ON_WINDOW_CLOSE, new EventListener<Event>() { chat.addEventListener(DialogEvents.ON_WINDOW_CLOSE, new EventListener<Event>() {
@Override @Override
public void onEvent(Event event) throws Exception { public void onEvent(Event event) throws Exception {
adTabbox.getSelectedGridTab().loadChats();
toolbar.getButton("Chat").setPressed(adTabbox.getSelectedGridTab().hasChat()); toolbar.getButton("Chat").setPressed(adTabbox.getSelectedGridTab().hasChat());
focusToActivePanel(); focusToActivePanel();
Clients.clearBusy(getComponent()); Clients.clearBusy(getComponent());

View File

@ -76,7 +76,7 @@ public class WAttachment extends Window implements EventListener<Event>
private int m_WindowNo; private int m_WindowNo;
/** Attachment */ /** Attachment */
private MAttachment m_attachment; private MAttachment m_attachment = null;
/** Change */ /** Change */
private boolean m_change = false; private boolean m_change = false;
@ -168,10 +168,10 @@ public class WAttachment extends Window implements EventListener<Event>
// Create Model // Create Model
if (AD_Attachment_ID == 0) if (AD_Attachment_ID > 0)
m_attachment = new MAttachment (Env.getCtx(), AD_Table_ID, Record_ID, trxName);
else
m_attachment = new MAttachment (Env.getCtx(), AD_Attachment_ID, trxName); m_attachment = new MAttachment (Env.getCtx(), AD_Attachment_ID, trxName);
else
m_attachment = new MAttachment (Env.getCtx(), AD_Table_ID, Record_ID, trxName);
loadAttachments(); loadAttachments();
@ -483,7 +483,10 @@ public class WAttachment extends Window implements EventListener<Event>
} }
} }
else else
{
m_attachment.delete(true); m_attachment.delete(true);
m_attachment = null;
}
dispose(); dispose();
} }
@ -614,6 +617,7 @@ public class WAttachment extends Window implements EventListener<Event>
if (result) if (result)
{ {
m_attachment.delete(true); m_attachment.delete(true);
m_attachment = null;
} }
} }
}); });