-
Notifications
You must be signed in to change notification settings - Fork 2.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #14014 from renegrob/support-hibernate-provided-ba…
…sic-types Support hibernate provided basic types
- Loading branch information
Showing
7 changed files
with
285 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
97 changes: 97 additions & 0 deletions
97
...ng-data-jpa/deployment/src/test/java/io/quarkus/spring/data/deployment/BasicTypeData.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
package io.quarkus.spring.data.deployment; | ||
|
||
import java.math.BigDecimal; | ||
import java.net.URL; | ||
import java.time.Duration; | ||
import java.util.Locale; | ||
import java.util.TimeZone; | ||
import java.util.UUID; | ||
|
||
import javax.persistence.Entity; | ||
import javax.persistence.GeneratedValue; | ||
import javax.persistence.Id; | ||
|
||
@Entity | ||
public class BasicTypeData { | ||
|
||
@Id | ||
@GeneratedValue | ||
private Integer id; | ||
|
||
private Double doubleValue; | ||
private BigDecimal bigDecimalValue; | ||
private Locale locale; | ||
private TimeZone timeZone; | ||
private java.net.URL url; | ||
private Class clazz; | ||
private java.util.UUID uuid; | ||
private Duration duration; | ||
|
||
public Integer getId() { | ||
return id; | ||
} | ||
|
||
public Double getDoubleValue() { | ||
return doubleValue; | ||
} | ||
|
||
public void setDoubleValue(Double doubleValue) { | ||
this.doubleValue = doubleValue; | ||
} | ||
|
||
public BigDecimal getBigDecimalValue() { | ||
return bigDecimalValue; | ||
} | ||
|
||
public void setBigDecimalValue(BigDecimal bigDecimalValue) { | ||
this.bigDecimalValue = bigDecimalValue; | ||
} | ||
|
||
public Locale getLocale() { | ||
return locale; | ||
} | ||
|
||
public void setLocale(Locale locale) { | ||
this.locale = locale; | ||
} | ||
|
||
public TimeZone getTimeZone() { | ||
return timeZone; | ||
} | ||
|
||
public void setTimeZone(TimeZone timeZone) { | ||
this.timeZone = timeZone; | ||
} | ||
|
||
public URL getUrl() { | ||
return url; | ||
} | ||
|
||
public void setUrl(URL url) { | ||
this.url = url; | ||
} | ||
|
||
public Class getClazz() { | ||
return clazz; | ||
} | ||
|
||
public void setClazz(Class clazz) { | ||
this.clazz = clazz; | ||
} | ||
|
||
public UUID getUuid() { | ||
return uuid; | ||
} | ||
|
||
public void setUuid(UUID uuid) { | ||
this.uuid = uuid; | ||
} | ||
|
||
public Duration getDuration() { | ||
return duration; | ||
} | ||
|
||
public void setDuration(Duration duration) { | ||
this.duration = duration; | ||
} | ||
} |
25 changes: 25 additions & 0 deletions
25
...a/deployment/src/test/java/io/quarkus/spring/data/deployment/BasicTypeDataRepository.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
package io.quarkus.spring.data.deployment; | ||
|
||
import java.net.URL; | ||
import java.time.Duration; | ||
import java.util.Locale; | ||
import java.util.Set; | ||
import java.util.TimeZone; | ||
import java.util.UUID; | ||
|
||
import org.springframework.data.jpa.repository.JpaRepository; | ||
import org.springframework.data.jpa.repository.Query; | ||
import org.springframework.stereotype.Repository; | ||
|
||
@Repository | ||
public interface BasicTypeDataRepository extends JpaRepository<BasicTypeData, Integer> { | ||
|
||
@Query("select doubleValue from BasicTypeData where url = ?1") | ||
Double doubleByURL(URL url); | ||
|
||
@Query("select duration from BasicTypeData where uuid = ?1") | ||
Duration durationByUUID(UUID uuid); | ||
|
||
@Query("select timeZone from BasicTypeData where locale = ?1") | ||
Set<TimeZone> timeZonesByLocale(Locale locale); | ||
} |
90 changes: 90 additions & 0 deletions
90
...ployment/src/test/java/io/quarkus/spring/data/deployment/BasicTypeDataRepositoryTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
package io.quarkus.spring.data.deployment; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
|
||
import java.math.BigDecimal; | ||
import java.net.MalformedURLException; | ||
import java.net.URL; | ||
import java.time.Duration; | ||
import java.util.Locale; | ||
import java.util.Set; | ||
import java.util.TimeZone; | ||
import java.util.UUID; | ||
|
||
import javax.inject.Inject; | ||
import javax.transaction.Transactional; | ||
|
||
import org.assertj.core.data.Percentage; | ||
import org.hibernate.Hibernate; | ||
import org.jboss.shrinkwrap.api.ShrinkWrap; | ||
import org.jboss.shrinkwrap.api.spec.JavaArchive; | ||
import org.junit.jupiter.api.MethodOrderer; | ||
import org.junit.jupiter.api.Order; | ||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.api.TestMethodOrder; | ||
import org.junit.jupiter.api.extension.RegisterExtension; | ||
|
||
import io.quarkus.test.QuarkusUnitTest; | ||
|
||
@TestMethodOrder(MethodOrderer.OrderAnnotation.class) | ||
public class BasicTypeDataRepositoryTest { | ||
|
||
@RegisterExtension | ||
static final QuarkusUnitTest TEST = new QuarkusUnitTest().setArchiveProducer( | ||
() -> ShrinkWrap.create(JavaArchive.class) | ||
.addClasses(BasicTypeData.class, BasicTypeDataRepository.class)) | ||
.withConfigurationResource("application.properties"); | ||
|
||
private static final UUID uuid = UUID.randomUUID(); | ||
private static final String QUARKUS_URL = "https://quarkus.io/guides/spring-data-jpa"; | ||
private static final String DURATION = "PT828H19M54.656S"; | ||
private static final String TIME_ZONE = "CST"; | ||
|
||
@Inject | ||
BasicTypeDataRepository repo; | ||
|
||
@Test | ||
@Order(1) | ||
@Transactional | ||
public void testInsert() throws Exception { | ||
BasicTypeData item = populateData(new BasicTypeData()); | ||
repo.save(item); | ||
} | ||
|
||
@Test | ||
@Order(2) | ||
@Transactional | ||
public void testDoubleByURL() throws Exception { | ||
Double price = repo.doubleByURL(new URL(QUARKUS_URL)); | ||
assertThat(price).isCloseTo(Math.PI, Percentage.withPercentage(1)); | ||
} | ||
|
||
@Test | ||
@Order(3) | ||
@Transactional | ||
public void testDurationByUUID() { | ||
Duration duration = repo.durationByUUID(uuid); | ||
assertThat(duration).isEqualTo(Duration.parse(DURATION)); | ||
} | ||
|
||
@Test | ||
@Order(4) | ||
@Transactional | ||
public void testTimeZonesByLocale() { | ||
final Set<TimeZone> timeZones = repo.timeZonesByLocale(Locale.TRADITIONAL_CHINESE); | ||
assertThat(timeZones).isNotEmpty().contains(TimeZone.getTimeZone("CST")); | ||
} | ||
|
||
private BasicTypeData populateData(BasicTypeData basicTypeData) throws MalformedURLException { | ||
basicTypeData.setDoubleValue(Math.PI); | ||
basicTypeData.setBigDecimalValue(BigDecimal.valueOf(Math.PI * 2.0)); | ||
basicTypeData.setLocale(Locale.TRADITIONAL_CHINESE); | ||
basicTypeData.setTimeZone(TimeZone.getTimeZone(TIME_ZONE)); | ||
basicTypeData.setUrl(new URL(QUARKUS_URL)); | ||
basicTypeData.setClazz(Hibernate.class); | ||
basicTypeData.setUuid(uuid); | ||
basicTypeData.setDuration(Duration.parse(DURATION)); | ||
|
||
return basicTypeData; | ||
} | ||
} |