Skip to content

Commit

Permalink
SAM-2452 dont convert Sets to Lists in the Hibernate layer! This can …
Browse files Browse the repository at this point in the history
…result in tens of thousands of extra queries. This commit removes the getItemTextAttachmentList() helper method

git-svn-id: https://source.sakaiproject.org/svn/sam/trunk@315993 66ffb92e-73f9-0310-93c1-f5514f145a0a
  • Loading branch information
ottenhoff committed Dec 11, 2014
1 parent d841cce commit cd2ff6a
Show file tree
Hide file tree
Showing 7 changed files with 25 additions and 36 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,6 @@ public interface ItemTextIfc

void setItemTextAttachmentSet(Set<ItemTextAttachmentIfc> itemTextAttachmentSet);

List<ItemTextAttachmentIfc> getItemTextAttachmentList();

/**
* This is an actual EMI Question Item (i.e. not Theme or Lead In Text or
* Complete Answer Options List)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -445,7 +445,14 @@ private List prepareItemTextAttachment(ItemTextIfc itemText, boolean isEditPendi
else if (itemText == null) {
return new ArrayList();
}
else return itemText.getItemTextAttachmentList();
else {
ArrayList attachmentList = new ArrayList();
Set<ItemTextAttachmentIfc> itemTextAttachmentSet = itemText.getItemTextAttachmentSet();
for (Iterator<ItemTextAttachmentIfc> it = itemTextAttachmentSet.iterator(); it.hasNext();) {
attachmentList.add(it.next());
}
return attachmentList;
}
}

private HashMap getResourceIdHash(Set attachmentSet){
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
import org.sakaiproject.tool.assessment.data.ifc.assessment.AnswerIfc;
import org.sakaiproject.tool.assessment.data.ifc.assessment.AssessmentIfc;
import org.sakaiproject.tool.assessment.data.ifc.assessment.ItemMetaDataIfc;
import org.sakaiproject.tool.assessment.data.ifc.assessment.ItemTextAttachmentIfc;
import org.sakaiproject.tool.assessment.data.ifc.assessment.ItemTextIfc;
import org.sakaiproject.tool.assessment.data.ifc.shared.TypeIfc;
import org.sakaiproject.tool.assessment.facade.AgentFacade;
Expand Down Expand Up @@ -645,7 +646,11 @@ else if (itemText.getSequence().equals(ItemTextIfc.EMI_ANSWER_OPTIONS_SEQUENCE))
}
answerbean.setCorrectOptionLabels(correctOptionLabels);

List attachmentList = itemfacade.getItemTextBySequence(answerbean.getSequence()).getItemTextAttachmentList();
Set<ItemTextAttachmentIfc> attachmentSet = itemfacade.getItemTextBySequence(answerbean.getSequence()).getItemTextAttachmentSet();
ArrayList<ItemTextAttachmentIfc> attachmentList = new ArrayList<ItemTextAttachmentIfc>();
for (Iterator<ItemTextAttachmentIfc> it = attachmentSet.iterator(); it.hasNext();) {
attachmentList.add(it.next());
}
answerbean.setAttachmentList(attachmentList);
answerbean.setResourceHash(null);
qaComboList.add(answerbean);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,10 @@
package org.sakaiproject.tool.assessment.ui.listener.author;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Set;

import javax.faces.event.AbortProcessingException;
import javax.faces.event.ActionEvent;
Expand Down Expand Up @@ -100,10 +103,10 @@ public void processAction(ActionEvent ae) throws AbortProcessingException {
ItemDataIfc item = itemService.getItem(itemId);
ItemTextIfc itemText = item.getItemTextBySequence(sequence);
//log.debug("*** item attachment="+item.getItemAttachmentList());
resetItemTextAttachment(answerBean.getResourceHash(), itemText.getItemTextAttachmentList(), assessmentService);
resetItemTextAttachment(answerBean.getResourceHash(), itemText.getItemTextAttachmentSet(), assessmentService);
}
else{
resetItemTextAttachment(answerBean.getResourceHash(), new ArrayList(), assessmentService);
resetItemTextAttachment(answerBean.getResourceHash(), new HashSet(), assessmentService);
}

}
Expand Down Expand Up @@ -189,15 +192,15 @@ private void removeLeftOverResources(HashMap resourceHash){
}
*/

private void resetItemTextAttachment(HashMap resourceHash, List attachmentList, AssessmentService service){
private void resetItemTextAttachment(HashMap resourceHash, Set<ItemTextAttachmentIfc> attachmentSet, AssessmentService service){
// 1. we need to make sure that attachment removed/added by file picker
// will be restored/remove when user cancels the entire modification
if (attachmentList != null){
for (int i=0; i<attachmentList.size(); i++){
AttachmentIfc attach = (AttachmentIfc) attachmentList.get(i);
if (attachmentSet != null){
for (Iterator<ItemTextAttachmentIfc> it = attachmentSet.iterator(); it.hasNext();) {
AttachmentIfc attach = (AttachmentIfc) it.next();
try{
ContentResource cr = AssessmentService.getContentHostingService().getResource(attach.getResourceId());
}
}
catch (PermissionException e) {
log.warn("PermissionException from ContentHostingService:"+e.getMessage());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -132,18 +132,6 @@ public void setItemTextAttachmentSet(Set<ItemTextAttachmentIfc> itemTextAttachme
this.itemTextAttachmentSet = itemTextAttachmentSet;
}

public List<ItemTextAttachmentIfc> getItemTextAttachmentList() {
ArrayList<ItemTextAttachmentIfc> list = new ArrayList<ItemTextAttachmentIfc>();
if (itemTextAttachmentSet != null) {
Iterator<ItemTextAttachmentIfc> iter = itemTextAttachmentSet.iterator();
while (iter.hasNext()) {
ItemTextAttachmentIfc a = iter.next();
list.add(a);
}
}
return list;
}

// for EMI - Attachments at Answer Level
public boolean getHasAttachment(){
if (itemTextAttachmentSet != null && itemTextAttachmentSet.size() >0)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@
<key column="ITEMTEXTID"/>
<one-to-many class="org.sakaiproject.tool.assessment.data.dao.assessment.PublishedAnswer"/>
</set>
<set name="itemTextAttachmentSet" table="SAM_PUBLISHEDATTACHMENT_T" cascade="all" order-by="createdDate asc" inverse="true" lazy="false">
<set name="itemTextAttachmentSet" table="SAM_PUBLISHEDATTACHMENT_T" cascade="all" order-by="createdDate asc" inverse="true" lazy="false" batch-size="50">
<key column="ITEMTEXTID"/>
<one-to-many class="org.sakaiproject.tool.assessment.data.dao.assessment.PublishedItemTextAttachment"/>
</set>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -131,18 +131,6 @@ public void setItemTextAttachmentSet(Set itemTextAttachmentSet) {
this.itemTextAttachmentSet = itemTextAttachmentSet;
}

public List getItemTextAttachmentList() {
ArrayList list = new ArrayList();
if (itemTextAttachmentSet != null) {
Iterator iter = itemTextAttachmentSet.iterator();
while (iter.hasNext()) {
ItemTextAttachmentIfc a = (ItemTextAttachmentIfc) iter.next();
list.add(a);
}
}
return list;
}

// for EMI - Attachments at Answer Level
public boolean getHasAttachment(){
if (itemTextAttachmentSet != null && itemTextAttachmentSet.size() >0)
Expand Down

0 comments on commit cd2ff6a

Please sign in to comment.