Author: epbernard
Date: 2010-07-20 05:05:09 -0400 (Tue, 20 Jul 2010)
New Revision: 19971
Added:
search/trunk/hibernate-search-integrationtest/
search/trunk/hibernate-search-integrationtest/pom.xml
search/trunk/hibernate-search-integrationtest/src/
search/trunk/hibernate-search-integrationtest/src/test/
search/trunk/hibernate-search-integrationtest/src/test/java/
search/trunk/hibernate-search-integrationtest/src/test/java/org/
search/trunk/hibernate-search-integrationtest/src/test/java/org/hibernate/
search/trunk/hibernate-search-integrationtest/src/test/java/org/hibernate/search/
search/trunk/hibernate-search-integrationtest/src/test/java/org/hibernate/search/test/
search/trunk/hibernate-search-integrationtest/src/test/java/org/hibernate/search/test/integration/
search/trunk/hibernate-search-integrationtest/src/test/java/org/hibernate/search/test/integration/jtaspring/
search/trunk/hibernate-search-integrationtest/src/test/java/org/hibernate/search/test/integration/jtaspring/AbstractEntity.java
search/trunk/hibernate-search-integrationtest/src/test/java/org/hibernate/search/test/integration/jtaspring/Box.java
search/trunk/hibernate-search-integrationtest/src/test/java/org/hibernate/search/test/integration/jtaspring/BoxDAO.java
search/trunk/hibernate-search-integrationtest/src/test/java/org/hibernate/search/test/integration/jtaspring/BoxRun.java
search/trunk/hibernate-search-integrationtest/src/test/java/org/hibernate/search/test/integration/jtaspring/Container.java
search/trunk/hibernate-search-integrationtest/src/test/java/org/hibernate/search/test/integration/jtaspring/Doughnut.java
search/trunk/hibernate-search-integrationtest/src/test/java/org/hibernate/search/test/integration/jtaspring/JtaAndSpringMoreComplexTest.java
search/trunk/hibernate-search-integrationtest/src/test/java/org/hibernate/search/test/integration/jtaspring/JtaAndSpringTest.java
search/trunk/hibernate-search-integrationtest/src/test/java/org/hibernate/search/test/integration/jtaspring/Muffin.java
search/trunk/hibernate-search-integrationtest/src/test/java/org/hibernate/search/test/integration/jtaspring/MuffinDAO.java
search/trunk/hibernate-search-integrationtest/src/test/java/org/hibernate/search/test/integration/jtaspring/Snert.java
search/trunk/hibernate-search-integrationtest/src/test/java/org/hibernate/search/test/integration/jtaspring/SnertDAO.java
search/trunk/hibernate-search-integrationtest/src/test/resources/
search/trunk/hibernate-search-integrationtest/src/test/resources/beans.xml
search/trunk/hibernate-search-integrationtest/src/test/resources/log4j.properties
search/trunk/hibernate-search-integrationtest/src/test/resources/persistence.xml
Modified:
search/trunk/pom.xml
Log:
HSEARCH-561 Add integration test module
It contains a test using both Spring Framework and a JTA transaction manager.
TODO: convert Bitronix to JBossTS
Added: search/trunk/hibernate-search-integrationtest/pom.xml
===================================================================
--- search/trunk/hibernate-search-integrationtest/pom.xml (rev 0)
+++ search/trunk/hibernate-search-integrationtest/pom.xml 2010-07-20 09:05:09 UTC (rev
19971)
@@ -0,0 +1,156 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project
xmlns="http://maven.apache.org/POM/4.0.0"
+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
http://maven.apache.org/maven-v4_0_0.xsd">
+
+ <modelVersion>4.0.0</modelVersion>
+
+ <parent>
+ <artifactId>hibernate-search-parent</artifactId>
+ <groupId>org.hibernate</groupId>
+ <version>3.3.0-SNAPSHOT</version>
+ <relativePath>../pom.xml</relativePath>
+ </parent>
+
+ <artifactId>hibernate-search-integrationtest</artifactId>
+
+ <name>Hibernate Search integration test</name>
+ <description>Hibernate Search integration tests. In particular with Spring
Framework and JTA</description>
+
+ <properties>
+ <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
+ <spring-release-version>3.0.2.RELEASE</spring-release-version>
+ </properties>
+
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-deploy-plugin</artifactId>
+ <version>2.4</version>
+ <configuration>
+ <skip>true</skip>
+ </configuration>
+ </plugin>
+ </plugins>
+ </build>
+
+
+ <dependencies>
+
+ <!-- Hibernate -->
+ <dependency>
+ <groupId>${groupId}</groupId>
+ <artifactId>hibernate-search</artifactId>
+ <version>${version}</version>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.hibernate</groupId>
+ <artifactId>hibernate-entitymanager</artifactId>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.hibernate</groupId>
+ <artifactId>hibernate-testing</artifactId>
+ <version>${hibernateVersion}</version>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>javassist</groupId>
+ <artifactId>javassist</artifactId>
+ <version>3.12.0.GA</version>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>cglib</groupId>
+ <artifactId>cglib</artifactId>
+ <version>2.2</version>
+ <scope>test</scope>
+ </dependency>
+
+ <!-- test -->
+ <dependency>
+ <groupId>junit</groupId>
+ <artifactId>junit</artifactId>
+ <version>4.7</version>
+ <!-- override version for annotation based JUnit -->
+ <scope>test</scope>
+ </dependency>
+
+ <!-- Spring Framework -->
+ <dependency>
+ <groupId>org.springframework</groupId>
+ <artifactId>spring-core</artifactId>
+ <version>${spring-release-version}</version>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.springframework</groupId>
+ <artifactId>spring-aop</artifactId>
+ <version>${spring-release-version}</version>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.springframework</groupId>
+ <artifactId>spring-orm</artifactId>
+ <version>${spring-release-version}</version>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.springframework</groupId>
+ <artifactId>spring-context</artifactId>
+ <version>${spring-release-version}</version>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.springframework</groupId>
+ <artifactId>spring-context-support</artifactId>
+ <version>${spring-release-version}</version>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.springframework</groupId>
+ <artifactId>spring-webmvc</artifactId>
+ <version>${spring-release-version}</version>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.springframework</groupId>
+ <artifactId>spring-tx</artifactId>
+ <version>${spring-release-version}</version>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.springframework</groupId>
+ <artifactId>spring-test</artifactId>
+ <version>${spring-release-version}</version>
+ <scope>test</scope>
+ </dependency>
+
+ <!-- JSR 330 - @Inject annotation -->
+ <dependency>
+ <groupId>javax.inject</groupId>
+ <artifactId>javax.inject</artifactId>
+ <version>1</version>
+ <scope>test</scope>
+ </dependency>
+
+ <!-- Bitronix Transaction Manager -->
+ <dependency>
+ <groupId>org.codehaus.btm</groupId>
+ <artifactId>btm</artifactId>
+ <version>2.0.0</version>
+ <scope>test</scope>
+ </dependency>
+
+ <dependency>
+ <groupId>com.h2database</groupId>
+ <artifactId>h2</artifactId>
+ <version>1.2.139</version>
+ <scope>test</scope>
+ </dependency>
+
+ </dependencies>
+
+</project>
\ No newline at end of file
Property changes on: search/trunk/hibernate-search-integrationtest/pom.xml
___________________________________________________________________
Name: svn:executable
+ *
Added:
search/trunk/hibernate-search-integrationtest/src/test/java/org/hibernate/search/test/integration/jtaspring/AbstractEntity.java
===================================================================
---
search/trunk/hibernate-search-integrationtest/src/test/java/org/hibernate/search/test/integration/jtaspring/AbstractEntity.java
(rev 0)
+++
search/trunk/hibernate-search-integrationtest/src/test/java/org/hibernate/search/test/integration/jtaspring/AbstractEntity.java 2010-07-20
09:05:09 UTC (rev 19971)
@@ -0,0 +1,37 @@
+package org.hibernate.search.test.integration.jtaspring;
+
+import java.util.UUID;
+
+import javax.persistence.Column;
+import javax.persistence.MappedSuperclass;
+
+import org.hibernate.annotations.NaturalId;
+
+@MappedSuperclass
+public abstract class AbstractEntity {
+
+ @NaturalId(mutable=true)
+ @Column(length=36)
+ private String magicKey_;
+
+ /**
+ * Sets the magic key for the instance
+ */
+ public AbstractEntity() {
+ magicKey_ = UUID.randomUUID().toString();
+ }
+
+ /**
+ * @return the magicKey
+ */
+ public String getMagicKey() {
+ return magicKey_;
+ }
+
+ /**
+ * @param magicKey the magicKey to set
+ */
+ public void setMagicKey(String magicKey) {
+ magicKey_ = magicKey;
+ }
+}
Added:
search/trunk/hibernate-search-integrationtest/src/test/java/org/hibernate/search/test/integration/jtaspring/Box.java
===================================================================
---
search/trunk/hibernate-search-integrationtest/src/test/java/org/hibernate/search/test/integration/jtaspring/Box.java
(rev 0)
+++
search/trunk/hibernate-search-integrationtest/src/test/java/org/hibernate/search/test/integration/jtaspring/Box.java 2010-07-20
09:05:09 UTC (rev 19971)
@@ -0,0 +1,81 @@
+package org.hibernate.search.test.integration.jtaspring;
+
+import java.util.HashSet;
+import java.util.Set;
+
+import javax.persistence.CascadeType;
+import javax.persistence.Entity;
+import javax.persistence.FetchType;
+import javax.persistence.OneToMany;
+
+import org.apache.lucene.analysis.standard.StandardAnalyzer;
+import org.hibernate.annotations.Cache;
+import org.hibernate.annotations.CacheConcurrencyStrategy;
+import org.hibernate.annotations.ForeignKey;
+import org.hibernate.search.annotations.Analyzer;
+import org.hibernate.search.annotations.Indexed;
+
+@Entity
+@Cache(usage = CacheConcurrencyStrategy.TRANSACTIONAL, region="container")
+
+@Indexed(index="container")
+@Analyzer(impl = StandardAnalyzer.class)
+public class Box extends Container {
+ @OneToMany(mappedBy="box", cascade={ CascadeType.MERGE, CascadeType.REMOVE,
CascadeType.REFRESH, CascadeType.PERSIST }, fetch=FetchType.LAZY)
+ @ForeignKey(name="FK_Box_Muffins")
+ private Set<Muffin> muffinSet;
+
+ @OneToMany(mappedBy="box", cascade={ CascadeType.MERGE, CascadeType.REMOVE,
CascadeType.REFRESH, CascadeType.PERSIST }, fetch=FetchType.LAZY)
+ @ForeignKey(name="FK_Box_Doughnuts")
+ private Set<Doughnut> doughnutSet;
+
+ public Box() {
+ }
+
+ /**
+ * @return the color
+ */
+ public void addMuffin(Muffin muffin) {
+ if (muffinSet == null) {
+ muffinSet = new HashSet<Muffin>();
+ }
+
+ muffinSet.add(muffin);
+ }
+
+ /**
+ * @return the muffinSet
+ */
+ public Set<Muffin> getMuffinSet() {
+ return muffinSet;
+ }
+
+ /**
+ * @param muffinSet the muffinSet to set
+ */
+ public void setMuffinSet(Set<Muffin> muffinSet) {
+ this.muffinSet = muffinSet;
+ }
+
+ /**
+ * @return the doughnutSet
+ */
+ public Set<Doughnut> getDoughnutSet() {
+ return doughnutSet;
+ }
+
+ /**
+ * @param doughnutSet the doughnutSet to set
+ */
+ public void setDoughnutSet(Set<Doughnut> doughnutSet) {
+ this.doughnutSet = doughnutSet;
+ }
+
+ public void addDoughnut(Doughnut doughnut) {
+ if (doughnutSet == null) {
+ doughnutSet = new HashSet<Doughnut>();
+ }
+
+ doughnutSet.add(doughnut);
+ }
+}
Added:
search/trunk/hibernate-search-integrationtest/src/test/java/org/hibernate/search/test/integration/jtaspring/BoxDAO.java
===================================================================
---
search/trunk/hibernate-search-integrationtest/src/test/java/org/hibernate/search/test/integration/jtaspring/BoxDAO.java
(rev 0)
+++
search/trunk/hibernate-search-integrationtest/src/test/java/org/hibernate/search/test/integration/jtaspring/BoxDAO.java 2010-07-20
09:05:09 UTC (rev 19971)
@@ -0,0 +1,38 @@
+package org.hibernate.search.test.integration.jtaspring;
+
+import javax.persistence.EntityManager;
+import javax.persistence.PersistenceContext;
+
+import org.springframework.stereotype.Repository;
+import org.springframework.transaction.annotation.Transactional;
+
+@Repository
+public class BoxDAO {
+ @PersistenceContext
+ private EntityManager entityManager;
+
+ @Transactional
+ public void persist(Box box) {
+ entityManager.persist(box);
+// entityManager.flush();
+ }
+
+ @Transactional
+ public Box merge(Box box) {
+ Box result = entityManager.merge(box);
+
+// entityManager.flush();
+
+ return result;
+ }
+
+ @Transactional
+ public void remove(Box box) {
+ entityManager.remove(box);
+// entityManager.flush();
+ }
+
+ public EntityManager getEntityManager() {
+ return entityManager;
+ }
+}
Added:
search/trunk/hibernate-search-integrationtest/src/test/java/org/hibernate/search/test/integration/jtaspring/BoxRun.java
===================================================================
---
search/trunk/hibernate-search-integrationtest/src/test/java/org/hibernate/search/test/integration/jtaspring/BoxRun.java
(rev 0)
+++
search/trunk/hibernate-search-integrationtest/src/test/java/org/hibernate/search/test/integration/jtaspring/BoxRun.java 2010-07-20
09:05:09 UTC (rev 19971)
@@ -0,0 +1,28 @@
+package org.hibernate.search.test.integration.jtaspring;
+
+import org.springframework.context.ApplicationContext;
+import org.springframework.context.support.ClassPathXmlApplicationContext;
+
+public class BoxRun {
+ private ApplicationContext applicationContext = new
ClassPathXmlApplicationContext("classpath:beans.xml");
+
+ public void run() {
+ BoxDAO boxDAO = (BoxDAO) applicationContext.getBean("boxDAO");
+
+ Box box = new Box();
+ box.setColor("red-and-white");
+ boxDAO.persist(box);
+
+ Muffin muffin = new Muffin();
+ muffin.setKind("blueberry");
+ muffin.setBox(box);
+
+ box.addMuffin(muffin);
+
+ boxDAO.merge(box);
+ }
+
+ public static void main(String args[]) {
+ new BoxRun().run();
+ }
+}
Added:
search/trunk/hibernate-search-integrationtest/src/test/java/org/hibernate/search/test/integration/jtaspring/Container.java
===================================================================
---
search/trunk/hibernate-search-integrationtest/src/test/java/org/hibernate/search/test/integration/jtaspring/Container.java
(rev 0)
+++
search/trunk/hibernate-search-integrationtest/src/test/java/org/hibernate/search/test/integration/jtaspring/Container.java 2010-07-20
09:05:09 UTC (rev 19971)
@@ -0,0 +1,61 @@
+package org.hibernate.search.test.integration.jtaspring;
+
+import javax.persistence.Column;
+import javax.persistence.DiscriminatorColumn;
+import javax.persistence.DiscriminatorType;
+import javax.persistence.Entity;
+import javax.persistence.GeneratedValue;
+import javax.persistence.GenerationType;
+import javax.persistence.Id;
+import javax.persistence.Inheritance;
+import javax.persistence.InheritanceType;
+import javax.persistence.Table;
+
+import org.apache.lucene.analysis.standard.StandardAnalyzer;
+import org.hibernate.annotations.Cache;
+import org.hibernate.annotations.CacheConcurrencyStrategy;
+import org.hibernate.search.annotations.Analyzer;
+import org.hibernate.search.annotations.Indexed;
+
+@Entity
+(a)Inheritance(strategy=InheritanceType.SINGLE_TABLE)
+@Table(name="container")
+@DiscriminatorColumn(name = "containerType", discriminatorType =
DiscriminatorType.STRING)
+
+@Cache(usage = CacheConcurrencyStrategy.TRANSACTIONAL, region="container")
+
+@Indexed(index="container")
+@Analyzer(impl = StandardAnalyzer.class)
+public class Container extends AbstractEntity {
+ @Id()
+ @GeneratedValue(strategy = GenerationType.AUTO)
+ private Long containerId;
+
+ @Column(length = 255)
+ private String color;
+
+ /**
+ * @return the containerId
+ */
+ public Long getContainerId() {
+ return containerId;
+ }
+
+ /**
+ * @param containerId the containerId to set
+ */
+ public void setContainerId(Long containerId) {
+ this.containerId = containerId;
+ }
+
+ public String getColor() {
+ return color;
+ }
+
+ /**
+ * @param color the color to set
+ */
+ public void setColor(String color) {
+ this.color = color;
+ }
+}
Added:
search/trunk/hibernate-search-integrationtest/src/test/java/org/hibernate/search/test/integration/jtaspring/Doughnut.java
===================================================================
---
search/trunk/hibernate-search-integrationtest/src/test/java/org/hibernate/search/test/integration/jtaspring/Doughnut.java
(rev 0)
+++
search/trunk/hibernate-search-integrationtest/src/test/java/org/hibernate/search/test/integration/jtaspring/Doughnut.java 2010-07-20
09:05:09 UTC (rev 19971)
@@ -0,0 +1,77 @@
+package org.hibernate.search.test.integration.jtaspring;
+
+import javax.persistence.Column;
+import javax.persistence.Entity;
+import javax.persistence.GeneratedValue;
+import javax.persistence.GenerationType;
+import javax.persistence.Id;
+import javax.persistence.ManyToOne;
+import javax.persistence.Table;
+
+import org.apache.lucene.analysis.standard.StandardAnalyzer;
+import org.hibernate.annotations.Cache;
+import org.hibernate.annotations.CacheConcurrencyStrategy;
+import org.hibernate.search.annotations.Analyzer;
+import org.hibernate.search.annotations.Indexed;
+
+//Hibernate
+@Entity
+@Table(name = "doughnut")
+(a)Cache(usage=CacheConcurrencyStrategy.TRANSACTIONAL, region="doughnut")
+// Hibernate Search
+@Indexed(index="Doughnut")
+@Analyzer(impl = StandardAnalyzer.class)
+public class Doughnut {
+ @Id()
+ @GeneratedValue(strategy = GenerationType.AUTO)
+ private Long doughnutId;
+
+ @ManyToOne
+ private Box box;
+
+ @Column(length = 255,nullable=false)
+ private String kind;
+
+ /**
+ * @return the doughnutId
+ */
+ public Long getDoughnutId() {
+ return doughnutId;
+ }
+
+ /**
+ * @param doughnutId the doughnutId to set
+ */
+ public void setDoughnutId(Long doughnutId) {
+ this.doughnutId = doughnutId;
+ }
+
+ /**
+ * @return the box
+ */
+ public Box getBox() {
+ return box;
+ }
+
+ /**
+ * @param box the box to set
+ */
+ public void setBox(Box box) {
+ this.box = box;
+ }
+
+ /**
+ * @return the kind
+ */
+ public String getKind() {
+ return kind;
+ }
+
+ /**
+ * @param kind the kind to set
+ */
+ public void setKind(String kind) {
+ this.kind = kind;
+ }
+
+}
Added:
search/trunk/hibernate-search-integrationtest/src/test/java/org/hibernate/search/test/integration/jtaspring/JtaAndSpringMoreComplexTest.java
===================================================================
---
search/trunk/hibernate-search-integrationtest/src/test/java/org/hibernate/search/test/integration/jtaspring/JtaAndSpringMoreComplexTest.java
(rev 0)
+++
search/trunk/hibernate-search-integrationtest/src/test/java/org/hibernate/search/test/integration/jtaspring/JtaAndSpringMoreComplexTest.java 2010-07-20
09:05:09 UTC (rev 19971)
@@ -0,0 +1,47 @@
+package org.hibernate.search.test.integration.jtaspring;
+
+import javax.inject.Inject;
+
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.springframework.test.context.ContextConfiguration;
+import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
+
+(a)RunWith(SpringJUnit4ClassRunner.class)
+@ContextConfiguration(locations={"classpath*:beans.xml"})
+//@TransactionConfiguration(transactionManager="transactionManager",defaultRollback=false)
+//@Transactional
+public class JtaAndSpringMoreComplexTest {
+ @Inject
+ private BoxDAO boxDAO;
+
+ @Test
+ public void testMufins() throws Exception {
+ Box box = new Box();
+ box.setColor("red-and-white");
+ boxDAO.persist(box);
+
+ Muffin muffin = new Muffin();
+ muffin.setKind("blueberry");
+ muffin.setBox(box);
+
+ box.addMuffin(muffin);
+
+ boxDAO.merge(box);
+ }
+
+ @Test
+ public void testDoughnuts() throws Exception {
+ Box box = new Box();
+ box.setColor("red-and-white");
+ boxDAO.persist(box);
+
+ Doughnut doughnut = new Doughnut();
+ doughnut.setKind("glazed");
+ doughnut.setBox(box);
+
+ box.addDoughnut(doughnut);
+
+ boxDAO.merge(box);
+ }
+}
Added:
search/trunk/hibernate-search-integrationtest/src/test/java/org/hibernate/search/test/integration/jtaspring/JtaAndSpringTest.java
===================================================================
---
search/trunk/hibernate-search-integrationtest/src/test/java/org/hibernate/search/test/integration/jtaspring/JtaAndSpringTest.java
(rev 0)
+++
search/trunk/hibernate-search-integrationtest/src/test/java/org/hibernate/search/test/integration/jtaspring/JtaAndSpringTest.java 2010-07-20
09:05:09 UTC (rev 19971)
@@ -0,0 +1,31 @@
+package org.hibernate.search.test.integration.jtaspring;
+
+import javax.inject.Inject;
+
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.springframework.test.context.ContextConfiguration;
+import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
+import org.springframework.test.context.transaction.TransactionConfiguration;
+import org.springframework.transaction.annotation.Transactional;
+
+(a)RunWith(SpringJUnit4ClassRunner.class)
+@ContextConfiguration(locations={"classpath*:beans.xml"})
+@TransactionConfiguration(transactionManager="transactionManager",defaultRollback=false)
+@Transactional
+public class JtaAndSpringTest {
+ @Inject
+ private SnertDAO snertDAO;
+
+ @Test
+ public void test() {
+ Snert snert = new Snert();
+
+ snert.setName("dave");
+ snert.setNickname("dude");
+ snert.setAge(99);
+ snert.setCool(Boolean.TRUE);
+
+ snertDAO.persist(snert);
+ }
+}
Added:
search/trunk/hibernate-search-integrationtest/src/test/java/org/hibernate/search/test/integration/jtaspring/Muffin.java
===================================================================
---
search/trunk/hibernate-search-integrationtest/src/test/java/org/hibernate/search/test/integration/jtaspring/Muffin.java
(rev 0)
+++
search/trunk/hibernate-search-integrationtest/src/test/java/org/hibernate/search/test/integration/jtaspring/Muffin.java 2010-07-20
09:05:09 UTC (rev 19971)
@@ -0,0 +1,78 @@
+package org.hibernate.search.test.integration.jtaspring;
+
+import javax.persistence.Column;
+import javax.persistence.Entity;
+import javax.persistence.GeneratedValue;
+import javax.persistence.GenerationType;
+import javax.persistence.Id;
+import javax.persistence.ManyToOne;
+import javax.persistence.Table;
+
+import org.hibernate.annotations.Cache;
+import org.hibernate.annotations.CacheConcurrencyStrategy;
+
+// Hibernate
+@Entity
+@Table(name = "muffin")
+(a)Cache(usage=CacheConcurrencyStrategy.TRANSACTIONAL, region="muffin")
+// Hibernate Search
+//@Indexed(index="Muffin")
+//@Analyzer(impl = StandardAnalyzer.class)
+public class Muffin {
+ @Id()
+ @GeneratedValue(strategy = GenerationType.AUTO)
+ private Long muffinId;
+
+ @ManyToOne
+ private Box box;
+
+ @Column(length = 255,nullable=false)
+ private String kind;
+
+ public Muffin() {
+ }
+
+ /**
+ * @return the muffinId
+ */
+ public Long getMuffinId() {
+ return muffinId;
+ }
+
+ /**
+ * @param muffinId the muffinId to set
+ */
+ public void setMuffinId(Long muffinId) {
+ this.muffinId = muffinId;
+ }
+
+ /**
+ * @return the box
+ */
+ public Box getBox() {
+ return box;
+ }
+
+ /**
+ * @param box the box to set
+ */
+ public void setBox(Box box) {
+ this.box = box;
+ }
+
+ /**
+ * @return the kind
+ */
+ public String getKind() {
+ return kind;
+ }
+
+ /**
+ * @param kind the kind to set
+ */
+ public void setKind(String kind) {
+ this.kind = kind;
+ }
+
+
+}
Added:
search/trunk/hibernate-search-integrationtest/src/test/java/org/hibernate/search/test/integration/jtaspring/MuffinDAO.java
===================================================================
---
search/trunk/hibernate-search-integrationtest/src/test/java/org/hibernate/search/test/integration/jtaspring/MuffinDAO.java
(rev 0)
+++
search/trunk/hibernate-search-integrationtest/src/test/java/org/hibernate/search/test/integration/jtaspring/MuffinDAO.java 2010-07-20
09:05:09 UTC (rev 19971)
@@ -0,0 +1,28 @@
+package org.hibernate.search.test.integration.jtaspring;
+
+import javax.persistence.EntityManager;
+import javax.persistence.PersistenceContext;
+
+import org.springframework.stereotype.Repository;
+import org.springframework.transaction.annotation.Transactional;
+
+@Repository
+public class MuffinDAO {
+ @PersistenceContext
+ private EntityManager entityManager;
+
+ @Transactional
+ public void persist(Muffin muffin) {
+ entityManager.persist(muffin);
+ }
+
+ @Transactional
+ public void merge(Muffin muffin) {
+ entityManager.merge(muffin);
+ }
+
+ @Transactional
+ public void remove(Muffin muffin) {
+ entityManager.remove(muffin);
+ }
+}
Added:
search/trunk/hibernate-search-integrationtest/src/test/java/org/hibernate/search/test/integration/jtaspring/Snert.java
===================================================================
---
search/trunk/hibernate-search-integrationtest/src/test/java/org/hibernate/search/test/integration/jtaspring/Snert.java
(rev 0)
+++
search/trunk/hibernate-search-integrationtest/src/test/java/org/hibernate/search/test/integration/jtaspring/Snert.java 2010-07-20
09:05:09 UTC (rev 19971)
@@ -0,0 +1,143 @@
+package org.hibernate.search.test.integration.jtaspring;
+
+import java.util.Date;
+
+import javax.persistence.Column;
+import javax.persistence.Entity;
+import javax.persistence.GeneratedValue;
+import javax.persistence.GenerationType;
+import javax.persistence.Id;
+import javax.persistence.Table;
+
+import org.apache.lucene.analysis.standard.StandardAnalyzer;
+import org.hibernate.annotations.Cache;
+import org.hibernate.annotations.CacheConcurrencyStrategy;
+import org.hibernate.search.annotations.Analyzer;
+import org.hibernate.search.annotations.DocumentId;
+import org.hibernate.search.annotations.Field;
+import org.hibernate.search.annotations.Index;
+import org.hibernate.search.annotations.Indexed;
+import org.hibernate.search.annotations.Store;
+import org.hibernate.search.annotations.TermVector;
+
+@Entity
+@Table(name = "snert")
+(a)Cache(usage=CacheConcurrencyStrategy.TRANSACTIONAL, region="snert")
+
+// full text search
+@Indexed(index="Snert")
+@Analyzer(impl = StandardAnalyzer.class)
+
+public class Snert {
+
+ @Id()
+ @GeneratedValue(strategy = GenerationType.AUTO)
+ @DocumentId
+ private Long id;
+
+ @Column(nullable=true)
+ private Date birthday;
+
+ @Column(length = 255)
+ @Field(index = Index.TOKENIZED, store = Store.NO, termVector = TermVector.YES)
+ private String name;
+
+ @Column(length=24)
+ private String nickname;
+
+ @Field(index=Index.UN_TOKENIZED, store=Store.NO)
+ private Boolean cool;
+
+ @Column(name="readCount")
+ @Field(index=Index.UN_TOKENIZED, store=Store.YES)
+ private int age;
+
+ public Snert() {
+ }
+
+ /**
+ * @return the id
+ */
+ public Long getId() {
+ return id;
+ }
+
+ /**
+ * @param id the id to set
+ */
+ public void setId(Long id) {
+ this.id = id;
+ }
+
+ /**
+ * @return the birthday
+ */
+ public Date getBirthday() {
+ return birthday;
+ }
+
+ /**
+ * @param birthday the birthday to set
+ */
+ public void setBirthday(Date birthday) {
+ this.birthday = birthday;
+ }
+
+ /**
+ * @return the name
+ */
+ public String getName() {
+ return name;
+ }
+
+ /**
+ * @param name the name to set
+ */
+ public void setName(String name) {
+ this.name = name;
+ }
+
+ /**
+ * @return the nickname
+ */
+ public String getNickname() {
+ return nickname;
+ }
+
+ /**
+ * @param nickname the nickname to set
+ */
+ public void setNickname(String nickname) {
+ this.nickname = nickname;
+ }
+
+ /**
+ * @return the cool
+ */
+ public Boolean getCool() {
+ return cool;
+ }
+
+ /**
+ * @param cool the cool to set
+ */
+ public void setCool(Boolean cool) {
+ this.cool = cool;
+ }
+
+ /**
+ * @return the age
+ */
+ public int getAge() {
+ return age;
+ }
+
+ /**
+ * @param age the age to set
+ */
+ public void setAge(int age) {
+ this.age = age;
+ }
+
+
+}
Added:
search/trunk/hibernate-search-integrationtest/src/test/java/org/hibernate/search/test/integration/jtaspring/SnertDAO.java
===================================================================
---
search/trunk/hibernate-search-integrationtest/src/test/java/org/hibernate/search/test/integration/jtaspring/SnertDAO.java
(rev 0)
+++
search/trunk/hibernate-search-integrationtest/src/test/java/org/hibernate/search/test/integration/jtaspring/SnertDAO.java 2010-07-20
09:05:09 UTC (rev 19971)
@@ -0,0 +1,28 @@
+package org.hibernate.search.test.integration.jtaspring;
+
+import javax.persistence.EntityManager;
+import javax.persistence.PersistenceContext;
+
+import org.springframework.stereotype.Repository;
+import org.springframework.transaction.annotation.Transactional;
+
+@Repository
+public class SnertDAO {
+ @PersistenceContext
+ private EntityManager entityManager;
+
+ @Transactional
+ public void persist(Snert snert) {
+ entityManager.persist(snert);
+ }
+
+ @Transactional
+ public void merge(Snert snert) {
+ entityManager.merge(snert);
+ }
+
+ @Transactional
+ public void remove(Snert snert) {
+ entityManager.remove(snert);
+ }
+}
Added: search/trunk/hibernate-search-integrationtest/src/test/resources/beans.xml
===================================================================
--- search/trunk/hibernate-search-integrationtest/src/test/resources/beans.xml
(rev 0)
+++ search/trunk/hibernate-search-integrationtest/src/test/resources/beans.xml 2010-07-20
09:05:09 UTC (rev 19971)
@@ -0,0 +1,157 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<beans
xmlns="http://www.springframework.org/schema/beans"
+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+
xmlns:context="http://www.springframework.org/schema/context"
+
xmlns:tx="http://www.springframework.org/schema/tx"
+
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
+
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-2.5.xsd
+
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx-2.5.xsd">
+
+ <bean id="dataSource"
class="bitronix.tm.resource.jdbc.PoolingDataSource" init-method="init"
destroy-method="close">
+ <property name="className" value="org.h2.jdbcx.JdbcDataSource"
/>
+ <property name="uniqueName" value="xaDataSource" />
+ <property name="allowLocalTransactions" value="true"/>
+ <property name="minPoolSize" value="5" />
+ <property name="maxPoolSize" value="100" />
+ <property name="maxIdleTime" value="100" />
+ <property name="testQuery" value="select 1+1 as sum" />
+ <property name="driverProperties">
+ <props>
+ <prop key="URL">jdbc:h2:mem:foobar</prop>
+ <!-- <prop key="user">root</prop>
+ <prop key="password"></prop> -->
+ </props>
+ </property>
+ </bean>
+
+ <!--
+ Process @PersistenceContext to inject entity manager factory
+ -->
+ <bean
class="org.springframework.orm.jpa.support.PersistenceAnnotationBeanPostProcessor"
/>
+
+ <!--
+ process @Transactional to create transaction proxies
+ -->
+ <tx:annotation-driven transaction-manager="transactionManager" />
+
+ <context:component-scan
base-package="org.hibernate.search.test.integration.jtaspring"/>
+
+ <bean id="hibernateJpaVendorAdapter"
class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter">
+ <property name="database" value="H2" />
+ <property name="showSql" value="false" />
+ <property name="generateDdl" value="false" />
+ </bean>
+
+ <bean id="entityManagerFactory"
class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean"
+ depends-on="btmConfig">
+ <property name="loadTimeWeaver">
+ <bean
class="org.springframework.instrument.classloading.InstrumentationLoadTimeWeaver"
/>
+ </property>
+ <property name="persistenceUnitName" value="integration" />
+ <property name="persistenceXmlLocation"
value="classpath:persistence.xml" />
+
+ <property name="dataSource" ref="dataSource" />
+ <property name="jpaVendorAdapter"
ref="hibernateJpaVendorAdapter" />
+
+ <property name="jpaPropertyMap">
+ <map>
+ <entry key="hibernate.dialect"
value="org.hibernate.dialect.H2Dialect" />
+ <entry key="hibernate.hbm2ddl.auto" value="create-drop" />
+ <entry key="hibernate.jdbc.batch_size" value="400" />
+ <entry key="hibernate.jdbc.fetch_size" value="200" />
+ <entry key="hibernate.jdbc.wrap_result_sets" value="true"
/>
+ <entry key="hibernate.generate_statistics" value="true" />
+ <!-- 2 is TRANSACTION_READ_COMMITTED -->
+ <entry key="hibernate.connection.isolation" value="2" />
+ <!--
http://docs.jboss.org/hibernate/core/3.3/reference/en/html/architecture.h...
-->
+ <entry key="hibernate.current_session_context_class"
value="org.hibernate.context.JTASessionContext" />
+
+ <!-- trying things to make Oracle happy -->
+ <entry key="hibernate.jdbc.batch_size" value="0" />
+
+ <!-- second level cache config for all cache providers -->
+ <entry key="hibernate.cache.use_second_level_cache"
value="false" />
+ <entry key="hibernate.cache.use_query_cache" value="false"
/>
+ <entry key="hibernate.cache.region_prefix" value="integration"
/>
+
+ <!-- second level cache - Infinispan -->
+ <!-- <entry key="hibernate.cache.region.factory_class"
value="org.hibernate.cache.infinispan.InfinispanRegionFactory" /> -->
+ <!-- With statistics on transaction would not commit -->
+ <!-- <entry key="hibernate.cache.infinispan.statistics"
value="true"/> -->
+
+ <!-- Atomikos JTA for Hibernate, required to get this JPA provider involved in
JTA -->
+ <!-- no value should be setup for hibernate.transaction.factory_class, it is not
required -->
+ <entry key="hibernate.transaction.manager_lookup_class"
value="org.hibernate.transaction.BTMTransactionManagerLookup"/>
+
+ <!-- Hibernate Search -->
+ <entry key="hibernate.search.default.indexBase" value="."
/>
+ <entry key="hibernate.search.default.directory_provider"
value="org.hibernate.search.store.RAMDirectoryProvider" />
+ <entry key="hibernate.search.worker.execution" value="async"
/>
+ <entry key="hibernate.search.default.optimizer.transaction_limit.max"
value="100" />
+ <entry key="hibernate.search.worker.thread_pool.size"
value="1" />
+ <entry key="hibernate.search.worker.buffer_queue.max"
value="1000000" />
+
+ </map>
+ </property>
+ </bean>
+
+ <!-- From
http://docs.codehaus.org/display/BTM/Spring+Framework13 -->
+ <!-- Bitronix Transaction Manager embedded configuration -->
+ <bean id="btmConfig" factory-method="getConfiguration"
class="bitronix.tm.TransactionManagerServices">
+ <!-- property serverId should not be set when BTMTransactionManagerLookup is
configured as the
+ hibernate transaction manager lookup class -->
+ <!-- <property name="serverId" value="spring-btm" />
-->
+ <property name="journal" value="null"/>
+ </bean>
+
+ <!-- create BTM transaction manager -->
+ <bean id="BitronixTransactionManager"
factory-method="getTransactionManager"
+ class="bitronix.tm.TransactionManagerServices"
depends-on="btmConfig,dataSource" destroy-method="shutdown" />
+
+ <!-- Spring JtaTransactionManager -->
+ <bean id="transactionManager"
class="org.springframework.transaction.jta.JtaTransactionManager">
+ <property name="transactionManager"
ref="BitronixTransactionManager" />
+ <property name="userTransaction"
ref="BitronixTransactionManager" />
+ </bean>
+
+ <!-- Atomikos Transactions -->
+ <!--
http://www.atomikos.com/Documentation/SpringIntegration#The_Advanced_Case...
-->
+
+<!-- <bean id="userTransactionService"
class="com.atomikos.icatch.config.UserTransactionServiceImp"
init-method="init" destroy-method="shutdownForce">
+ <constructor-arg> -->
+ <!-- IMPORTANT: specify all Atomikos properties here (in constructor args) -->
+<!-- <props>
+ <prop
key="com.atomikos.icatch.service">com.atomikos.icatch.standalone.UserTransactionServiceFactory</prop>
+ <prop
key="com.atomikos.icatch.automatic_resource_registration">false</prop>
+ <prop key="com.atomikos.icatch.console_log_level">WARN</prop>
+ <prop
key="com.atomikos.icatch.force_shutdown_on_vm_exit">true</prop>
+ <prop key="com.atomikos.icatch.enable_logging">false</prop>
+ <prop
key="com.atomikos.icatch.serial_jta_transactions">false</prop>
+ </props>
+ </constructor-arg>
+ </bean> -->
+
+ <!-- when close is called, should we force transactions to terminate or not? -->
+<!-- <bean id="atomikosTransactionManager"
class="com.atomikos.icatch.jta.UserTransactionManager"
init-method="init" destroy-method="close"
depends-on="userTransactionService">
+ <property name="forceShutdown" value="false" />
+ </bean> -->
+
+ <!-- Also use Atomikos UserTransactionImp, needed to configure Spring -->
+<!-- <bean id="atomikosUserTransaction"
class="com.atomikos.icatch.jta.UserTransactionImp"
depends-on="userTransactionService">
+ <property name="transactionTimeout" value="300" />
+ </bean> -->
+
+ <!-- Configure the Spring framework to use JTA transactions from Atomikos -->
+<!-- <bean id="transactionManager"
class="org.springframework.transaction.jta.JtaTransactionManager"
depends-on="userTransactionService">
+ <property name="transactionManager"
ref="atomikosTransactionManager" />
+ <property name="userTransaction" ref="atomikosUserTransaction"
/>
+ </bean> -->
+
+ <!-- Spring JPA Transaction Manager, 1PC -->
+ <!-- <bean id="transactionManager"
class="org.springframework.orm.jpa.JpaTransactionManager">
+ <property name="entityManagerFactory" ref="entityManagerFactory"
/>
+ </bean> -->
+
+
+</beans>
+
Added: search/trunk/hibernate-search-integrationtest/src/test/resources/log4j.properties
===================================================================
--- search/trunk/hibernate-search-integrationtest/src/test/resources/log4j.properties
(rev 0)
+++
search/trunk/hibernate-search-integrationtest/src/test/resources/log4j.properties 2010-07-20
09:05:09 UTC (rev 19971)
@@ -0,0 +1,8 @@
+log4j.rootCategory=INFO, CONSOLE
+
+# CONSOLE is set to be a ConsoleAppender using a PatternLayout.
+log4j.appender.CONSOLE=org.apache.log4j.ConsoleAppender
+log4j.appender.CONSOLE.layout=org.apache.log4j.PatternLayout
+log4j.appender.CONSOLE.layout.ConversionPattern=[%d{yyyy-mm-dd
hh:mm:ss.S},%6.6r]%-5p[%t]%x(%F:%L) - %m%n
+
+#log4j.logger.org.hibernate.search=TRACE
\ No newline at end of file
Added: search/trunk/hibernate-search-integrationtest/src/test/resources/persistence.xml
===================================================================
--- search/trunk/hibernate-search-integrationtest/src/test/resources/persistence.xml
(rev 0)
+++
search/trunk/hibernate-search-integrationtest/src/test/resources/persistence.xml 2010-07-20
09:05:09 UTC (rev 19971)
@@ -0,0 +1,10 @@
+<persistence
xmlns="http://java.sun.com/xml/ns/persistence"
version="1.0">
+ <persistence-unit name="integration" transaction-type="JTA">
+ <provider>org.hibernate.ejb.HibernatePersistence</provider>
+ <class>org.hibernate.search.test.integration.jtaspring.Snert</class>
+ <class>org.hibernate.search.test.integration.jtaspring.Container</class>
+ <class>org.hibernate.search.test.integration.jtaspring.Box</class>
+ <class>org.hibernate.search.test.integration.jtaspring.Doughnut</class>
+ <class>org.hibernate.search.test.integration.jtaspring.Muffin</class>
+ </persistence-unit>
+</persistence>
Modified: search/trunk/pom.xml
===================================================================
--- search/trunk/pom.xml 2010-07-20 09:03:29 UTC (rev 19970)
+++ search/trunk/pom.xml 2010-07-20 09:05:09 UTC (rev 19971)
@@ -42,6 +42,7 @@
<module>hibernate-search</module>
<module>hibernate-search-testing</module>
<module>hibernate-search-archetype</module>
+ <module>hibernate-search-integrationtest</module>
</modules>
<issueManagement>