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();
}
}