aspose file tools*
The moose likes Other Application Frameworks and the fly likes Why to use Ibatis DAO pattern Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Frameworks » Other Application Frameworks
Bookmark "Why to use Ibatis DAO pattern " Watch "Why to use Ibatis DAO pattern " New topic
Author

Why to use Ibatis DAO pattern

Praveen Sharma
Ranch Hand

Joined: Jul 31, 2008
Posts: 129
Hi,
I have learned IBatis and I want to use the IBatis framework in my application.
After going through some documents I read something abut IBatis DAO pattern. But I am not really sure how and why one should use IBatis DAO pattern. Could anyone help me out in this. What I basically want to know is that am I free to write my own DAO class with IBatis or do I have to use IBatis DAO pattern ?

I have following sample test class to access sqlMap-config.xml file [dont worry about the syntax if something is missing or wrong ].

Can this file be called a DAO ?

public class IBatis
{
private static SqlMapClient sqlMap = null;
private static String resource = "com\\myorg\\test\\resource\\sqlMap-config.xml";

public static SqlMapClient getSqlMap() throws IOException
{
if (sqlMap == null)
{
Reader reader = Resources.getResourceAsReader(resource);
sqlMap = SqlMapClientBuilder.buildSqlMapClient(reader);
}
return sqlMap;
}

public static void testEmployee() throws Exception
{
SqlMapClient sqlMap = IBatis.getSqlMap();

Department d = new Department();
d.setDepartmentId(10);
d.setDepartmentName("Manlog");

List<Department> list = sqlMap.queryForList("getDepartments", d);
for (Department e : list)
{
//System.out.println(e.getDepartmentId());
System.out.println(e.getDepartmentName());
}

//sqlMap.insert("addDept", d);


}

public static void main (String args[]) throws Exception
{
testEmployee();
}
}


SCJP 80% SCWCD 89%
Gregg Bolinger
GenRocket Founder
Ranch Hand

Joined: Jul 11, 2001
Posts: 15299
    
    6

If you are referring to the DAO API that used to be included with iBatis, that is deprecated and shouldn't be used anymore as it is no longer maintained. What you have written is not a DAO. It is a class that inserts a Department. But you have no methods for reusing this class outside of itself. A DAO is an object that provides data access methods like insert, delete, findByFirstName, etc that deals with a specific entity.

While this article might be a bit beyond where your learning process is at the moment, it might help give you an idea of what a DAO actually is.

http://www.greggbolinger.com/blog/2009/02/25/1235585940000.html


GenRocket - Experts at Building Test Data
Praveen Sharma
Ranch Hand

Joined: Jul 31, 2008
Posts: 129
Gregg,
I thank you from the bottom of my heart for the reply. I went through your artcile and the DAO concept is clear to me know. You know sometimes it is so nice if someone clears your confusion in a minute when you are going thru a barrage of document trying to understand a new thing. Thanks once again.
Praveen Sharma
Ranch Hand

Joined: Jul 31, 2008
Posts: 129
Hi Gregg,
You mentioned in your reply that the IBatis DAO API is deprecated. By saying that are you referring to the API mentioned here - http://ibatis.apache.org/docs/java/user/com/ibatis/dao/client/package-tree.html ?
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Why to use Ibatis DAO pattern