Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [eclipselink-users] Correct Way of Writing Generic Select All Query? (Here's how i did it)

Cool, also in case anyone's intersted here's a "generic" way to call
named queries until that's added.

	public List<?> getNamedQuery(String name,Object...binds)
	{
		Query query = getEntityManager().createNamedQuery(name);
		for (int i = 0; i < binds.length; i++) {
			Object tmp = binds[i];
			query.setParameter(i + 1,tmp);
		}
	    return query.getResultList();
	}




On Thu, May 1, 2008 at 11:14 AM,  <DOUGLAS.CLARKE@xxxxxxxxxx> wrote:
> Tim,
>
>  James filed a bug to address this requirement if you are interested in tracking it or contributing to the discussion of what the final solution might look like.
>
>  https://bugs.eclipse.org/bugs/show_bug.cgi?id=229772
>
>  What you have done is fine but we should add a more elegant and less proprietary solution for this.
>
>  Doug
>
>
>
>  -----Original Message-----
>  From: Tim Hollosy [mailto:hollosyt@xxxxxxxxx]
>  Sent: Wednesday, April 30, 2008 1:40 PM
>  To: EclipseLink User Discussions
>  Subject: [eclipselink-users] Correct Way of Writing Generic Select All
>  Query? (Here's how i did it)
>
>
>  I noticed myself writing the same select all query over and over
>  again, here's how I made it generic.
>
>  This is a method in my "model" class (a class that holds an instance
>  of my EntityManager)
>
>         public List<?> selectAll(Class<?> clazz)
>         {
>            JpaEntityManager jpaEm = JpaHelper.getEntityManager(getEntityManager());
>             Query query = jpaEm.createQuery(null, clazz);
>             return query.getResultList();
>         }
>
>
>  So I'm basically creating a new query with a null expression, this way
>  I'm not writing boiler plate Select queries. Is there a more elegant
>  way of doing it though?
>
>
>  --
>  ./tch
>  _______________________________________________
>  eclipselink-users mailing list
>  eclipselink-users@xxxxxxxxxxx
>  https://dev.eclipse.org/mailman/listinfo/eclipselink-users
>  _______________________________________________
>  eclipselink-users mailing list
>  eclipselink-users@xxxxxxxxxxx
>  https://dev.eclipse.org/mailman/listinfo/eclipselink-users
>



-- 
./tch


Back to the top