Skip to content

Commit

Permalink
Merge branch 'master' into develop
Browse files Browse the repository at this point in the history
  • Loading branch information
alex268 committed Feb 2, 2024
2 parents 22dee7c + 9bebfc2 commit 354bbb4
Show file tree
Hide file tree
Showing 37 changed files with 1,793 additions and 14 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,10 @@ jobs:

steps:
- name: Checkout
uses: actions/checkout@v3
uses: actions/checkout@v4

- name: Set up JDK
uses: actions/setup-java@v3
uses: actions/setup-java@v4
with:
java-version: ${{ matrix.java }}
distribution: 'temurin'
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/validate.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@ jobs:

steps:
- name: Checkout
uses: actions/checkout@v3
uses: actions/checkout@v4

- name: Set up JDK
uses: actions/setup-java@v3
uses: actions/setup-java@v4
with:
java-version: ${{ matrix.java }}
distribution: 'temurin'
Expand Down
17 changes: 15 additions & 2 deletions jdbc/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,13 @@
<packaging>pom</packaging>

<properties>
<ydb.jdbc.version>2.0.2</ydb.jdbc.version>
<slf4j.version>1.7.25</slf4j.version>
<ydb.jdbc.version>2.0.6</ydb.jdbc.version>
<slf4j.version>1.7.36</slf4j.version>
</properties>

<modules>
<module>basic-example</module>
<module>spring-data-jpa-v5</module>
</modules>

<dependencyManagement>
Expand All @@ -38,4 +39,16 @@
</dependency>
</dependencies>
</dependencyManagement>

<profiles>
<profile>
<id>jdk17-examples</id>
<activation>
<jdk>[17</jdk>
</activation>
<modules>
<module>spring-data-jpa</module>
</modules>
</profile>
</profiles>
</project>
147 changes: 147 additions & 0 deletions jdbc/spring-data-jpa-v5/pom.xml
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>
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
}
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
}
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>
}
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
Loading

0 comments on commit 354bbb4

Please sign in to comment.