• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Liutauras Vilda
  • Jeanne Boyarsky
  • paul wheaton
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Henry Wong
Saloon Keepers:
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Tim Moores
  • Mikalai Zaikin
Bartenders:
  • Frits Walraven

Data Access Object

 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi to all,

Can any one help me by giving the DAO example code. and let me know the process of dao.
 
author & internet detective
Posts: 42003
911
Eclipse IDE VI Editor Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Bhumireddy,
Welcome to JavaRanch!

Have you seen Sun's DAO description page yet? It has a good description and example.
 
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi following code shows abstraction between business layer and data access layer. data access can be any like using JDBC or Hibernate.


The DAO Factory
public abstract class DAOFactory
{
public static final DAOFactory HIBERNATE =
new com.vmware.vcp.dao.hibernate.HibernateDAOFactory();

public static final DAOFactory JDBC =
new com.vmware.vcp.dao.jdbc.JDBCDAOFactory();


public static final DAOFactory DEFAULT = HIBERNATE;
public static final DAOFactory getDAOFactory()
{
return DEFAULT;
}

public abstract CustomerDAO getCustomerDAO();
}

The Hibernate DAO Factory
public class HibernateDAOFactory extends DAOFactory
{
public CustomerDAO getCustomerDAO()
{
return new CustomerDAOHibernate(getCurrentSession(Constants.Hibernate.MASTER_SESSION_FACTORY_NAME));
}
}


The Customer DAO interface
public interface CustomerDAO {
public Customer findCustomerForUserId(String id, boolean lock);
}

The concrete impl of customer dao
public class CustomerDAOHibernate implements CustomerDAO
{
public Customer findCustomerForUserId(String id, boolean lock)
{
// Database access code
}
}

Business layer code

DAOFactory df = DAOFactory.getDAOFactory();
CustomerDAO custDao = df.getCustomerDAO();
custDao.findCustomerForUserId(UserId, true);
 
That feels good. Thanks. Here's a tiny ad:
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
    Bookmark Topic Watch Topic
  • New Topic