-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
37 changed files
with
1,793 additions
and
14 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,147 @@ | ||
<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 https://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
<modelVersion>4.0.0</modelVersion> | ||
<parent> | ||
<groupId>tech.ydb.jdbc.examples</groupId> | ||
<artifactId>ydb-jdbc-examples</artifactId> | ||
<version>1.1.0-SNAPSHOT</version> | ||
</parent> | ||
|
||
<artifactId>spring-data-jpa-v5</artifactId> | ||
<name>Spring Data JPA Example Hibernate 5</name> | ||
<description>Basic example for SpringBoot3 and Hibernate 6</description> | ||
<properties> | ||
<kotlin.version>1.9.22</kotlin.version> | ||
<hibernate.ydb.dialect.version>0.9.1</hibernate.ydb.dialect.version> | ||
<spring.boot.version>2.5.7</spring.boot.version> | ||
</properties> | ||
<dependencies> | ||
<dependency> | ||
<groupId>org.springframework.boot</groupId> | ||
<artifactId>spring-boot-starter-data-jpa</artifactId> | ||
<version>${spring.boot.version}</version> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.springframework.data</groupId> | ||
<artifactId>spring-data-commons</artifactId> | ||
<version>${spring.boot.version}</version> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.jetbrains.kotlin</groupId> | ||
<artifactId>kotlin-reflect</artifactId> | ||
<version>${kotlin.version}</version> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.jetbrains.kotlin</groupId> | ||
<artifactId>kotlin-stdlib</artifactId> | ||
<version>${kotlin.version}</version> | ||
</dependency> | ||
<dependency> | ||
<groupId>tech.ydb.dialects</groupId> | ||
<artifactId>hibernate-ydb-dialect-v5</artifactId> | ||
<version>${hibernate.ydb.dialect.version}</version> | ||
</dependency> | ||
<dependency> | ||
<groupId>tech.ydb.jdbc</groupId> | ||
<artifactId>ydb-jdbc-driver-shaded</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>com.github.javafaker</groupId> | ||
<artifactId>javafaker</artifactId> | ||
<version>1.0.2</version> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.jetbrains.kotlinx</groupId> | ||
<artifactId>kotlinx-coroutines-core</artifactId> | ||
<version>1.7.3</version> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.postgresql</groupId> | ||
<artifactId>postgresql</artifactId> | ||
<version>42.7.1</version> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.testcontainers</groupId> | ||
<artifactId>postgresql</artifactId> | ||
<version>1.19.1</version> | ||
<scope>test</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>tech.ydb.test</groupId> | ||
<artifactId>ydb-junit5-support</artifactId> | ||
<scope>test</scope> | ||
<exclusions> | ||
<exclusion> | ||
<groupId>org.junit.jupiter</groupId> | ||
<artifactId>junit-jupiter-api</artifactId> | ||
</exclusion> | ||
</exclusions> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.springframework.boot</groupId> | ||
<artifactId>spring-boot-starter-test</artifactId> | ||
<version>${spring.boot.version}</version> | ||
<scope>test</scope> | ||
</dependency> | ||
</dependencies> | ||
<build> | ||
<sourceDirectory>${project.basedir}/src/main/kotlin</sourceDirectory> | ||
<testSourceDirectory>${project.basedir}/src/test/kotlin</testSourceDirectory> | ||
<plugins> | ||
<plugin> | ||
<groupId>org.apache.maven.plugins</groupId> | ||
<artifactId>maven-surefire-plugin</artifactId> | ||
<configuration> | ||
<environmentVariables> | ||
<TESTCONTAINERS_REUSE_ENABLE>true</TESTCONTAINERS_REUSE_ENABLE> | ||
</environmentVariables> | ||
</configuration> | ||
</plugin> | ||
<plugin> | ||
<groupId>org.springframework.boot</groupId> | ||
<artifactId>spring-boot-maven-plugin</artifactId> | ||
<version>${spring.boot.version}</version> | ||
</plugin> | ||
<plugin> | ||
<groupId>org.jetbrains.kotlin</groupId> | ||
<artifactId>kotlin-maven-plugin</artifactId> | ||
<version>${kotlin.version}</version> | ||
<executions> | ||
<execution> | ||
<id>compile</id> | ||
<phase>compile</phase> | ||
<goals> | ||
<goal>compile</goal> | ||
</goals> | ||
</execution> | ||
<execution> | ||
<id>test-compile</id> | ||
<goals> | ||
<goal>test-compile</goal> | ||
</goals> | ||
</execution> | ||
</executions> | ||
<configuration> | ||
<args> | ||
<arg>-Xjsr305=strict</arg> | ||
</args> | ||
<compilerPlugins> | ||
<plugin>spring</plugin> | ||
<plugin>jpa</plugin> | ||
</compilerPlugins> | ||
</configuration> | ||
<dependencies> | ||
<dependency> | ||
<groupId>org.jetbrains.kotlin</groupId> | ||
<artifactId>kotlin-maven-allopen</artifactId> | ||
<version>${kotlin.version}</version> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.jetbrains.kotlin</groupId> | ||
<artifactId>kotlin-maven-noarg</artifactId> | ||
<version>${kotlin.version}</version> | ||
</dependency> | ||
</dependencies> | ||
</plugin> | ||
</plugins> | ||
</build> | ||
</project> |
17 changes: 17 additions & 0 deletions
17
jdbc/spring-data-jpa-v5/src/main/kotlin/tech/ydb/jpa/pagination/Author.kt
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,17 @@ | ||
package tech.ydb.jpa.pagination | ||
|
||
import javax.persistence.Entity | ||
import javax.persistence.Id | ||
import javax.persistence.Table | ||
|
||
@Entity | ||
@Table(name = "authors") | ||
class Author { | ||
|
||
@Id | ||
lateinit var id: String | ||
|
||
lateinit var firstName: String | ||
|
||
lateinit var lastName: String | ||
} |
19 changes: 19 additions & 0 deletions
19
jdbc/spring-data-jpa-v5/src/main/kotlin/tech/ydb/jpa/pagination/Book.kt
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,19 @@ | ||
package tech.ydb.jpa.pagination | ||
|
||
import java.util.* | ||
import javax.persistence.* | ||
|
||
@Entity | ||
@Table(name = "books") | ||
class Book { | ||
|
||
@Id | ||
lateinit var id: String | ||
|
||
lateinit var title: String | ||
lateinit var isbn10: String | ||
lateinit var publicationDate: Date | ||
|
||
@ManyToOne | ||
lateinit var author: Author | ||
} |
39 changes: 39 additions & 0 deletions
39
jdbc/spring-data-jpa-v5/src/main/kotlin/tech/ydb/jpa/pagination/BookRepository.kt
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,39 @@ | ||
package tech.ydb.jpa.pagination | ||
|
||
import org.springframework.data.domain.* | ||
import org.springframework.data.jpa.repository.Query | ||
import org.springframework.data.repository.CrudRepository | ||
import org.springframework.data.repository.query.Param | ||
|
||
interface BookRepository : CrudRepository<Book, String> { | ||
|
||
/** | ||
* Uses an offset based pagination that first sorts the entries by their [ publication_date][Book.getPublicationDate] | ||
* and then limits the result by dropping the number of rows specified in the | ||
* [offset][Pageable.getOffset] clause. To retrieve [Page.getTotalElements] an additional count query | ||
* is executed. | ||
* | ||
* @param title | ||
* @param pageable | ||
*/ | ||
@Query( | ||
"SELECT * FROM books WHERE books.title LIKE %:title% ORDER BY books.publication_date", | ||
countQuery = "SELECT count(*) FROM books WHERE books.title LIKE %:title%", | ||
nativeQuery = true | ||
) | ||
fun findByTitleContainsOrderByPublicationDate(@Param("title") title: String, pageable: Pageable): Page<Book> | ||
|
||
/** | ||
* Uses an offset based slicing that first sorts the entries by their [ publication_date][Book.getPublicationDate] | ||
* and then limits the result by dropping the number of rows specified in the | ||
* [offset][Pageable.getOffset] clause. | ||
* | ||
* @param title | ||
* @param pageable | ||
*/ | ||
@Query( | ||
"SELECT * FROM books WHERE books.title LIKE %:title% ORDER BY books.publication_date", | ||
nativeQuery = true | ||
) | ||
fun findBooksByTitleContainsOrderByPublicationDate(title: String, pageable: Pageable): Slice<Book> | ||
} |
6 changes: 6 additions & 0 deletions
6
jdbc/spring-data-jpa-v5/src/main/kotlin/tech/ydb/jpa/pagination/PagingApplication.kt
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,6 @@ | ||
package tech.ydb.jpa.pagination | ||
|
||
import org.springframework.boot.autoconfigure.SpringBootApplication | ||
|
||
@SpringBootApplication | ||
class PagingApplication |
Oops, something went wrong.