Home > iBATIS, Java Language, Spring > Spring + iBatis // Part 5 // The DAO

Spring + iBatis // Part 5 // The DAO

We declared a DAO in our applicationContext.xml file.  It’s time to create that DAO now by starting with an interface declaration.  I called this interface MyDAO.java.

package com.example;

import java.util.List;

public interface MyDAO {

 FilePickup selectFilepickupInstruction(long id);
 List<FilePickup> selectFilepickupInstructions();

}

Then we need to create the class that will implement this interface.  The name of this class should match that specified in the applicationContext.xml.  In this example it’s MyDAOImpl.java.

package com.example;

import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.springframework.orm.ibatis.support.SqlMapClientDaoSupport;

public class MyDAOImpl extends SqlMapClientDaoSupport implements MyDAO {
  public MyDAOImpl() {
  }

  public FilePickup selectFilepickupInstruction(long id) {
    return  
      (FilePickup)getSqlMapClientTemplate().queryForObject(
          "selectFilepickupInstruction",id);
  }
  public List<FilePickup> selectFilepickupInstructions() {   
      return     
        getSqlMapClientTemplate().queryForList(
            "selectFilepickupInstructions",null);

  }

 }

Note that a java.util.list is used to handle results from a sql statement that returns multiple rows.  The strings used in the queryForList() and queryForObject() methods are those names declared in the mapping stage.

Advertisement
  1. No comments yet.
  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Connecting to %s

Follow

Get every new post delivered to your Inbox.