diff --git a/spring-batch-samples/.springBeans b/spring-batch-samples/.springBeans index ab8a45ad9..e9febe203 100644 --- a/spring-batch-samples/.springBeans +++ b/spring-batch-samples/.springBeans @@ -46,6 +46,7 @@ src/main/resources/jobs/iosample/xml.xml src/main/resources/jobs/iosample/hibernate.xml src/main/resources/jobs/hibernateJob.xml + src/main/resources/jobs/iosample/jpa.xml @@ -428,5 +429,18 @@ src/main/resources/simple-job-launcher-context.xml + + + true + false + + src/main/resources/data-source-context.xml + src/main/resources/data-source-context-init.xml + src/main/resources/jobs/iosample/jpa.xml + src/main/resources/jobs/ioSampleJob.xml + src/main/resources/org/springframework/batch/sample/config/common-context.xml + src/main/resources/simple-job-launcher-context.xml + + diff --git a/spring-batch-samples/pom.xml b/spring-batch-samples/pom.xml index 41f0e5608..b89827dba 100644 --- a/spring-batch-samples/pom.xml +++ b/spring-batch-samples/pom.xml @@ -125,6 +125,21 @@ org.hibernate com.springsource.org.hibernate + + org.hibernate + com.springsource.org.hibernate.ejb + true + + + org.hibernate + com.springsource.org.hibernate.annotations + true + + + javax.persistence + com.springsource.javax.persistence + true + javax.transaction com.springsource.javax.transaction diff --git a/spring-batch-samples/src/main/java/org/springframework/batch/sample/domain/trade/CustomerCredit.java b/spring-batch-samples/src/main/java/org/springframework/batch/sample/domain/trade/CustomerCredit.java index 38bd5d166..589ad581b 100644 --- a/spring-batch-samples/src/main/java/org/springframework/batch/sample/domain/trade/CustomerCredit.java +++ b/spring-batch-samples/src/main/java/org/springframework/batch/sample/domain/trade/CustomerCredit.java @@ -18,30 +18,39 @@ package org.springframework.batch.sample.domain.trade; import java.math.BigDecimal; +import javax.persistence.Entity; +import javax.persistence.Id; +import javax.persistence.Table; +@Entity +@Table(name = "CUSTOMER") public class CustomerCredit { + + @Id private int id; - private String name; - private BigDecimal credit; - - public CustomerCredit(){ - } - - public CustomerCredit(int id, String name, BigDecimal credit){ + + private String name; + + private BigDecimal credit; + + public CustomerCredit() { + } + + public CustomerCredit(int id, String name, BigDecimal credit) { this.id = id; this.name = name; this.credit = credit; } public String toString() { - return "CustomerCredit [id=" + id +",name=" + name + ", credit=" + credit + "]"; - } + return "CustomerCredit [id=" + id + ",name=" + name + ", credit=" + credit + "]"; + } - public BigDecimal getCredit() { - return credit; - } + public BigDecimal getCredit() { + return credit; + } - public int getId() { + public int getId() { return id; } @@ -50,31 +59,31 @@ public class CustomerCredit { } public void setCredit(BigDecimal credit) { - this.credit = credit; - } + this.credit = credit; + } - public String getName() { - return name; - } + public String getName() { + return name; + } - public void setName(String name) { - this.name = name; - } - - public CustomerCredit increaseCreditBy(BigDecimal sum) { - CustomerCredit newCredit = new CustomerCredit(); - newCredit.credit = this.credit.add(sum); - newCredit.name = this.name; - newCredit.id = this.id; - return newCredit; - } - - public boolean equals(Object o) { - return (o instanceof CustomerCredit) && ((CustomerCredit)o).id==id; + public void setName(String name) { + this.name = name; + } + + public CustomerCredit increaseCreditBy(BigDecimal sum) { + CustomerCredit newCredit = new CustomerCredit(); + newCredit.credit = this.credit.add(sum); + newCredit.name = this.name; + newCredit.id = this.id; + return newCredit; + } + + public boolean equals(Object o) { + return (o instanceof CustomerCredit) && ((CustomerCredit) o).id == id; } public int hashCode() { return id; } - + } diff --git a/spring-batch-samples/src/main/resources/META-INF/persistence.xml b/spring-batch-samples/src/main/resources/META-INF/persistence.xml new file mode 100644 index 000000000..bc3353f67 --- /dev/null +++ b/spring-batch-samples/src/main/resources/META-INF/persistence.xml @@ -0,0 +1,13 @@ + + + + + org.springframework.batch.sample.domain.trade.CustomerCredit + true + + + + \ No newline at end of file diff --git a/spring-batch-samples/src/main/resources/jobs/iosample/jpa.xml b/spring-batch-samples/src/main/resources/jobs/iosample/jpa.xml new file mode 100644 index 000000000..8fb859dac --- /dev/null +++ b/spring-batch-samples/src/main/resources/jobs/iosample/jpa.xml @@ -0,0 +1,44 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/spring-batch-samples/src/test/java/org/springframework/batch/sample/iosample/JpaFunctionalTests.java b/spring-batch-samples/src/test/java/org/springframework/batch/sample/iosample/JpaFunctionalTests.java new file mode 100644 index 000000000..ca97c7b93 --- /dev/null +++ b/spring-batch-samples/src/test/java/org/springframework/batch/sample/iosample/JpaFunctionalTests.java @@ -0,0 +1,19 @@ +package org.springframework.batch.sample.iosample; + +import org.junit.runner.RunWith; +import org.springframework.batch.item.ItemReader; +import org.springframework.batch.sample.domain.trade.CustomerCredit; +import org.springframework.test.context.ContextConfiguration; +import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; + +@RunWith(SpringJUnit4ClassRunner.class) +@ContextConfiguration(locations = { "/simple-job-launcher-context.xml", "/jobs/ioSampleJob.xml", + "/jobs/iosample/jpa.xml" }) +public class JpaFunctionalTests extends AbstractIoSampleTests { + + @Override + protected void pointReaderToOutput(ItemReader reader) { + // no-op + } + +}