Mikeš.
authorFrantišek Kučera <franta-hg@frantovo.cz>
Thu Feb 11 23:16:43 2010 +0100 (2010-02-11)
changeset 60ae95f929a1a
parent 5 7cf0cbef2936
child 7 a8c280a7c0e2
Mikeš.
java/SpringDemo1/SpringDemo1-ejb/src/java/cz/frantovo/springDemo1/dao/KnihaDAO.java
java/SpringDemo1/SpringDemo1-ejb/src/java/cz/frantovo/springDemo1/dao/KnihaPSSetter.java
java/SpringDemo1/SpringDemo1-lib/src/cz/frantovo/springDemo1/KnihaDAORemote.java
     1.1 --- a/java/SpringDemo1/SpringDemo1-ejb/src/java/cz/frantovo/springDemo1/dao/KnihaDAO.java	Wed Feb 10 23:11:38 2010 +0100
     1.2 +++ b/java/SpringDemo1/SpringDemo1-ejb/src/java/cz/frantovo/springDemo1/dao/KnihaDAO.java	Thu Feb 11 23:16:43 2010 +0100
     1.3 @@ -9,7 +9,7 @@
     1.4  import org.springframework.jdbc.core.JdbcTemplate;
     1.5  
     1.6  /**
     1.7 - *
     1.8 + * Pro zjednodušení bez <a href="http://hg.frantovo.cz/SuperDAO/">SuperDao</a>.
     1.9   * @author fiki
    1.10   */
    1.11  @Stateless
    1.12 @@ -18,9 +18,13 @@
    1.13      @Resource(mappedName = "jdbc/sqlVyuka/piskoviste")
    1.14      private DataSource dataSource;
    1.15      private KnihaRowMapper knihaRowMapper = new KnihaRowMapper();
    1.16 +    JdbcTemplate t = new JdbcTemplate(dataSource);
    1.17  
    1.18      public Collection<Kniha> getKnihy() {
    1.19 -	JdbcTemplate t = new JdbcTemplate(dataSource);
    1.20  	return t.query("SELECT * FROM sbirka.kniha;", knihaRowMapper);
    1.21      }
    1.22 +
    1.23 +    public int ulozKnihu(Kniha k) {
    1.24 +	return t.update("UPDATE kniha SET (nazev, autor, datum, isbn, pocet_stran, rok_vydani, id) VALUES (?,?,?,?,?,?,?)", new KnihaPSSetter(k));
    1.25 +    }
    1.26  }
     2.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     2.2 +++ b/java/SpringDemo1/SpringDemo1-ejb/src/java/cz/frantovo/springDemo1/dao/KnihaPSSetter.java	Thu Feb 11 23:16:43 2010 +0100
     2.3 @@ -0,0 +1,31 @@
     2.4 +package cz.frantovo.springDemo1.dao;
     2.5 +
     2.6 +import cz.frantovo.springDemo1.dto.Kniha;
     2.7 +import java.sql.PreparedStatement;
     2.8 +import java.sql.SQLException;
     2.9 +import java.sql.Timestamp;
    2.10 +import org.springframework.jdbc.core.PreparedStatementSetter;
    2.11 +
    2.12 +/**
    2.13 + *
    2.14 + * @author fiki
    2.15 + */
    2.16 +public class KnihaPSSetter implements PreparedStatementSetter {
    2.17 +
    2.18 +    private Kniha kniha;
    2.19 +
    2.20 +    public KnihaPSSetter(Kniha kniha) {
    2.21 +	this.kniha = kniha;
    2.22 +    }
    2.23 +
    2.24 +    public void setValues(PreparedStatement ps) throws SQLException {
    2.25 +	ps.setString(1, kniha.getNazev());
    2.26 +	ps.setInt(2, kniha.getAutor());
    2.27 +	ps.setTimestamp(3, new Timestamp(kniha.getDatumAktualizace().getTime()));
    2.28 +	ps.setString(4, kniha.getIsbn());
    2.29 +	ps.setInt(5, kniha.getPocetStran());
    2.30 +	ps.setInt(6, kniha.getRokVydani());
    2.31 +	ps.setInt(7, kniha.getId());
    2.32 +    }
    2.33 +
    2.34 +}
     3.1 --- a/java/SpringDemo1/SpringDemo1-lib/src/cz/frantovo/springDemo1/KnihaDAORemote.java	Wed Feb 10 23:11:38 2010 +0100
     3.2 +++ b/java/SpringDemo1/SpringDemo1-lib/src/cz/frantovo/springDemo1/KnihaDAORemote.java	Thu Feb 11 23:16:43 2010 +0100
     3.3 @@ -13,4 +13,5 @@
     3.4  
     3.5      public Collection<Kniha> getKnihy();
     3.6  
     3.7 +    public int ulozKnihu(Kniha k);
     3.8  }