Menu

#4 SelectMatching method

open
nobody
None
5
2005-10-14
2005-10-14
farinhaP
No

from
http://java.sun.com/blueprints/corej2eepatterns/Patterns/DataAccessObject.html
towards the end of the example there is

// select all customers in the same city
Customer criteria=new Customer();
criteria.setCity("New York");
Collection customersList =
custDAO.selectCustomersTO(criteria);

I reckon this is an excellent feature to be added.
i.e. fooDaoImplBase.getMatching(fooObj)

the select statement would look something like
sql = SQL_SELECT + WHERE 1=1
if( assertNotNull(fooObj.getFieldName()) {
sql += "AND field_name='"+fooObj.getFieldName()+"'";

if( assertNotNull(fooObj.getFieldName2()) {
sql += "AND field_name2='"+fooObj.getFieldName2()+"'";

etc!

This will allow to build the object fooObj with some
criteria and then fetch all of them from DB whithout
need to write the SQL

Discussion


Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.