-
1. Re: Use Of Restriction in EJBQL for Seam
sean.tozer Jun 24, 2010 9:38 AM (in response to eswaramoorthy1986)The idea of the EntityQuery objects is fairly straight-forward.
Basically, seam-gen makes an *List class extending EntityQuery for each entity. The list class holds an instance of the associated entity. For instance, your ProjectList class has a Project.
What you are meant to do is set the fields of the contained object ("#{projectList.project.projectName}", for example) to whatever it is that you want to search for.
The RESTRICTIONS string is simply an SQL clause which takes each of the basic fields in the contained entity and uses them to select matching entities. Within the parent class, when it goes to do the actual query, it'll use the restrictions and the EJBQL to perform a select using only the restrictions that have a non-null value associated with them.
You can do various other things by extending the *List class. For example, you could add a clause directly to the EJBQL to fetch an association as well, or to always select only the entities matching a specific where clause.
-
2. Re: Use Of Restriction in EJBQL for Seam
eswaramoorthy1986 Jun 24, 2010 1:20 PM (in response to eswaramoorthy1986)Thanks for your reply Sean Tozer, But i want to know, what in this code
private static final String[] RESTRICTIONS = { "lower(project.processOwner) like lower(concat(#{projectList.project.processOwner},'%'))", "lower(project.projectName) like lower(concat(#{projectList.project.projectName},'%'))",
}; -
3. Re: Use Of Restriction in EJBQL for Seam
eswaramoorthy1986 Jun 24, 2010 1:28 PM (in response to eswaramoorthy1986)
Thanks for your reply Sean Tozer, But i want to know,string RESTRICTIONS carry after execution of this below code.
private static final String[] RESTRICTIONS = { "lower(project.processOwner) like lower(concat(#{projectList.project.processOwner},'%'))", "lower(project.projectName) like lower(concat(#{projectList.project.projectName},'%'))",
};
And will you guide me to retrieve data from database.
That is, I have date column in my project table . I want to search table records by date. -
4. Re: Use Of Restriction in EJBQL for Seam
sean.tozer Jun 25, 2010 10:09 AM (in response to eswaramoorthy1986)After execution, the RESTRICTIONS string array would hold something depending on what is in the project entity.
So, say for instance that you had set the projectList.project entity to hold the following:
processOwner = 'test'
projectName = 'Awesome Project'Then the RESTRICTIONS array would hold the following:
{"lower(project.processOwner) like lower(concat('test', '%')", "lower(project.projectName) like lower(concat('Awesome Project', '%')"}
Those restrictions would then be passed as part of the WHERE clause to the database engine when the retrieve was made. If either of the restrictions had a null value, then that restriction would be ignored.
If you wanted to find a project based on the date, you could add a restriction:
"project.date = #{projectList.project.date}"
Or something to that effect.
-
5. Re: Use Of Restriction in EJBQL for Seam
eswaramoorthy1986 Jun 26, 2010 10:03 AM (in response to eswaramoorthy1986)
Thanks for your reply Sean Tozer
And my project display the result while I search using String currentdate entity in entity bean and varchar PRO_DATE in MYSQL database.
From this above declaration it store rich calendar value in project table and retrieve date value from project table in database, display the successful result....
While i using JSF code like
<rich:calendar id="currentdate" datePattern="MM/dd/yyyy"
value="project.currentdate">
and in bean
I declared currentdate entity as DATE datatype in project entity bean and in database i use PRO_DATE as DATE datatype but it display no result ... that is resultlist contains no search result...
This is code
in project.java
@Column(name = "PRO_DATE", nullable = false)
public Date getCurrentdate( )
{
return this.currentdate;
}
public void setCurrentdate (Date currentdate)
{
this.currentdate = currentdate;
}
in projectlist.java
@Name("projectList") public class ProjectList extends EntityQuery {
private static final long serialVersionUID = -7673337640345325071L;
private static final String EJBQL = "select project from Project project";
private static final String[] RESTRICTIONS = { "lower(project.processOwner) like lower(concat(#{projectList.project.processOwner},'%'))",
"lower(project.projectName) like lower(concat(#{projectList.project.projectName},'%'))",
"lower(project.currentdate) like lower(concat(#{projectList.project.currentdate},'%'))",
};
private Project project = new Project();
public ProjectList() { ; setEjbql(EJBQL); setRestrictionExpressionStrings(Arrays.asList(RESTRICTIONS)); setMaxResults(25); }
public Project getProject() { return project; } }
From this above code it sucessfully store rich calendar value in project table .
But not retrieve date value from project table in database,
Please help me....
I am very new to seam framework
-
6. Re: Use Of Restriction in EJBQL for Seam
eswaramoorthy1986 Jun 28, 2010 3:18 AM (in response to eswaramoorthy1986)It cant work Sean Tozer..........
"project.date = #{projectList.project.date}"
for my project.
@Name("projectList") public class ProjectList extends EntityQuery {
private static final long serialVersionUID = -7673337640345325071L;
private static final String EJBQL = "select project from Project project";
private static final String[] RESTRICTIONS = { "lower(project.processOwner) like lower(concat(#{projectList.project.processOwner},'%'))",
"lower(project.projectName) like lower(concat(#{projectList.project.projectName},'%'))",
"project.currentdate = #{projectList.project.currentdate}",
};