Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

uso do NamedParameterJdbcDaoSupport

  • Loading branch information...
commit b61ceb788663f9db3204f73f6ef47b5f41ed8555 1 parent 63a373d
@brunoborges authored
View
2  turma2/src/main/java/com/tivit/PageCategoria.java
@@ -1,6 +1,6 @@
package com.tivit;
-import org.apache.wicket.markup.html.form.Form;
+import org.apache.wicket.markup.html.form.Form;
import org.apache.wicket.markup.html.form.RequiredTextField;
import org.apache.wicket.model.CompoundPropertyModel;
import org.apache.wicket.spring.injection.annot.SpringBean;
View
6 turma2/src/main/java/com/tivit/servicos/CategoriaServiceFacade.java
@@ -1,9 +1,15 @@
package com.tivit.servicos;
+import java.util.List;
+
+import com.tivit.dominio.Categoria;
+
public interface CategoriaServiceFacade {
public void excluir(int id);
public void incluir(String nome);
+ public List<Categoria> listarTodos();
+
}
View
38 turma2/src/main/java/com/tivit/servicos/CategoriaServiceFacadeImpl.java
@@ -1,17 +1,18 @@
package com.tivit.servicos;
import java.util.HashMap;
-import java.util.Map;
-
-import javax.sql.DataSource;
+import java.util.List;
+import org.springframework.jdbc.core.BeanPropertyRowMapper;
import org.springframework.jdbc.core.JdbcTemplate;
-import org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate;
+import org.springframework.jdbc.core.namedparam.NamedParameterJdbcDaoSupport;
+
+import com.tivit.dominio.Categoria;
-public class CategoriaServiceFacadeImpl implements CategoriaServiceFacade {
+public class CategoriaServiceFacadeImpl extends NamedParameterJdbcDaoSupport
+ implements CategoriaServiceFacade {
private LivroServiceFacade livroService;
- private DataSource dataSource;
public LivroServiceFacade getLivroService() {
return livroService;
@@ -22,10 +23,6 @@ public void setLivroService(LivroServiceFacade livroService) {
this.livroService = livroService;
}
- public void setDataSource(DataSource dataSource) {
- this.dataSource = dataSource;
- }
-
public void incluir(final String nome) {
/*
* NamedParameterJdbcTemplate nm = new NamedParameterJdbcTemplate(
@@ -33,15 +30,32 @@ public void incluir(final String nome) {
* Object>(); paramMap.put("nome", nome);
* nm.update("insert into categoria(nome) values(:nome)", paramMap);
*/
- JdbcTemplate jt = new JdbcTemplate(dataSource);
+ JdbcTemplate jt = getJdbcTemplate();
jt.update("insert into categoria(tx_nome) values(?)", nome);
}
public void excluir(int id) {
livroService.excluirLivrosByCategoria(id);
- JdbcTemplate jt = new JdbcTemplate(dataSource);
+ JdbcTemplate jt = getJdbcTemplate();
jt.update("DELETE FROM CATEGORIA where SQ_ID = ?", id);
}
+ // tx_nome setTxNome
+ public List<Categoria> listarTodos() {
+ JdbcTemplate jt = getJdbcTemplate();
+
+ List<Categoria> l = jt.query("select * from categoria",
+ new BeanPropertyRowMapper<Categoria>());
+ return l;
+ }
+
+ public void alterar(Categoria c) {
+ HashMap<String, Object> hashMap = new HashMap<String, Object>();
+ hashMap.put("n", c.getTxNome());
+ hashMap.put("i", c.getSqId());
+
+ getNamedParameterJdbcTemplate().update(
+ "update categoria set tx_nome = :n where sq_id = :i", hashMap);
+ }
}
View
10 turma2/src/main/resources/applicationContext.xml
@@ -12,7 +12,7 @@
<context:property-placeholder location="classpath:jdbc.properties" />
- <bean id="dataSource"
+ <bean id="b2"
class="org.springframework.jdbc.datasource.DriverManagerDataSource">
<property name="driverClassName" value="${jdbc.driverClassName}" />
<property name="url" value="${jdbc.url}" />
@@ -23,18 +23,18 @@
<!-- <jee:jndi-lookup id="dataSource" ref="jdbc/dataSource" /> -->
<bean id="txManager"
class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
- <property name="dataSource" ref="dataSource" />
+ <property name="dataSource" ref="b2" />
</bean>
<!-- <context:component-scan base-package="code.services" /> <context:property-placeholder
location="classpath:mongodb.properties" /> <import resource="classpath:emailContext.xml"
/> -->
- <bean id="livroService" class="com.tivit.servicos.LivroServiceFacadeImpl" />
+ <bean id="a1" class="com.tivit.servicos.LivroServiceFacadeImpl" />
<bean id="categoriaService" class="com.tivit.servicos.CategoriaServiceFacadeImpl">
- <property name="livroService" ref="livroService" />
- <property name="dataSource" ref="dataSource" />
+ <property name="livroService" ref="a1" />
+ <property name="dataSource" ref="b2" />
</bean>
<bean id="autorService" class="com.tivit.servicos.AutorServiceFacadeImpl" />
Please sign in to comment.
Something went wrong with that request. Please try again.