Re: The easiest framework for Java Database applications development
released for production use
yaormaAdmin wrote:
What would the code you would write to get the data from the
message_table and echo it to the console in the example at www.yaorma.org
look like?
You assume I would write code like that. I wouldn't, normally. In a toy
example where everything fits in one 'main()' call, there's not much you can
conclude about the utility of a framework.
The question isn't whether you can simplify a single call to a database for a
single hard-coded query. The question is whether you can build a robust,
stable, extendible application backed by a database. Knocking away a couple
of 'close()' calls is of minor value in such a context.
But to answer your question for the toy example, something similar to
public class Foo
{
@PersistenceContext( unitName = "pcontext" )
private EntityManager em;
public List <Message> findMessages()
{
final CriteriaQuery <Message> cq =
em.getCriteriaBuilder().createQuery( Message.class );
cq.select( cq.from( Message.class ));
return em.createQuery( cq ).getResultList();
}
public static void main( String [] args )
{
System.out.println( new Foo().findMessages() );
}
}
Or I might use a JQL query instead of the 'CriteriaQuery'. It's just that the
criteria approach is amenable to generic treatment - my actual code has a type
parameter for the 'Message' type.
--
Lew
Ceci n'est pas une fen??tre.
..___________.
|###] | [###|
|##/ | *\##|
|#/ * | \#|
|#----|----#|
|| | * ||
|o * | o|
|_____|_____|
|===========|