diff --git a/jpa/eclipselink/README.md b/jpa/eclipselink/README.md new file mode 100644 index 00000000..65719c40 --- /dev/null +++ b/jpa/eclipselink/README.md @@ -0,0 +1,7 @@ +# Spring Data JPA - Eclipselink + Static Weaving Example + +This project contains an example of using Eclipselink with static weaving with Spring Data. Static weaving is +accomplished with a maven plugin that requires a persistence.xml, so a persistence.xml exists in this project. +The persistence.xml is not actually used by the Spring Boot example and is only used at build time for the maven +plugin. To use the persistence.xml file, please see instructions on how to [use a traditional persistence.xm](http://docs.spring.io/spring-boot/docs/current/reference/html/howto-data-access.html#howto-use-traditional-persistence-xml). + diff --git a/jpa/eclipselink/pom.xml b/jpa/eclipselink/pom.xml new file mode 100644 index 00000000..8c8c935a --- /dev/null +++ b/jpa/eclipselink/pom.xml @@ -0,0 +1,81 @@ + + + + + org.springframework.data.examples + spring-data-jpa-examples + 1.0.0.BUILD-SNAPSHOT + + + + + com.ethlo.eclipselink.tools + http://ethlo.com/maven + + + + + + com.ethlo.eclipselink.tools + http://ethlo.com/maven + + + + 4.0.0 + + example.springdata.jpa + eclipselink + 0.0.1-SNAPSHOT + jar + + Spring Data JPA - Spring Data JPA w/ Eclipse Link and Static Weaving + Example Spring Data JPA Project using EclipseLink and Static Weaving + + + UTF-8 + example.springdata.jpa.eclipselink.SpringDataJpaEclipseLinkApplication + 1.8 + 2.6.0 + + + + + org.eclipse.persistence + org.eclipse.persistence.jpa + ${eclipselink.version} + + + + + + + org.springframework.boot + spring-boot-maven-plugin + + + + com.ethlo.persistence.tools + eclipselink-maven-plugin + 1.1-SNAPSHOT + + + process-classes + + weave + + + + + + + org.eclipse.persistence + org.eclipse.persistence.jpa + ${eclipselink.version} + + + + + + + diff --git a/jpa/eclipselink/src/main/java/example/springdata/jpa/eclipselink/SpringDataJpaEclipseLinkApplication.java b/jpa/eclipselink/src/main/java/example/springdata/jpa/eclipselink/SpringDataJpaEclipseLinkApplication.java new file mode 100644 index 00000000..3eb8b6f9 --- /dev/null +++ b/jpa/eclipselink/src/main/java/example/springdata/jpa/eclipselink/SpringDataJpaEclipseLinkApplication.java @@ -0,0 +1,94 @@ +/* + * Copyright 2015 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package example.springdata.jpa.eclipselink; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +import org.springframework.data.jpa.repository.config.EnableJpaRepositories; +import org.springframework.jdbc.datasource.embedded.EmbeddedDatabaseBuilder; +import org.springframework.jdbc.datasource.embedded.EmbeddedDatabaseType; +import org.springframework.orm.jpa.JpaVendorAdapter; +import org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean; +import org.springframework.orm.jpa.vendor.Database; +import org.springframework.orm.jpa.vendor.EclipseLinkJpaDialect; +import org.springframework.orm.jpa.vendor.EclipseLinkJpaVendorAdapter; + +import javax.sql.DataSource; +import java.util.HashMap; +import java.util.Map; + +/** + * Spring Boot application with Spring Java Config annotations that use EclipseLink as the JPA Provider + * and turn on Static Weaving of the entity classes by disabling dynamic weaving and utilizing a maven + * build that includes a static weaving plugin. + * + * @author Jeremy Rickard + */ + +@SpringBootApplication +@Configuration +@EnableJpaRepositories("example.springdata.jpa.eclipselink.repositories") +public class SpringDataJpaEclipseLinkApplication { + + @Bean + public DataSource dataSource() { + return new EmbeddedDatabaseBuilder().setType(EmbeddedDatabaseType.HSQL).build(); + } + + + @Bean + public LocalContainerEntityManagerFactoryBean entityManagerFactory() { + LocalContainerEntityManagerFactoryBean lemfb = new LocalContainerEntityManagerFactoryBean(); + lemfb.setDataSource(dataSource()); + lemfb.setJpaVendorAdapter(jpaVendorAdapter()); + lemfb.setJpaDialect(eclipseLinkJpaDialect()); + lemfb.setJpaPropertyMap(jpaProperties()); + lemfb.setPackagesToScan("example.springdata.jpa.eclipselink.domain"); + return lemfb; + } + + @Bean + public EclipseLinkJpaDialect eclipseLinkJpaDialect() { + return new EclipseLinkJpaDialect(); + } + + /* + * Set this property to disable LoadTimeWeaver (i.e. Dynamic Weaving) for EclipseLink. + * Otherwise, you'll get: Cannot apply class transformer without LoadTimeWeaver specified + */ + @Bean + public Map jpaProperties() { + Map props = new HashMap<>(); + props.put("eclipselink.weaving", "false"); + return props; + } + + @Bean + public JpaVendorAdapter jpaVendorAdapter() { + EclipseLinkJpaVendorAdapter jpaVendorAdapter = new EclipseLinkJpaVendorAdapter(); + jpaVendorAdapter.setDatabase(Database.HSQL); + jpaVendorAdapter.setGenerateDdl(true); + return jpaVendorAdapter; + } + + + public static void main(String[] args) { + SpringApplication.run(SpringDataJpaEclipseLinkApplication.class, args); + } +} diff --git a/jpa/eclipselink/src/main/java/example/springdata/jpa/eclipselink/domain/Gender.java b/jpa/eclipselink/src/main/java/example/springdata/jpa/eclipselink/domain/Gender.java new file mode 100644 index 00000000..7e298edf --- /dev/null +++ b/jpa/eclipselink/src/main/java/example/springdata/jpa/eclipselink/domain/Gender.java @@ -0,0 +1,27 @@ +package example.springdata.jpa.eclipselink.domain; + +/* + * Copyright 2015 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + + +/** + * @author Jeremy Rickard + */ + +public enum Gender { + FEMALE, + MALE +} diff --git a/jpa/eclipselink/src/main/java/example/springdata/jpa/eclipselink/domain/Participant.java b/jpa/eclipselink/src/main/java/example/springdata/jpa/eclipselink/domain/Participant.java new file mode 100644 index 00000000..cfcd85bf --- /dev/null +++ b/jpa/eclipselink/src/main/java/example/springdata/jpa/eclipselink/domain/Participant.java @@ -0,0 +1,136 @@ +/* + * Copyright 2015 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package example.springdata.jpa.eclipselink.domain; + +/** + * Entity showing use of {@link org.eclipse.persistence.annotations.UuidGenerator} from + * the EclipseLink JPA Provider. Does not extend the AbstractPersistable because of the UUID generator + * + * @author Jeremy Rickard + */ + +import org.eclipse.persistence.annotations.UuidGenerator; + +import javax.persistence.*; +import java.util.List; + +@Entity +public class Participant { + @Id + @UuidGenerator(name = "UUID") + @GeneratedValue(generator = "UUID") + private String uuid; + + private String firstName; + + private String lastName; + + private String emailAddress; + + private String phoneNumber; + + private int age; + + @Enumerated + private Gender gender; + + @ManyToMany(mappedBy = "registrations") + private List raceRegistrations; + + public String getUuid() { + return uuid; + } + + public void setUuid(String uuid) { + this.uuid = uuid; + } + + public String getFirstName() { + return firstName; + } + + public void setFirstName(String firstName) { + this.firstName = firstName; + } + + public String getLastName() { + return lastName; + } + + public void setLastName(String lastName) { + this.lastName = lastName; + } + + public String getEmailAddress() { + return emailAddress; + } + + public void setEmailAddress(String emailAddress) { + this.emailAddress = emailAddress; + } + + public String getPhoneNumber() { + return phoneNumber; + } + + public void setPhoneNumber(String phoneNumber) { + this.phoneNumber = phoneNumber; + } + + public int getAge() { + return age; + } + + public void setAge(int age) { + this.age = age; + } + + public Gender getGender() { + return gender; + } + + public void setGender(Gender gender) { + this.gender = gender; + } + + public List getRaceRegistrations() { + return raceRegistrations; + } + + public void setRaceRegistrations(List raceRegistrations) { + this.raceRegistrations = raceRegistrations; + } + + public boolean equals(Object obj) { + if (null == obj) { + return false; + } else if (this == obj) { + return true; + } else if (!this.getClass().equals(obj.getClass())) { + return false; + } else { + Participant that = (Participant) obj; + return null == this.getUuid() ? false : this.getUuid().equals(that.getUuid()); + } + } + + public int hashCode() { + byte hashCode = 17; + int hashCode1 = hashCode + (null == this.getUuid() ? 0 : this.getUuid().hashCode() * 31); + return hashCode1; + } +} diff --git a/jpa/eclipselink/src/main/java/example/springdata/jpa/eclipselink/domain/Race.java b/jpa/eclipselink/src/main/java/example/springdata/jpa/eclipselink/domain/Race.java new file mode 100644 index 00000000..ddc2c845 --- /dev/null +++ b/jpa/eclipselink/src/main/java/example/springdata/jpa/eclipselink/domain/Race.java @@ -0,0 +1,124 @@ +/* + * Copyright 2015 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package example.springdata.jpa.eclipselink.domain; + + +/** + * Entity showing use of {@link org.eclipse.persistence.annotations.UuidGenerator} from + * the EclipseLink JPA Provider. Does not extend the AbstractPersistable because of the UUID generator + * + * @author Jeremy Rickard + */ + +import org.eclipse.persistence.annotations.UuidGenerator; + +import javax.persistence.*; +import java.util.Date; +import java.util.List; + +@Entity +public class Race { + @Id + @UuidGenerator(name = "UUID") + @GeneratedValue(generator = "UUID") + private String uuid; + + private double distance; + + @Column(nullable = false) + @Temporal(TemporalType.DATE) + private Date date; + + @Column(nullable = false) + private String name; + + @Column(nullable = false, length = 5000) + private String description; + + @ManyToMany + @JoinTable(name = "RACE_REG", + joinColumns = {@JoinColumn(name = "RACE_ID", referencedColumnName = "uuid")}, + inverseJoinColumns = {@JoinColumn(name = "PART_ID", referencedColumnName = "uuid", unique = true)}) + private List registrations; + + public String getUuid() { + return uuid; + } + + public void setUuid(String uuid) { + this.uuid = uuid; + } + + public double getDistance() { + return distance; + } + + public void setDistance(double distance) { + this.distance = distance; + } + + public Date getDate() { + return date; + } + + public void setDate(Date date) { + this.date = date; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public String getDescription() { + return description; + } + + public void setDescription(String description) { + this.description = description; + } + + public List getRegistrations() { + return registrations; + } + + public void setRegistrations(List registrations) { + this.registrations = registrations; + } + + public boolean equals(Object obj) { + if (null == obj) { + return false; + } else if (this == obj) { + return true; + } else if (!this.getClass().equals(obj.getClass())) { + return false; + } else { + Race that = (Race) obj; + return null == this.getUuid() ? false : this.getUuid().equals(that.getUuid()); + } + } + + public int hashCode() { + byte hashCode = 17; + int hashCode1 = hashCode + (null == this.getUuid() ? 0 : this.getUuid().hashCode() * 31); + return hashCode1; + } +} diff --git a/jpa/eclipselink/src/main/java/example/springdata/jpa/eclipselink/repositories/ParticipantRepository.java b/jpa/eclipselink/src/main/java/example/springdata/jpa/eclipselink/repositories/ParticipantRepository.java new file mode 100644 index 00000000..e176e730 --- /dev/null +++ b/jpa/eclipselink/src/main/java/example/springdata/jpa/eclipselink/repositories/ParticipantRepository.java @@ -0,0 +1,40 @@ +/* + * Copyright 2015 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package example.springdata.jpa.eclipselink.repositories; + + +import example.springdata.jpa.eclipselink.domain.Participant; +import org.springframework.data.jpa.repository.Query; +import org.springframework.data.repository.CrudRepository; + +import java.util.List; + +/** + * Repository to manage {@link example.springdata.jpa.eclipselink.domain.Participant} instances. + * + * @author Jeremy Rickard + */ +public interface ParticipantRepository extends CrudRepository { + + @Query("SELECT p from Participant p") + List findAll(); + + List findByLastName(String lastName); + + List findByAgeLessThan(int age); + + List findByAgeBetween(int age1, int age2); +} diff --git a/jpa/eclipselink/src/main/java/example/springdata/jpa/eclipselink/repositories/RaceRepository.java b/jpa/eclipselink/src/main/java/example/springdata/jpa/eclipselink/repositories/RaceRepository.java new file mode 100644 index 00000000..f8e3f7e4 --- /dev/null +++ b/jpa/eclipselink/src/main/java/example/springdata/jpa/eclipselink/repositories/RaceRepository.java @@ -0,0 +1,40 @@ +/* + * Copyright 2015 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package example.springdata.jpa.eclipselink.repositories; + + +/** + * Repository to manage {@link example.springdata.jpa.eclipselink.domain.Race} instances. + * + * @author Jeremy Rickard + */ + +import example.springdata.jpa.eclipselink.domain.Race; +import org.springframework.data.repository.CrudRepository; + +import java.util.Date; +import java.util.List; + +public interface RaceRepository extends CrudRepository { + + List findByName(String name); + + List findByDate(Date date); + + List findByDateBefore(Date date); + + List findByDistanceBetween(double start, double end); +} diff --git a/jpa/eclipselink/src/main/resources/application.properties b/jpa/eclipselink/src/main/resources/application.properties new file mode 100644 index 00000000..e69de29b diff --git a/jpa/eclipselink/src/test/java/example/springdata/jpa/eclipselink/SpringDataJpaEclipseLinkApplicationTests.java b/jpa/eclipselink/src/test/java/example/springdata/jpa/eclipselink/SpringDataJpaEclipseLinkApplicationTests.java new file mode 100644 index 00000000..0675fc84 --- /dev/null +++ b/jpa/eclipselink/src/test/java/example/springdata/jpa/eclipselink/SpringDataJpaEclipseLinkApplicationTests.java @@ -0,0 +1,264 @@ +package example.springdata.jpa.eclipselink; + +import example.springdata.jpa.eclipselink.domain.Gender; +import example.springdata.jpa.eclipselink.domain.Participant; +import example.springdata.jpa.eclipselink.domain.Race; +import example.springdata.jpa.eclipselink.repositories.ParticipantRepository; +import example.springdata.jpa.eclipselink.repositories.RaceRepository; +import org.junit.After; +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.SpringApplicationConfiguration; +import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; + +import java.text.SimpleDateFormat; +import java.util.Date; +import java.util.List; + +import static org.hamcrest.Matchers.is; +import static org.junit.Assert.*; + +/** + * Test for Spring Data JPA EclipseLink w/ Static Weaving example + * + * @author Jeremy Rickard + */ +@RunWith(SpringJUnit4ClassRunner.class) +@SpringApplicationConfiguration(classes = SpringDataJpaEclipseLinkApplication.class) +public class SpringDataJpaEclipseLinkApplicationTests { + + @Autowired + RaceRepository raceRepository; + + @Autowired + ParticipantRepository participantRepository; + + Race pikesPeakAscent; + + Race pikesPeakMarathon; + + Race summerRoundUp; + + Race gardenOfTheGods10Mile; + + Participant one; + + Participant two; + + Participant three; + + Date ascentStartDate; + + SimpleDateFormat sdf; + + double ascentDistanceInKM = 21.4364621; + + @Before + public void setUp() throws Exception { + + sdf = new SimpleDateFormat("MM/dd/yyyy HH:MM z"); + + + ascentStartDate = sdf.parse("08/15/2015 07:00 MDT"); + + pikesPeakAscent = new Race(); + pikesPeakAscent.setName("Pikes Peak Ascent"); + pikesPeakAscent.setDistance(ascentDistanceInKM); + pikesPeakAscent.setDate(ascentStartDate); + pikesPeakAscent.setDescription("Started in 1956 as a challenge between smokers and non-smokers, " + + "the Pikes Peak Marathon is #3 on the list of longest running US marathons behind Boston and Yonkers."); + + pikesPeakMarathon = new Race(); + pikesPeakMarathon.setName("Pikes Peak Marathon"); + pikesPeakMarathon.setDistance(ascentDistanceInKM * 2); + pikesPeakMarathon.setDate(ascentStartDate); + pikesPeakMarathon.setDescription("Started in 1956 as a challenge between smokers and non-smokers, " + + "the Pikes Peak Marathon is #3 on the list of longest running US marathons behind Boston and Yonkers."); + + + summerRoundUp = new Race(); + summerRoundUp.setName("Summer Round Up"); + summerRoundUp.setDescription("2nd Leg of the Triple Crown of Running"); + summerRoundUp.setDate(sdf.parse("07/12/2015 07:00 MDT")); + summerRoundUp.setDistance(12.0); + + gardenOfTheGods10Mile = new Race(); + gardenOfTheGods10Mile.setName("Garden of the Gods 10 Miler"); + gardenOfTheGods10Mile.setDescription("1st Leg of the Triple Crown of Running"); + gardenOfTheGods10Mile.setDate(sdf.parse("06/15/2015 07:00 MDT")); + gardenOfTheGods10Mile.setDistance(16.0934); + + + one = new Participant(); + one.setAge(25); + one.setEmailAddress("john.doe@gmail.com"); + one.setFirstName("John"); + one.setLastName("Doe"); + one.setPhoneNumber("1-123-234-5679"); + one.setGender(Gender.MALE); + + two = new Participant(); + two.setAge(21); + two.setEmailAddress("jane.doe@gmail.com"); + two.setFirstName("Jane"); + two.setLastName("Doe"); + two.setPhoneNumber("1-123-234-5678"); + two.setGender(Gender.FEMALE); + + three = new Participant(); + three.setAge(62); + three.setEmailAddress("sam.smith@gmail.com"); + three.setFirstName("Samantha"); + three.setLastName("Smith"); + three.setPhoneNumber("1-234-911-5678"); + three.setGender(Gender.FEMALE); + + + } + + + @Test + public void contextLoads() { + } + + @Test + public void testInsertRace() { + + pikesPeakAscent = raceRepository.save(pikesPeakAscent); + pikesPeakMarathon = raceRepository.save(pikesPeakMarathon); + summerRoundUp = raceRepository.save(summerRoundUp); + gardenOfTheGods10Mile = raceRepository.save(gardenOfTheGods10Mile); + + assertNotNull(pikesPeakAscent.getUuid()); + assertNotNull(pikesPeakMarathon.getUuid()); + assertNotNull(summerRoundUp.getUuid()); + assertNotNull(gardenOfTheGods10Mile.getUuid()); + + assertNotEquals(pikesPeakAscent.getUuid(), pikesPeakMarathon.getUuid()); + } + + @Test + public void testFindRacesByDates() { + pikesPeakAscent = raceRepository.save(pikesPeakAscent); + pikesPeakMarathon = raceRepository.save(pikesPeakMarathon); + summerRoundUp = raceRepository.save(summerRoundUp); + gardenOfTheGods10Mile = raceRepository.save(gardenOfTheGods10Mile); + + List races = raceRepository.findByDate(ascentStartDate); + assertThat(races.contains(pikesPeakAscent), is(true)); + assertThat(races.contains(pikesPeakMarathon), is(true)); + + races = raceRepository.findByDateBefore(ascentStartDate); + assertThat(races.contains(pikesPeakAscent), is(false)); + assertThat(races.contains(pikesPeakMarathon), is(false)); + } + + @Test + public void testFindRacesByDistance() { + pikesPeakAscent = raceRepository.save(pikesPeakAscent); + pikesPeakMarathon = raceRepository.save(pikesPeakMarathon); + summerRoundUp = raceRepository.save(summerRoundUp); + gardenOfTheGods10Mile = raceRepository.save(gardenOfTheGods10Mile); + + List races = raceRepository.findByDistanceBetween(20, 100); + assertThat(races.contains(pikesPeakAscent), is(true)); + assertThat(races.contains(pikesPeakMarathon), is(true)); + + races = raceRepository.findByDistanceBetween(10, 19); + assertThat(races.contains(pikesPeakAscent), is(false)); + assertThat(races.contains(pikesPeakMarathon), is(false)); + } + + + @Test + public void testRaceByName() { + pikesPeakAscent = raceRepository.save(pikesPeakAscent); + pikesPeakMarathon = raceRepository.save(pikesPeakMarathon); + summerRoundUp = raceRepository.save(summerRoundUp); + gardenOfTheGods10Mile = raceRepository.save(gardenOfTheGods10Mile); + + List races = raceRepository.findByName("Summer Round Up"); + assertThat(races.contains(pikesPeakAscent), is(false)); + assertThat(races.contains(pikesPeakMarathon), is(false)); + assertThat(races.contains(summerRoundUp), is(true)); + } + + + @Test + public void testInsertParticipant() { + + one = participantRepository.save(one); + two = participantRepository.save(two); + three = participantRepository.save(three); + + assertNotNull(one.getUuid()); + assertNotNull(two.getUuid()); + assertNotNull(three.getUuid()); + + assertNotEquals(one.getUuid(), two.getUuid()); + assertNotEquals(two.getUuid(), three.getUuid()); + + assertThat(participantRepository.findAll().size(), is(3)); + + List twentySomethings = participantRepository.findByAgeLessThan(40); + + for (Participant participant : twentySomethings) { + System.err.println(participant.getUuid()); + } + + System.err.println(one.getUuid()); + System.err.println(two.getUuid()); + System.err.println(three.getUuid()); + + assertThat(twentySomethings.contains(one), is(true)); + + } + + @Test + public void testFindByAgeLessThan() { + + one = participantRepository.save(one); + two = participantRepository.save(two); + three = participantRepository.save(three); + + List twentySomethings = participantRepository.findByAgeLessThan(40); + assertThat(twentySomethings.contains(one), is(true)); + assertThat(twentySomethings.contains(three), is(false)); + } + + @Test + public void testFindAgeBetween() { + one = participantRepository.save(one); + two = participantRepository.save(two); + three = participantRepository.save(three); + + List twentySomethings = participantRepository.findByAgeBetween(40, 70); + assertThat(twentySomethings.contains(one), is(false)); + assertThat(twentySomethings.contains(three), is(true)); + } + + @Test + public void testFindByLastName() { + + one = participantRepository.save(one); + two = participantRepository.save(two); + three = participantRepository.save(three); + + List theDoes = participantRepository.findByLastName("Doe"); + + assertThat(theDoes.contains(one), is(true)); + assertThat(theDoes.contains(three), is(false)); + + } + + + @After + public void tearDown() { + participantRepository.deleteAll(); + raceRepository.deleteAll(); + } + + +} diff --git a/jpa/pom.xml b/jpa/pom.xml index 045710cf..f5a0818a 100644 --- a/jpa/pom.xml +++ b/jpa/pom.xml @@ -24,6 +24,7 @@ jpa21 security multiple-datasources + eclipselink @@ -45,4 +46,4 @@ - \ No newline at end of file +