franta-hg@1: package cz.frantovo.springDemo1.dao;
franta-hg@1:
franta-hg@2: import cz.frantovo.springDemo1.KnihaDAORemote;
franta-hg@1: import cz.frantovo.springDemo1.dto.Kniha;
franta-hg@1: import java.util.Collection;
franta-hg@1: import javax.annotation.Resource;
franta-hg@2: import javax.ejb.Stateless;
franta-hg@1: import javax.sql.DataSource;
franta-hg@1: import org.springframework.jdbc.core.JdbcTemplate;
franta-hg@1:
franta-hg@1: /**
franta-hg@6: * Pro zjednodušení bez SuperDao.
franta-hg@1: * @author fiki
franta-hg@1: */
franta-hg@2: @Stateless
franta-hg@2: public class KnihaDAO implements KnihaDAORemote {
franta-hg@1:
franta-hg@3: @Resource(mappedName = "jdbc/sqlVyuka/piskoviste")
franta-hg@1: private DataSource dataSource;
franta-hg@4: private KnihaRowMapper knihaRowMapper = new KnihaRowMapper();
franta-hg@6: JdbcTemplate t = new JdbcTemplate(dataSource);
franta-hg@1:
franta-hg@1: public Collection getKnihy() {
franta-hg@4: return t.query("SELECT * FROM sbirka.kniha;", knihaRowMapper);
franta-hg@1: }
franta-hg@6:
franta-hg@6: public int ulozKnihu(Kniha k) {
franta-hg@6: return t.update("UPDATE kniha SET (nazev, autor, datum, isbn, pocet_stran, rok_vydani, id) VALUES (?,?,?,?,?,?,?)", new KnihaPSSetter(k));
franta-hg@6: }
franta-hg@1: }