ibatis-user-java mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Daniel Guido" <dgu...@gmail.com>
Subject Re: beginner spring+ibatis help
Date Mon, 30 Jun 2008 18:29:32 GMT
Thanks Christian,

I took your suggestion to extend the SqlMap class off
SqlMapClientDaoSupport, but I must be missing something because
queryForList is unresolved when I used it like you did. It looks like
this now:

public class SqlMapProductDao extends SqlMapClientDaoSupport {

    protected final Log logger = LogFactory.getLog(getClass());
    //private SqlMapClient sqlMapClient;

    //public void setSqlMapClient(SqlMapClient sqlMapClient) {
    //  this.sqlMapClient = sqlMapClient;
    //}

    public List<Product> getProductList() {
      logger.info("Getting products! (iBatis)");

      List<Product> allProducts = queryForList("selectAllProducts");
//unresolved
      return allProducts;

    }
...
}

I'm in the middle of reading docs and digging through sample code on
Google Code to figure it out, but any additional help would be
appreciated.

Also, my service layer has code (without the annotations) that looks
very similar to what you wrote:

public class SimpleProductManager implements ProductManager {
  private ProductDao productDao;
  public List<Product> getProducts() {
    return productDao.getProductList();
  }
  public void setProductDao(ProductDao productDao) {
    this.productDao = productDao;
  }
...
}

public interface ProductManager extends Serializable {
    public void increasePrice(int percentage);
    public List<Product> getProducts();
}




--
Dan Guido


On Mon, Jun 30, 2008 at 7:48 AM, Poitras Christian
<Christian.Poitras@ircm.qc.ca> wrote:
> Hi,
>
> First I'd make my SqlMap class extends SqlMapClientDaoSupport from Spring since it will
relieve you of writing a try-catch block.
>
>    public List<Product> getProductList() throws DataAccessException {
>        logger.info("Getting products! (iBatis)");
>
>        List<Product> allProducts = queryForList("selectAllProducts");
>        return allProducts;
>    }
>
>
> Second, I'd handle transaction in a service class.
>
> @Service
> Public class ProductService {
>    @Autowired
>    ProductDao productDao;
>
>    -- Transaction managed by Spring.
>    @Transactional
>    public List<Product> getProductList() throws DataAccessException {
>        return productDao.getProductList();
>    }
> }
>
> This works if you use annotations in Spring. (See annotations in section 3.11 and transaction
in section 9.5)
>
>
> Christian
>
>
> -----Original Message-----
> From: Daniel Guido [mailto:dguido@gmail.com]
> Sent: Friday, June 27, 2008 4:50 PM
> To: user-java@ibatis.apache.org
> Subject: beginner spring+ibatis help
>
> I'm a student and my grasp of JSP/J2EE, iBatis, and Spring is a little iffy. I'm attempting
to learn all of them as part of a project and I'd appreciate any help you could offer me (and
to save time, yes, I've read the developer's guide pdf).
>
> I followed the Spring tutorial to create their little inventory management demo-app.
It works fine with JDBC and HSQL and I mostly understand what's going on. The URL for that
tutorial is here:
> http://static.springframework.org/docs/Spring-MVC-step-by-step/
>
> Now I'm trying to replace the JDBC DAO with an iBatis DAO. I think I've got everything
put together correctly, but my ProductDao (the parent class to my SqlMapProductDao) has a
method: public List<Product> getProductList(); It was created in this step of the
> tutorial: http://static.springframework.org/docs/Spring-MVC-step-by-step/part5.html#step5.4
>
> How do I create an equivalent function in the SqlMapProductDao? I made a sql map that
looks like this (my columns and properties match, no need for result maps):
> <select id="selectAllProducts" resultMap="ProductResult">
>    select * from products
> </select>
>
> The following is _completely_ wrong but at least shows what I'd like it to do:
>
>
>    public List<Product> getProductList() throws DataAccessException {
>      logger.info("Getting products! (iBatis)");
>
>      this.sqlMapClient.startTransaction();
>      try {
>          List<Product> allProducts =
> this.sqlMapClient.queryForList("selectAllProducts");
>          return allProducts;
>      }
>      catch (SQLException ex) {}
>      this.sqlMapClient.commitTransaction();
>    }
>
>
> based off this:
> http://static.springframework.org/spring/docs/2.5.x/reference/orm.html#orm-ibatis-straight
>
> Can anyone help? I can post more of the source I'm working with if you think it will
help. Thanks.
>
>
> --
> Dan Guido
>

Mime
View raw message