• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Bear Bibeault
  • Junilu Lacar
Sheriffs:
  • Jeanne Boyarsky
  • Tim Cooke
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • salvin francis
  • Frits Walraven
Bartenders:
  • Scott Selikoff
  • Piet Souris
  • Carey Brown

what is the dao layer

 
Ranch Hand
Posts: 1325
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i read the this tutorial .
http://java.sun.com/blueprints/corej2eepatterns/Patterns/DataAccessObject.html
is dao means access object through interfaces.then dao is eaqual to Factory design pattern?
is it true?
 
Ranch Hand
Posts: 157
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
No. You're assuming that just because DAO uses an interface it is a Factory. The interface is just a way to decouple your code, and DAO pattern is mostly used to manage relational database access. Factory, on the other hand, is a creational pattern in which is defined how implementers of a a particular interface do the actual object creation.
 
shawn peter
Ranch Hand
Posts: 1325
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
can you please explain this using example?i think it is very helpful.
 
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
DAO is similar to DB file but we are using Mapper to this like ColumnMapRowMapper() or Table_nameRowMapper()

ColumnMapRowMapper() is used when you are selecting particular column and Table_nameRowMapper() for selecting all the columns (select *)

e.g.
ColumnMapRowMapper()


String selectSql = "SELECT emp_name FROM emp WHERE emp_id = ? AND emp_type = ? ";

Object[] paramValues=new Object[]{emp_id,emp_type};
int[] paramTypes=new int[]{Types.INTEGER,Types.VARCHAR};

list = getJdbcTemplate().query(selectSql,paramValues,paramTypes, new ColumnMapRowMapper());

so in list you will get only column values .


Table_nameRowMapper()

String selectSql = "SELECT * FROM emp WHERE emp_id = ? AND emp_type = ? ";

Object[] paramValues=new Object[]{emp_id,emp_type};
int[] paramTypes=new int[]{Types.INTEGER,Types.VARCHAR};

list = getJdbcTemplate().query(selectSql,paramValues,paramTypes, new EmpRowMapper());

and at the end of file there will be a class of name EmpRowMapper

class EmpRowMapperimplements RowMapper
{
public Object mapRow(ResultSet rs, int index) throws SQLException
{

Emp emp = new Emp ();
emp .setEmpId(rs.getInt("EMP_ID"));
emp .setEmpType(rs.getString("EMP_TYPE"));
// all the column name.
return emp;

}
}

so in a list you will get all the resultant object of Emp class.

Thanks,
-Ravi
 
Eduardo Bueno
Ranch Hand
Posts: 157
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
ravi pardeshi, organize your posts. I barely could understand what you posted above.

Wikipedia has a factory method example and Sun has an example using both.
 
ravi pardeshi
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Eduardo Bueno wrote:ravi pardeshi, organize your posts. I barely could understand what you posted above.

Wikipedia has a factory method example and Sun has an example using both.



 
Well THAT's new! Comfort me, reliable tiny ad:
Thread Boost feature
https://coderanch.com/t/674455/Thread-Boost-feature
    Bookmark Topic Watch Topic
  • New Topic