[jboss-cvs] JBossAS SVN: r100152 - in projects/snowdrop/examples/trunk/sportsclub: sportsclub-domain/src/main/java/org/jboss/snowdrop/samples/sportsclub/domain/repository and 9 other directories.
jboss-cvs-commits at lists.jboss.org
jboss-cvs-commits at lists.jboss.org
Fri Jan 29 19:21:41 EST 2010
Author: marius.bogoevici
Date: 2010-01-29 19:21:40 -0500 (Fri, 29 Jan 2010)
New Revision: 100152
Added:
projects/snowdrop/examples/trunk/sportsclub/sportsclub-ear/src/main/application/META-INF/persistence.xml
projects/snowdrop/examples/trunk/sportsclub/sportsclub-jpa-dao/src/main/java/org/jboss/snowdrop/samples/sportsclub/dao/jpa/initializer/
projects/snowdrop/examples/trunk/sportsclub/sportsclub-jpa-dao/src/main/java/org/jboss/snowdrop/samples/sportsclub/dao/jpa/initializer/DatabaseInitializer.java
projects/snowdrop/examples/trunk/sportsclub/sportsclub-jpa-dao/src/main/resources/dao-context.xml
projects/snowdrop/examples/trunk/sportsclub/sportsclub-jpa-dao/src/main/resources/infrastructure.xml
projects/snowdrop/examples/trunk/sportsclub/sportsclub-jpa-dao/src/test/java/org/jboss/snowdrop/samples/sportsclub/dao/jpa/TestJpaPersonDao.java
projects/snowdrop/examples/trunk/sportsclub/sportsclub-jpa-dao/src/test/resources/
projects/snowdrop/examples/trunk/sportsclub/sportsclub-jpa-dao/src/test/resources/TEST-jpa-infrastructure.xml
projects/snowdrop/examples/trunk/sportsclub/sportsclub-jpa-dao/src/test/resources/test-persistence.xml
Modified:
projects/snowdrop/examples/trunk/sportsclub/sportsclub-domain/pom.xml
projects/snowdrop/examples/trunk/sportsclub/sportsclub-domain/src/main/java/org/jboss/snowdrop/samples/sportsclub/domain/repository/Repository.java
projects/snowdrop/examples/trunk/sportsclub/sportsclub-hibernate-dao/src/main/java/org/jboss/snowdrop/samples/sportsclub/dao/hibernate/HibernateMembershipRepository.java
projects/snowdrop/examples/trunk/sportsclub/sportsclub-hibernate-dao/src/main/java/org/jboss/snowdrop/samples/sportsclub/dao/hibernate/HibernateRepository.java
projects/snowdrop/examples/trunk/sportsclub/sportsclub-jpa-dao/pom.xml
projects/snowdrop/examples/trunk/sportsclub/sportsclub-jpa-dao/src/main/java/org/jboss/snowdrop/samples/sportsclub/dao/jpa/JpaPersonRepository.java
projects/snowdrop/examples/trunk/sportsclub/sportsclub-jpa-dao/src/main/java/org/jboss/snowdrop/samples/sportsclub/dao/jpa/JpaRepository.java
Log:
JPA support test infrastructure
Modified: projects/snowdrop/examples/trunk/sportsclub/sportsclub-domain/pom.xml
===================================================================
--- projects/snowdrop/examples/trunk/sportsclub/sportsclub-domain/pom.xml 2010-01-30 00:17:13 UTC (rev 100151)
+++ projects/snowdrop/examples/trunk/sportsclub/sportsclub-domain/pom.xml 2010-01-30 00:21:40 UTC (rev 100152)
@@ -23,4 +23,8 @@
<artifactId>hibernate-annotations</artifactId>
</dependency>
</dependencies>
+
+ <build>
+ <finalName>sportsclub-domain</finalName>
+ </build>
</project>
\ No newline at end of file
Modified: projects/snowdrop/examples/trunk/sportsclub/sportsclub-domain/src/main/java/org/jboss/snowdrop/samples/sportsclub/domain/repository/Repository.java
===================================================================
--- projects/snowdrop/examples/trunk/sportsclub/sportsclub-domain/src/main/java/org/jboss/snowdrop/samples/sportsclub/domain/repository/Repository.java 2010-01-30 00:17:13 UTC (rev 100151)
+++ projects/snowdrop/examples/trunk/sportsclub/sportsclub-domain/src/main/java/org/jboss/snowdrop/samples/sportsclub/domain/repository/Repository.java 2010-01-30 00:21:40 UTC (rev 100152)
@@ -15,5 +15,5 @@
Collection<T> findAll();
- int countAll();
+ long countAll();
}
Added: projects/snowdrop/examples/trunk/sportsclub/sportsclub-ear/src/main/application/META-INF/persistence.xml
===================================================================
--- projects/snowdrop/examples/trunk/sportsclub/sportsclub-ear/src/main/application/META-INF/persistence.xml (rev 0)
+++ projects/snowdrop/examples/trunk/sportsclub/sportsclub-ear/src/main/application/META-INF/persistence.xml 2010-01-30 00:21:40 UTC (rev 100152)
@@ -0,0 +1,10 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<persistence xmlns="http://java.sun.com/xml/ns/persistence" version="1.0">
+ <persistence-unit name="sportsclubPU" transaction-type="JTA">
+ <jta-data-source>java:/SportsClubDS</jta-data-source>
+ <jar-file>lib/sportsclub-domain.jar</jar-file>
+ <properties>
+ <property name="jboss.entity.manager.jndi.name" value="java:/sportsclub/em"/>
+ </properties>
+ </persistence-unit>
+</persistence>
\ No newline at end of file
Modified: projects/snowdrop/examples/trunk/sportsclub/sportsclub-hibernate-dao/src/main/java/org/jboss/snowdrop/samples/sportsclub/dao/hibernate/HibernateMembershipRepository.java
===================================================================
--- projects/snowdrop/examples/trunk/sportsclub/sportsclub-hibernate-dao/src/main/java/org/jboss/snowdrop/samples/sportsclub/dao/hibernate/HibernateMembershipRepository.java 2010-01-30 00:17:13 UTC (rev 100151)
+++ projects/snowdrop/examples/trunk/sportsclub/sportsclub-hibernate-dao/src/main/java/org/jboss/snowdrop/samples/sportsclub/dao/hibernate/HibernateMembershipRepository.java 2010-01-30 00:21:40 UTC (rev 100152)
@@ -25,7 +25,7 @@
return query.list();
}
- public int countAll()
+ public long countAll()
{
return (Integer)getCurrentSession().createCriteria(Membership.class).setProjection(Projections.count("code")).uniqueResult();
}
Modified: projects/snowdrop/examples/trunk/sportsclub/sportsclub-hibernate-dao/src/main/java/org/jboss/snowdrop/samples/sportsclub/dao/hibernate/HibernateRepository.java
===================================================================
--- projects/snowdrop/examples/trunk/sportsclub/sportsclub-hibernate-dao/src/main/java/org/jboss/snowdrop/samples/sportsclub/dao/hibernate/HibernateRepository.java 2010-01-30 00:17:13 UTC (rev 100151)
+++ projects/snowdrop/examples/trunk/sportsclub/sportsclub-hibernate-dao/src/main/java/org/jboss/snowdrop/samples/sportsclub/dao/hibernate/HibernateRepository.java 2010-01-30 00:21:40 UTC (rev 100152)
@@ -56,7 +56,7 @@
}
- public int countAll()
+ public long countAll()
{
return (Integer)getCurrentSession().createCriteria(clazz).setProjection(Projections.count("id")).uniqueResult();
}
Modified: projects/snowdrop/examples/trunk/sportsclub/sportsclub-jpa-dao/pom.xml
===================================================================
--- projects/snowdrop/examples/trunk/sportsclub/sportsclub-jpa-dao/pom.xml 2010-01-30 00:17:13 UTC (rev 100151)
+++ projects/snowdrop/examples/trunk/sportsclub/sportsclub-jpa-dao/pom.xml 2010-01-30 00:21:40 UTC (rev 100152)
@@ -23,6 +23,11 @@
</dependency>
<dependency>
+ <groupId>org.springframework</groupId>
+ <artifactId>spring-test</artifactId>
+ </dependency>
+
+ <dependency>
<groupId>org.jboss.snowdrop.samples.sportsclub</groupId>
<artifactId>sportsclub-domain</artifactId>
</dependency>
@@ -34,6 +39,12 @@
</dependency>
<dependency>
+ <groupId>commons-dbcp</groupId>
+ <artifactId>commons-dbcp</artifactId>
+ <scope>test</scope>
+ </dependency>
+
+ <dependency>
<groupId>hsqldb</groupId>
<artifactId>hsqldb</artifactId>
<scope>test</scope>
@@ -42,9 +53,27 @@
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
- <version>3.8.1</version>
+ </dependency>
+
+ <dependency>
+ <groupId>org.hibernate</groupId>
+ <artifactId>hibernate-core</artifactId>
+ <scope>provided</scope>
+ </dependency>
+
+ <dependency>
+ <groupId>org.hibernate</groupId>
+ <artifactId>hibernate-annotations</artifactId>
+ <scope>provided</scope>
+ </dependency>
+
+ <dependency>
+ <groupId>org.hibernate</groupId>
+ <artifactId>hibernate-entitymanager</artifactId>
+ <version>3.3.2.GA</version>
<scope>test</scope>
</dependency>
+
</dependencies>
</project>
Modified: projects/snowdrop/examples/trunk/sportsclub/sportsclub-jpa-dao/src/main/java/org/jboss/snowdrop/samples/sportsclub/dao/jpa/JpaPersonRepository.java
===================================================================
--- projects/snowdrop/examples/trunk/sportsclub/sportsclub-jpa-dao/src/main/java/org/jboss/snowdrop/samples/sportsclub/dao/jpa/JpaPersonRepository.java 2010-01-30 00:17:13 UTC (rev 100151)
+++ projects/snowdrop/examples/trunk/sportsclub/sportsclub-jpa-dao/src/main/java/org/jboss/snowdrop/samples/sportsclub/dao/jpa/JpaPersonRepository.java 2010-01-30 00:21:40 UTC (rev 100152)
@@ -1,11 +1,14 @@
package org.jboss.snowdrop.samples.sportsclub.dao.jpa;
+import org.springframework.stereotype.Repository;
+
import org.jboss.snowdrop.samples.sportsclub.domain.entity.Person;
import org.jboss.snowdrop.samples.sportsclub.domain.repository.PersonRepository;
/**
* @author <a href="mailto:lvlcek at redhat.com">Lukas Vlcek</a>
*/
+ at Repository
public class JpaPersonRepository extends JpaRepository<Person, Integer> implements PersonRepository
{
public JpaPersonRepository()
Modified: projects/snowdrop/examples/trunk/sportsclub/sportsclub-jpa-dao/src/main/java/org/jboss/snowdrop/samples/sportsclub/dao/jpa/JpaRepository.java
===================================================================
--- projects/snowdrop/examples/trunk/sportsclub/sportsclub-jpa-dao/src/main/java/org/jboss/snowdrop/samples/sportsclub/dao/jpa/JpaRepository.java 2010-01-30 00:17:13 UTC (rev 100151)
+++ projects/snowdrop/examples/trunk/sportsclub/sportsclub-jpa-dao/src/main/java/org/jboss/snowdrop/samples/sportsclub/dao/jpa/JpaRepository.java 2010-01-30 00:21:40 UTC (rev 100152)
@@ -1,13 +1,13 @@
package org.jboss.snowdrop.samples.sportsclub.dao.jpa;
import org.jboss.snowdrop.samples.sportsclub.domain.repository.Repository;
-import org.hibernate.Session;
import javax.persistence.EntityManager;
-import javax.persistence.PersistenceContext;
import java.io.Serializable;
import java.util.Collection;
+import org.springframework.beans.factory.annotation.Autowired;
+
/**
* Abstract repository using JPA EntityManager.
*
@@ -15,7 +15,7 @@
*/
public abstract class JpaRepository<T, I extends Serializable> implements Repository<T, I>
{
- @PersistenceContext
+ @Autowired
protected EntityManager entityManager;
Class<T> clazz;
@@ -42,11 +42,11 @@
public Collection<T> findAll()
{
- return entityManager.createQuery("FROM " + clazz.getSimpleName()).getResultList();
+ return entityManager.createQuery("SELECT c FROM " + clazz.getSimpleName() + " c").getResultList();
}
- public int countAll()
+ public long countAll()
{
- return (Integer)entityManager.createQuery("SELECT COUNT(c) FROM " + clazz.getSimpleName() + " c").getSingleResult();
+ return (Long)entityManager.createQuery("SELECT COUNT(c) FROM " + clazz.getSimpleName() + " c").getSingleResult();
}
}
Copied: projects/snowdrop/examples/trunk/sportsclub/sportsclub-jpa-dao/src/main/java/org/jboss/snowdrop/samples/sportsclub/dao/jpa/initializer/DatabaseInitializer.java (from rev 100143, projects/snowdrop/examples/trunk/sportsclub/sportsclub-hibernate-dao/src/main/java/org/jboss/snowdrop/samples/sportsclub/dao/hibernate/initializer/DatabaseInitializer.java)
===================================================================
--- projects/snowdrop/examples/trunk/sportsclub/sportsclub-jpa-dao/src/main/java/org/jboss/snowdrop/samples/sportsclub/dao/jpa/initializer/DatabaseInitializer.java (rev 0)
+++ projects/snowdrop/examples/trunk/sportsclub/sportsclub-jpa-dao/src/main/java/org/jboss/snowdrop/samples/sportsclub/dao/jpa/initializer/DatabaseInitializer.java 2010-01-30 00:21:40 UTC (rev 100152)
@@ -0,0 +1,212 @@
+package org.jboss.snowdrop.samples.sportsclub.dao.jpa.initializer;
+
+import static org.jboss.snowdrop.samples.sportsclub.domain.entity.EquipmentType.COURT;
+import static org.jboss.snowdrop.samples.sportsclub.domain.entity.EquipmentType.STEPPER;
+import static org.jboss.snowdrop.samples.sportsclub.domain.entity.EquipmentType.TREADMILL;
+
+import javax.persistence.EntityManager;
+import javax.persistence.Query;
+import java.math.BigDecimal;
+import java.util.Calendar;
+import java.util.Date;
+import java.util.HashMap;
+import java.util.Locale;
+import java.util.Map;
+import java.util.Set;
+
+import org.springframework.beans.factory.InitializingBean;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.transaction.PlatformTransactionManager;
+import org.springframework.transaction.TransactionStatus;
+import org.springframework.transaction.support.TransactionCallback;
+import org.springframework.transaction.support.TransactionTemplate;
+
+import org.jboss.snowdrop.samples.sportsclub.domain.entity.Account;
+import org.jboss.snowdrop.samples.sportsclub.domain.entity.Address;
+import org.jboss.snowdrop.samples.sportsclub.domain.entity.BillingType;
+import org.jboss.snowdrop.samples.sportsclub.domain.entity.Equipment;
+import org.jboss.snowdrop.samples.sportsclub.domain.entity.EquipmentType;
+import org.jboss.snowdrop.samples.sportsclub.domain.entity.Membership;
+import org.jboss.snowdrop.samples.sportsclub.domain.entity.Name;
+import org.jboss.snowdrop.samples.sportsclub.domain.entity.Person;
+import org.jboss.snowdrop.samples.sportsclub.domain.entity.Reservation;
+
+/**
+ * @author <a href="mailto:mariusb at redhat.com">Marius Bogoevici</a>
+ */
+public class DatabaseInitializer implements InitializingBean
+{
+
+ @Autowired
+ private EntityManager entityManager;
+
+ @Autowired
+ private PlatformTransactionManager transactionManager;
+
+ public void afterPropertiesSet() throws Exception
+ {
+ new TransactionTemplate(transactionManager).execute(new TransactionCallback()
+ {
+ public Object doInTransaction(TransactionStatus status)
+ {
+
+ Query query = DatabaseInitializer.this.entityManager.createQuery("select count(m) from Membership m");
+
+ if (((Long) query.getSingleResult()) > 0)
+ {
+ return null;
+ }
+
+ Membership silverMembership = createMembership("SILVER", "600.0");
+ Membership goldMembership = createMembership("GOLD", "900.0");
+ Membership platinumMembership = createMembership("PLATINUM", "1200.0");
+
+ save(DatabaseInitializer.this.entityManager, silverMembership);
+ save(DatabaseInitializer.this.entityManager, goldMembership);
+ save(DatabaseInitializer.this.entityManager, platinumMembership);
+
+
+ Map<String, Person> persons = new HashMap<String, Person>();
+
+ persons.put("person1", createPerson("Samuel", "Vimes", "1 Yonge", "Toronto", "Ontario", "Canada"));
+ persons.put("person2", createPerson("Sibyl", "Vimes", "1 Yonge", "Toronto", "Ontario", "Canada"));
+ persons.put("person3", createPerson("Havelock", "Vetinari", "1 Bloor", "Toronto", "Ontario", "Canada"));
+ persons.put("person4", createPerson("Nobby", "Nobbs", "1 Dufferin", "Toronto", "Ontario", "Canada"));
+ persons.put("person5", createPerson("Carrot", "Ironfoundersson", "1 King", "Toronto", "Ontario", "Canada"));
+ persons.put("person6", createPerson("Magrat", "Garlick", "1 King", "Lancre", "Ramtops", "Canada"));
+ persons.put("person7", createPerson("Gytha", "Ogg", "1 King", "Lancre", "Ramtops", "Canada"));
+ persons.put("person8", createPerson("Esmerelda", "Weatherwax", "1 King", "Lancre", "Ramtops", "Canada"));
+ persons.put("person9", createPerson("Mustrum", "Ridcully", "1 King", "Lancre", "Ramtops", "Canada"));
+ persons.put("person10", createPerson("Bill", "Door", "1 King", "Lancre", "Ramtops", "Canada"));
+ persons.put("person11", createPerson("Angua", "von Uberwald", "1 King", "Lancre", "Ramtops", "Canada"));
+ persons.put("person12", createPerson("Claude", "Dibbler", "1 King", "Lancre", "Ramtops", "Canada"));
+
+ saveMap(DatabaseInitializer.this.entityManager, persons);
+
+
+ Map<String, Account> accounts = new HashMap<String, Account>();
+
+ accounts.put("account1", createAccount(silverMembership, BillingType.MONTHLY, persons.get("person1")));
+ accounts.put("account2", createAccount(goldMembership, BillingType.WEEKLY, persons.get("person2")));
+ accounts.put("account3", createAccount(platinumMembership, BillingType.BIWEEKLY, persons.get("person3")));
+ accounts.put("account4", createAccount(goldMembership, BillingType.BIWEEKLY, persons.get("person4")));
+ accounts.put("account5", createAccount(platinumMembership, BillingType.BIWEEKLY, persons.get("person5")));
+ accounts.put("account6", createAccount(platinumMembership, BillingType.BIWEEKLY, persons.get("person6")));
+ accounts.put("account7", createAccount(platinumMembership, BillingType.BIWEEKLY, persons.get("person7")));
+ accounts.put("account8", createAccount(platinumMembership, BillingType.MONTHLY, persons.get("person8")));
+ accounts.put("account9", createAccount(platinumMembership, BillingType.BIWEEKLY, persons.get("person9")));
+ accounts.put("account10", createAccount(platinumMembership, BillingType.BIWEEKLY, persons.get("person10")));
+ accounts.put("account11", createAccount(platinumMembership, BillingType.BIWEEKLY, persons.get("person11")));
+ accounts.put("account12", createAccount(platinumMembership, BillingType.BIWEEKLY, persons.get("person12")));
+
+ saveMap(DatabaseInitializer.this.entityManager, accounts);
+
+
+ Map<String, Equipment> equipments = new HashMap<String, Equipment>();
+
+ equipments.put("equipment1", createEquipment("Engage", "95T Engage by LifeFitness", TREADMILL));
+ equipments.put("equipment2", createEquipment("Inclusive", "95T Inclusive by LifeFitness", TREADMILL));
+ equipments.put("equipment3", createEquipment("Omnidirectional", "by Cyberwalk", TREADMILL));
+ equipments.put("equipment4", createEquipment("Squash", "by Court Company", COURT));
+ equipments.put("equipment5", createEquipment("FreeMotion", "FreeMotion s5.6 by NordicTrack", STEPPER));
+ equipments.put("equipment6", createEquipment("MTN", "MTN 740 by NordicTrack", STEPPER));
+
+ saveMap(DatabaseInitializer.this.entityManager, equipments);
+
+
+ Map<String, Reservation> reservations = new HashMap<String, Reservation>();
+
+ reservations.put("reservation1", createReservation(createDate(2009, 02, 01), createDate(2009, 10, 31), equipments.get("equipment1"), accounts.get("account1")));
+ reservations.put("reservation2", createReservation(createDate(2009, 01, 01), createDate(2009, 12, 31), equipments.get("equipment2"), accounts.get("account2")));
+ reservations.put("reservation3", createReservation(createDate(2009, 05, 01), createDate(2009, 10, 31), equipments.get("equipment3"), accounts.get("account3")));
+ reservations.put("reservation4", createReservation(createDate(2009, 07, 01), createDate(2009, 07, 02), equipments.get("equipment4"), accounts.get("account4")));
+ reservations.put("reservation5", createReservation(createDate(2009, 07, 01), createDate(2009, 07, 02), equipments.get("equipment5"), accounts.get("account5")));
+ reservations.put("reservation6", createReservation(createDate(2009, 07, 01), createDate(2009, 07, 02), equipments.get("equipment6"), accounts.get("account6")));
+
+ saveMap(DatabaseInitializer.this.entityManager, reservations);
+
+ return null;
+ }
+ });
+ }
+
+ private static void saveMap(EntityManager entityManager, Map data)
+ {
+ for (String key : (Set<String>)data.keySet())
+ {
+ save(entityManager, data.get(key));
+ }
+ }
+
+ private static void save(EntityManager entityManager, Object entity)
+ {
+ entityManager.persist(entity);
+ //entityManager.flush();
+ }
+
+ private static Account createAccount(Membership silverMembership, BillingType billingType, Person person)
+ {
+ Account account = new Account();
+ account.setSubscriber(person);
+ account.setCreationDate(new Date());
+ account.setBillingType(billingType);
+ account.setMembership(silverMembership);
+ account.setClosed(false);
+ return account;
+ }
+
+ private static Person createPerson(String firstname, String lastname, String street, String city, String province, String country)
+ {
+ Person person = new Person();
+ person.setName(new Name());
+ person.setAddress(new Address());
+
+ person.getName().setFirstName(firstname);
+ person.getName().setLastName(lastname);
+ person.getAddress().setStreetAddress(street);
+ person.getAddress().setCity(city);
+ person.getAddress().setProvinceOrState(province);
+ person.getAddress().setCountry(country);
+ person.getAddress().setPostalCode("H0H0H0");
+ return person;
+ }
+
+ private static Membership createMembership(String code, String amount)
+ {
+ Membership membership = new Membership(code);
+ membership.setActive(true);
+ membership.setAnnualFee(new BigDecimal(amount));
+ return membership;
+ }
+
+ private static Equipment createEquipment(String name, String description, EquipmentType type)
+ {
+ Equipment equipment = new Equipment();
+ equipment.setDescription(description);
+ equipment.setName(name);
+ equipment.setEquipmentType(type);
+ return equipment;
+ }
+
+ private static Reservation createReservation(Date fromDate, Date toDate, Equipment equipment, Account account)
+ {
+ assert fromDate.before(toDate);
+ Reservation reservation = new Reservation();
+ reservation.setAccount(account);
+ reservation.setEquipment(equipment);
+ reservation.setFrom(fromDate);
+ reservation.setTo(toDate);
+ return reservation;
+ }
+
+ /**
+ * Months are human readable and start at 1!
+ */
+ private static Date createDate(int year, int month, int day)
+ {
+ Calendar cal = Calendar.getInstance(Locale.US);
+ cal.clear();
+ cal.set(year, month - 1, day);
+ return cal.getTime();
+ }
+}
\ No newline at end of file
Added: projects/snowdrop/examples/trunk/sportsclub/sportsclub-jpa-dao/src/main/resources/dao-context.xml
===================================================================
--- projects/snowdrop/examples/trunk/sportsclub/sportsclub-jpa-dao/src/main/resources/dao-context.xml (rev 0)
+++ projects/snowdrop/examples/trunk/sportsclub/sportsclub-jpa-dao/src/main/resources/dao-context.xml 2010-01-30 00:21:40 UTC (rev 100152)
@@ -0,0 +1,14 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<beans xmlns="http://www.springframework.org/schema/beans"
+ xmlns:context="http://www.springframework.org/schema/context"
+ 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.xsd
+ http://www.springframework.org/schema/context
+ http://www.springframework.org/schema/context/spring-context.xsd">
+
+ <context:component-scan base-package="org.jboss.snowdrop.samples.sportsclub.dao.jpa"/>
+
+ <bean id="databaseInitializer" class="org.jboss.snowdrop.samples.sportsclub.dao.jpa.initializer.DatabaseInitializer"/>
+</beans>
\ No newline at end of file
Added: projects/snowdrop/examples/trunk/sportsclub/sportsclub-jpa-dao/src/main/resources/infrastructure.xml
===================================================================
--- projects/snowdrop/examples/trunk/sportsclub/sportsclub-jpa-dao/src/main/resources/infrastructure.xml (rev 0)
+++ projects/snowdrop/examples/trunk/sportsclub/sportsclub-jpa-dao/src/main/resources/infrastructure.xml 2010-01-30 00:21:40 UTC (rev 100152)
@@ -0,0 +1,20 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<beans xmlns="http://www.springframework.org/schema/beans"
+ xmlns:jee="http://www.springframework.org/schema/jee"
+ xmlns:tx="http://www.springframework.org/schema/tx"
+ xmlns:util="http://www.springframework.org/schema/util"
+ 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.xsd
+ http://www.springframework.org/schema/jee
+ http://www.springframework.org/schema/jee/spring-jee.xsd
+ http://www.springframework.org/schema/util
+ http://www.springframework.org/schema/util/spring-util.xsd
+ http://www.springframework.org/schema/tx
+ http://www.springframework.org/schema/tx/spring-tx.xsd">
+
+ <jee:jndi-lookup jndi-name="java:/sportsclub/em"/>
+
+ <tx:jta-transaction-manager/>
+
+</beans>
\ No newline at end of file
Added: projects/snowdrop/examples/trunk/sportsclub/sportsclub-jpa-dao/src/test/java/org/jboss/snowdrop/samples/sportsclub/dao/jpa/TestJpaPersonDao.java
===================================================================
--- projects/snowdrop/examples/trunk/sportsclub/sportsclub-jpa-dao/src/test/java/org/jboss/snowdrop/samples/sportsclub/dao/jpa/TestJpaPersonDao.java (rev 0)
+++ projects/snowdrop/examples/trunk/sportsclub/sportsclub-jpa-dao/src/test/java/org/jboss/snowdrop/samples/sportsclub/dao/jpa/TestJpaPersonDao.java 2010-01-30 00:21:40 UTC (rev 100152)
@@ -0,0 +1,32 @@
+package org.jboss.snowdrop.samples.sportsclub.dao.jpa;
+
+import javax.persistence.EntityManager;
+
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.test.context.ContextConfiguration;
+import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
+
+import org.jboss.snowdrop.samples.sportsclub.domain.repository.PersonRepository;
+import org.junit.Assert;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+
+/**
+ * @author Marius Bogoevici
+ */
+ at ContextConfiguration(locations = {"classpath:test-infrastructure.xml",
+ "classpath:TEST-jpa-infrastructure.xml",
+ "classpath:dao-context.xml"})
+ at RunWith(SpringJUnit4ClassRunner.class)
+public class TestJpaPersonDao
+{
+ @Autowired
+ PersonRepository personRepository;
+
+ @Test
+ public void testPersonRepository()
+ {
+ long count = personRepository.countAll();
+ Assert.assertEquals(12, count);
+ }
+}
Added: projects/snowdrop/examples/trunk/sportsclub/sportsclub-jpa-dao/src/test/resources/TEST-jpa-infrastructure.xml
===================================================================
--- projects/snowdrop/examples/trunk/sportsclub/sportsclub-jpa-dao/src/test/resources/TEST-jpa-infrastructure.xml (rev 0)
+++ projects/snowdrop/examples/trunk/sportsclub/sportsclub-jpa-dao/src/test/resources/TEST-jpa-infrastructure.xml 2010-01-30 00:21:40 UTC (rev 100152)
@@ -0,0 +1,38 @@
+<beans xmlns="http://www.springframework.org/schema/beans"
+ xmlns:jee="http://www.springframework.org/schema/jee"
+ xmlns:tx="http://www.springframework.org/schema/tx"
+ xmlns:util="http://www.springframework.org/schema/util"
+ 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.xsd
+ http://www.springframework.org/schema/jee
+ http://www.springframework.org/schema/jee/spring-jee.xsd
+ http://www.springframework.org/schema/util
+ http://www.springframework.org/schema/util/spring-util.xsd
+ http://www.springframework.org/schema/tx
+ http://www.springframework.org/schema/tx/spring-tx.xsd">
+
+
+ <bean id="entityManagerFactory" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
+ <property name="jpaDialect">
+ <bean class="org.springframework.orm.jpa.vendor.HibernateJpaDialect"/>
+ </property>
+ <property name="jpaVendorAdapter">
+ <bean class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter">
+ <property name="database" value="HSQL"/>
+ <property name="generateDdl" value="true"/>
+ </bean>
+ </property>
+ <property name="persistenceXmlLocation" value="test-persistence.xml"/>
+ <property name="dataSource" ref="stayFitDS"/>
+ </bean>
+
+ <bean id="entityManagerWrapper" class="org.springframework.orm.jpa.support.SharedEntityManagerBean">
+ <property name="entityManagerFactory" ref="entityManagerFactory"/>
+ </bean>
+
+ <bean id="transactionManager" class="org.springframework.orm.jpa.JpaTransactionManager">
+ <property name="entityManagerFactory" ref="entityManagerFactory"/>
+ </bean>
+
+</beans>
\ No newline at end of file
Added: projects/snowdrop/examples/trunk/sportsclub/sportsclub-jpa-dao/src/test/resources/test-persistence.xml
===================================================================
--- projects/snowdrop/examples/trunk/sportsclub/sportsclub-jpa-dao/src/test/resources/test-persistence.xml (rev 0)
+++ projects/snowdrop/examples/trunk/sportsclub/sportsclub-jpa-dao/src/test/resources/test-persistence.xml 2010-01-30 00:21:40 UTC (rev 100152)
@@ -0,0 +1,13 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<persistence xmlns="http://java.sun.com/xml/ns/persistence" version="1.0">
+ <persistence-unit name="sportsclubPU" transaction-type="RESOURCE_LOCAL">
+ <class>org.jboss.snowdrop.samples.sportsclub.domain.entity.Account</class>
+ <class>org.jboss.snowdrop.samples.sportsclub.domain.entity.Equipment</class>
+ <class>org.jboss.snowdrop.samples.sportsclub.domain.entity.Invoice</class>
+ <class>org.jboss.snowdrop.samples.sportsclub.domain.entity.Balance</class>
+ <class>org.jboss.snowdrop.samples.sportsclub.domain.entity.Payment</class>
+ <class>org.jboss.snowdrop.samples.sportsclub.domain.entity.Membership</class>
+ <class>org.jboss.snowdrop.samples.sportsclub.domain.entity.Person</class>
+ <class>org.jboss.snowdrop.samples.sportsclub.domain.entity.Reservation</class>
+ </persistence-unit>
+</persistence>
\ No newline at end of file
More information about the jboss-cvs-commits
mailing list