Using Entity Query
olasamuel Aug 16, 2010 8:03 AMHi All,
I am using Entity quesry and it was working fine. However, I wanted to sort my data with this and I seem not to get the correct code as I have exhausted all the methods available but seems not to be working. Please can someone who know how to use this more than I do help me. Please find the code I am using below and possibly tell me what I must do to make sure that the data are sorted after displaying them.
Thank you in advance.
package za.co.csir.meraka.mobi4d.web.voting.session;
import java.util.Arrays;
import java.util.List;
import org.jboss.seam.annotations.Name;
import org.jboss.seam.framework.EntityQuery;
import za.co.csir.meraka.mobi4d.web.voting.entity.Vote;
/**
* Title: Vote Home
* Description: This is the vote list...
*
* Created on: July 19, 2010
* Company: CSIR
*
* @author JP Tolmay
* @version 0.1
*/
@Name("voteList")
public class VoteList extends EntityQuery<Vote>
{
// region Declarations
private static final long serialVersionUID = 3200216085422142008L;
private final static String QUERY = "select vote from Vote vote";
private final static String[] RESTRICTIONS = { "lower(vote.name) like lower(#{voteList.name})", "lower(vote.topic) like lower(#{voteList.topic})", "lower(vote.feedback) like lower(#{voteList.feedback})" };
// region Constructors
/**
* Declare all the constructors.
*/
public VoteList() { this._Initialize(QUERY, RESTRICTIONS); } // Initialise the class
// region Properties
/**
* Holds the name value to include in the list
*/
public void setName(String name) { this.name = name; }
public String getName() { return this.name; }
private String name;
/**
* Holds the topic value to include in the list
*/
public void setTopic(String topic) { this.topic = topic; }
public String getTopic() { return this.topic; }
private String topic;
/**
* Holds the feedback value to include in the list
*/
public void setFeedback(String feedback) { this.feedback = feedback; }
public String getFeedback() { return this.feedback; }
private String feedback;
// region Methods
// region Methods-private
/**
* Description: This method initialise the class
*/
private void _Initialize(String query, String[] restrictions) {
// Set the query and restrictions to use
this.setEjbql(query);
this.setRestrictionExpressionStrings(Arrays.asList(restrictions));
this.setOrderBy(topic);
}
// region Methods-public
/**
* Description: This method returns a list of stored records, dependent on the filtered options
*
* @param name Holds the 'vote.name' specific records to filter (find)
* @param topic Holds the 'vote.topic' specific records to filter (find)
* @param feedback Holds the 'vote.feedback' specific records to filter (find)
* @return A list of stored 'vote' objects from the persistence store
*/
public List<Vote> getList(String name, String topic, String feedback) { this.name = name; this.topic = topic; this.feedback = feedback; return this.getResultList(); }
/**
* Description: This method returns the number of stored records, dependent on the filtered options
*
* @param name Holds the 'vote.name' specific records to filter (find)
* @param topic Holds the 'vote.topic' specific records to filter (find)
* @param feedback Holds the 'vote.feedback' specific records to filter (find)
* @return A list of stored 'vote' objects from the persistence store
*/
public int getCount(String name, String topic, String feedback) { this.name = name; this.topic = topic; this.feedback = feedback; return this.getResultList().size(); }
}
I am using Entity quesry and it was working fine. However, I wanted to sort my data with this and I seem not to get the correct code as I have exhausted all the methods available but seems not to be working. Please can someone who know how to use this more than I do help me. Please find the code I am using below and possibly tell me what I must do to make sure that the data are sorted after displaying them.
Thank you in advance.
package za.co.csir.meraka.mobi4d.web.voting.session;
import java.util.Arrays;
import java.util.List;
import org.jboss.seam.annotations.Name;
import org.jboss.seam.framework.EntityQuery;
import za.co.csir.meraka.mobi4d.web.voting.entity.Vote;
/**
* Title: Vote Home
* Description: This is the vote list...
*
* Created on: July 19, 2010
* Company: CSIR
*
* @author JP Tolmay
* @version 0.1
*/
@Name("voteList")
public class VoteList extends EntityQuery<Vote>
{
// region Declarations
private static final long serialVersionUID = 3200216085422142008L;
private final static String QUERY = "select vote from Vote vote";
private final static String[] RESTRICTIONS = { "lower(vote.name) like lower(#{voteList.name})", "lower(vote.topic) like lower(#{voteList.topic})", "lower(vote.feedback) like lower(#{voteList.feedback})" };
// region Constructors
/**
* Declare all the constructors.
*/
public VoteList() { this._Initialize(QUERY, RESTRICTIONS); } // Initialise the class
// region Properties
/**
* Holds the name value to include in the list
*/
public void setName(String name) { this.name = name; }
public String getName() { return this.name; }
private String name;
/**
* Holds the topic value to include in the list
*/
public void setTopic(String topic) { this.topic = topic; }
public String getTopic() { return this.topic; }
private String topic;
/**
* Holds the feedback value to include in the list
*/
public void setFeedback(String feedback) { this.feedback = feedback; }
public String getFeedback() { return this.feedback; }
private String feedback;
// region Methods
// region Methods-private
/**
* Description: This method initialise the class
*/
private void _Initialize(String query, String[] restrictions) {
// Set the query and restrictions to use
this.setEjbql(query);
this.setRestrictionExpressionStrings(Arrays.asList(restrictions));
this.setOrderBy(topic);
}
// region Methods-public
/**
* Description: This method returns a list of stored records, dependent on the filtered options
*
* @param name Holds the 'vote.name' specific records to filter (find)
* @param topic Holds the 'vote.topic' specific records to filter (find)
* @param feedback Holds the 'vote.feedback' specific records to filter (find)
* @return A list of stored 'vote' objects from the persistence store
*/
public List<Vote> getList(String name, String topic, String feedback) { this.name = name; this.topic = topic; this.feedback = feedback; return this.getResultList(); }
/**
* Description: This method returns the number of stored records, dependent on the filtered options
*
* @param name Holds the 'vote.name' specific records to filter (find)
* @param topic Holds the 'vote.topic' specific records to filter (find)
* @param feedback Holds the 'vote.feedback' specific records to filter (find)
* @return A list of stored 'vote' objects from the persistence store
*/
public int getCount(String name, String topic, String feedback) { this.name = name; this.topic = topic; this.feedback = feedback; return this.getResultList().size(); }
}