9. <? xml version = "1.0" encoding = "UTF-8" ?> < beans xmlns = "http://www.springframework.org/schema/beans" xmlns:xsi = "http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation = "http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd" > < bean id = "dataSource” class = "org.springframework.jdbc.datasource.DriverManagerDataSource" lazy-init = "false" > < property name = "driverClassName" value = "org.hsqldb.jdbcDriver" /> < property name = "url" value = "jdbc:hsqldb:hsql://C:/db" /> < property name = "username" value = "sa" /> < property name = "password" value = "" /> </ bean > </ beans >
10.
11. <? xml version = "1.0" encoding = "UTF-8" ?> < beans xmlns = "http://www.springframework.org/schema/beans" xmlns:xsi = "http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation = "http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd" > < bean id = "dataSource" class = "org.springframework.jdbc.datasource.DriverManagerDataSource" lazy-init = "false" > < property name = "driverClassName" value = "org.hsqldb.jdbcDriver" /> < property name = "url” value = "jdbc:hsqldb:file:///C:targetspringdb" /> < property name = "username" value = "sa" /> < property name = "password“ value = "" /> </ bean > < bean id = "jdbcTemplate" class = "org.springframework.jdbc.core.JdbcTemplate" lazy-init = "false" > < property name = "dataSource" ref = "dataSource" /> < property name = "lazyInit" value = "false" /> </ bean > </ beans >
12.
13.
14. <? xml version = "1.0" encoding = "UTF-8" ?> < beans xmlns = "http://www.springframework.org/schema/beans" xmlns:xsi = "http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation = "http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd" > < bean id = "dataSource" class = "org.springframework.jdbc.datasource.DriverManagerDataSource” lazy-init = "false" > < property name = "driverClassName" value = "org.hsqldb.jdbcDriver" /> < property name = "url" value = "jdbc:hsqldb:file:///C:targetspringdb" /> < property name = "username" value = "sa" /> < property name = "password" value = "" /> </ bean > < bean id = "sessionFactory" class = "org.springframework.orm.hibernate3.LocalSessionFactoryBean" lazy-init = "false" > < property name = "dataSource" ref = "dataSource" /> < property name = "mappingResources" > < list > < value > com/targettrust/spring/hibernate/Pessoa.hbm.xml </ value > </ list > </ property > < property name = "hibernateProperties" > < props > < prop key = "hibernate.dialect" > org.hibernate.dialect.PointbaseDialect </ prop > < prop key = "hibernate.hbm2ddl.auto" > create </ prop > </ props > </ property > </ bean > </ beans >
15.
16.
17.
18. package com.targettrust.spring.hibernate; public class Pessoa { private Long id ; private String nome ; private String email ; // Getters e Setters } <? xml version = "1.0" encoding = "UTF-8" ?> <! DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD//EN" "http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd" > < hibernate-mapping > < class name = "com.targettrust.spring.hibernate.Pessoa" table = "pessoa" > < id name = "id" column = "id" type = "java.lang.Long" unsaved-value = "0" > < generator class = "increment" /> </ id > < property name = "nome" column = "nome" type = "java.lang.String" /> < property name = "email" column = "email" type = "java.lang.String" /> </ class > </ hibernate-mapping >
19. <? xml version = "1.0" encoding = "UTF-8" ?> < beans xmlns = "http://www.springframework.org/schema/beans" xmlns:xsi = "http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation = "http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd" > < bean id = "dataSource” lazy-init = "false” class = "org.springframework.jdbc.datasource.DriverManagerDataSource“ > < property name = "driverClassName" value = "org.hsqldb.jdbcDriver" /> < property name = "url" value = "jdbc:hsqldb:file:///C:targetspringdb" /> < property name = "username" value = "sa" /> < property name = "password" value = "" /> </ bean > < bean id = "sessionFactory“ lazy-init = "false" class = "org.springframework.orm.hibernate3.LocalSessionFactoryBean“ > < property name = "dataSource" ref = "dataSource" /> < property name = "mappingResources" > < list >< value > com/targettrust/spring/hibernate/Pessoa.hbm.xml </ value ></ list > </ property > < property name = "hibernateProperties" > < props > < prop key = "hibernate.dialect" > org.hibernate.dialect.PointbaseDialect </ prop > </ props > </ property > </ bean > < bean id = "hibernateTemplate“ lazy-init = "false” class = "org.springframework.orm.hibernate3.HibernateTemplate“ > < property name = "sessionFactory" ref = "sessionFactory" /> </ bean > </ beans >
20.
21.
22.
23.
24. <!-- Defini ç ão do Dataource para acesso ao banco HSQLDB --> < bean id = "dataSource" class = "org.springframework.jdbc.datasource.DriverManagerDataSource" lazy-init = "false" > < property name = "driverClassName" value = "org.hsqldb.jdbcDriver" /> < property name = "url" value = "jdbc:hsqldb:file:///C:targetspringdb" /> <property name = "username" value = "sa" /> < property name = "password" value = "" /> </ bean >
25. <!-- Defini ç ão da SessionFactory do Hibernate --> < bean id = "sessionFactory" class = "org.springframework.orm.hibernate3.LocalSessionFactoryBean" lazy-init = "false" > < property name = "dataSource" ref = "dataSource" /> < property name = "mappingResources" > < list > < value > com/targettrust/spring/transaction/Produto.hbm.xml </ value > </ list > </ property > < property name = "hibernateProperties" > < props > < prop key = "hibernate.dialect" > org.hibernate.dialect.HSQLDialect </ prop > </ props > </ property ></ bean >
26. <!-- Defini ç ão do TransactionManager, nesse caso o escolhido para a tarefa de gerencia as transa ç ões foi o org.springframework.orm.hibernate3.HibernateTransactionManager que gerencia transa ç ões entre Hibernate e JDBC pelo DataSource --> < bean id = "txManager" class = "org.springframework.orm.hibernate3.HibernateTransactionManager" > < property name = "sessionFactory" ref = "sessionFactory" /> </ bean >
27. define os pontos do sistema que seram interceptados, nesse caso é a execu ç ão de qaulquer metodos do ProdutoService. Depois ele vincula essas classes interceptadas com um advice o txAdvice; --> < aop:config > < aop:pointcut id = "produtoServiceMetodos" expression = "execution(* com.targettrust.spring.transaction.ProdutoService.*(..))" /> < aop:advisor advice-ref = "txAdvice" pointcut-ref = "produtoServiceMetodos" /> </ aop:config >
28. <!-- Defini ç ão do Advide AOP que casa o gerente de transa ç ões com os metodos Esse beans informa que metodos e como esses metodos devem ser tratados pela transa ç ão --> < tx:advice id = "txAdvice" transaction-manager = "txManager" > < tx:attributes > < tx:method name = "salvar*" propagation = "REQUIRED" /> < tx:method name = "findAll" propagation = "REQUIRED" read-only = "true" /> </ tx:attributes ></ tx:advice >