Win a copy of Emmy in the Key of Code this week in the General Computing forum!
  • 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
  • Liutauras Vilda
  • Junilu Lacar
  • Jeanne Boyarsky
  • Bear Bibeault
Sheriffs:
  • Knute Snortum
  • Devaka Cooray
  • Tim Cooke
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Ron McLeod
  • Carey Brown
Bartenders:
  • Paweł Baczyński
  • Piet Souris
  • Vijitha Kumara

Why to use Ibatis DAO pattern

 
Ranch Hand
Posts: 129
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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();
}
}
 
Ranch Hand
Posts: 15304
6
Mac OS X IntelliJ IDE Chrome
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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

 
Praveen Sharma
Ranch Hand
Posts: 129
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 129
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ?
 
Let nothing stop you! Not even this tiny ad:
Java file APIs (DOC, XLS, PDF, and many more)
https://products.aspose.com/total/java
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!