Skip to content

Commit

Permalink
Merge branch 'master' into add-topic-transaction-examples
Browse files Browse the repository at this point in the history
  • Loading branch information
pnv1 committed Mar 29, 2024
2 parents 53998f0 + 952de6e commit 11b66d7
Show file tree
Hide file tree
Showing 25 changed files with 1,108 additions and 32 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ on:
- master
- develop
pull_request:
type: [opened, reopened, edited]
type: [opened, reopened, edited, synchronize]

jobs:
build:
Expand Down Expand Up @@ -44,7 +44,7 @@ jobs:
- name: Checkout YDB Java SDK
if: ${{ env.NEED_SDK }}
uses: actions/checkout@v3
uses: actions/checkout@v4
with:
repository: ydb-platform/ydb-java-sdk
ref: develop
Expand All @@ -61,7 +61,7 @@ jobs:

- name: Checkout YDB YC Auth Provider
if: ${{ env.NEED_SDK }}
uses: actions/checkout@v3
uses: actions/checkout@v4
with:
repository: ydb-platform/ydb-java-yc
ref: develop
Expand Down
4 changes: 0 additions & 4 deletions basic_example/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,6 @@
<groupId>tech.ydb</groupId>
<artifactId>ydb-sdk-table</artifactId>
</dependency>
<dependency>
<groupId>tech.ydb</groupId>
<artifactId>ydb-sdk-topic</artifactId>
</dependency>
<dependency>
<groupId>tech.ydb.auth</groupId>
<artifactId>yc-auth-provider</artifactId>
Expand Down
12 changes: 5 additions & 7 deletions basic_example/src/main/java/tech/ydb/example/App.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
import tech.ydb.table.settings.BulkUpsertSettings;
import tech.ydb.table.settings.ExecuteScanQuerySettings;
import tech.ydb.table.transaction.TableTransaction;
import tech.ydb.table.transaction.Transaction;
import tech.ydb.table.transaction.TxControl;
import tech.ydb.table.values.ListType;
import tech.ydb.table.values.ListValue;
Expand Down Expand Up @@ -305,6 +304,7 @@ private void scanQueryWithParams(long seriesID, long seasonID) {

private void multiStepTransaction(long seriesID, long seasonID) {
retryCtx.supplyStatus(session -> {
TableTransaction transaction = session.createNewTransaction(TxMode.SERIALIZABLE_RW);
String query1
= "DECLARE $seriesId AS Uint64; "
+ "DECLARE $seasonId AS Uint64; "
Expand All @@ -314,8 +314,7 @@ private void multiStepTransaction(long seriesID, long seasonID) {
// Execute first query to get the required values to the client.
// Transaction control settings don't set CommitTx flag to keep transaction active
// after query execution.
TxControl<?> tx1 = TxControl.serializableRw().setCommitTx(false);
DataQueryResult res1 = session.executeDataQuery(query1, tx1, Params.of(
DataQueryResult res1 = transaction.executeDataQuery(query1, Params.of(
"$seriesId", PrimitiveValue.newUint64(seriesID),
"$seasonId", PrimitiveValue.newUint64(seasonID)
)).join().getValue();
Expand All @@ -329,7 +328,7 @@ private void multiStepTransaction(long seriesID, long seasonID) {
LocalDate toDate = fromDate.plusDays(15);

// Get active transaction id
String txId = res1.getTxId();
logger.info("got transaction id {}", transaction.getId());

// Construct next query based on the results of client logic
String query2
Expand All @@ -342,8 +341,7 @@ private void multiStepTransaction(long seriesID, long seasonID) {
// Execute second query.
// Transaction control settings continues active transaction (tx) and
// commits it at the end of second query execution.
TxControl<?> tx2 = TxControl.id(txId).setCommitTx(true);
DataQueryResult res2 = session.executeDataQuery(query2, tx2, Params.of(
DataQueryResult res2 = transaction.executeDataQueryAndCommit(query2, Params.of(
"$seriesId", PrimitiveValue.newUint64(seriesID),
"$fromDate", PrimitiveValue.newDate(fromDate),
"$toDate", PrimitiveValue.newDate(toDate)
Expand Down Expand Up @@ -375,7 +373,7 @@ private void tclTransaction() {
Params params = Params.of("$airDate", PrimitiveValue.newDate(Instant.now()));

// Execute data query on new transaction.
// Transaction will be created on server and become active
// Transaction will be created on server and become active on client
// Query will be executed on it, but transaction will not be committed
DataQueryResult result = transaction.executeDataQuery(query, params)
.join().getValue();
Expand Down
1 change: 1 addition & 0 deletions jdbc/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
</activation>
<modules>
<module>spring-data-jpa</module>
<module>spring-liquibase-app</module>
</modules>
</profile>
</profiles>
Expand Down
4 changes: 2 additions & 2 deletions jdbc/spring-data-jpa-v5/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
<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>
<hibernate.ydb.dialect.version>0.9.2</hibernate.ydb.dialect.version>
<spring.boot.version>2.5.7</spring.boot.version>
</properties>
<dependencies>
Expand Down Expand Up @@ -57,7 +57,7 @@
<dependency>
<groupId>org.postgresql</groupId>
<artifactId>postgresql</artifactId>
<version>42.7.1</version>
<version>42.7.3</version>
</dependency>
<dependency>
<groupId>org.testcontainers</groupId>
Expand Down
4 changes: 2 additions & 2 deletions jdbc/spring-data-jpa/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
<properties>
<maven.compiler.release>17</maven.compiler.release>
<kotlin.version>1.9.22</kotlin.version>
<hibernate.ydb.dialect.version>0.9.1</hibernate.ydb.dialect.version>
<hibernate.ydb.dialect.version>0.9.2</hibernate.ydb.dialect.version>
<spring.boot.version>3.2.1</spring.boot.version>
</properties>
<dependencies>
Expand Down Expand Up @@ -58,7 +58,7 @@
<dependency>
<groupId>org.postgresql</groupId>
<artifactId>postgresql</artifactId>
<version>42.7.1</version>
<version>42.7.3</version>
</dependency>
<dependency>
<groupId>org.testcontainers</groupId>
Expand Down
140 changes: 140 additions & 0 deletions jdbc/spring-liquibase-app/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,140 @@
<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-liquibase-app</artifactId>
<name>Spring Liquibase Example</name>
<description>Basic example for SpringBoot3 and Liquibase</description>
<properties>
<maven.compiler.release>17</maven.compiler.release>
<kotlin.version>1.9.22</kotlin.version>
<hibernate.ydb.dialect.version>0.9.1</hibernate.ydb.dialect.version>
<spring.boot.version>3.2.1</spring.boot.version>
<liquibase.ydb.dialect.version>0.9.1</liquibase.ydb.dialect.version>
<liquibase.core.version>4.24.0</liquibase.core.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</artifactId>
<version>${hibernate.ydb.dialect.version}</version>
</dependency>
<dependency>
<groupId>tech.ydb.jdbc</groupId>
<artifactId>ydb-jdbc-driver-shaded</artifactId>
</dependency>
<dependency>
<groupId>tech.ydb.dialects</groupId>
<artifactId>liquibase-ydb-dialect</artifactId>
<version>0.9.7</version>
</dependency>
<dependency>
<groupId>org.liquibase</groupId>
<artifactId>liquibase-core</artifactId>
<version>${liquibase.core.version}</version>
</dependency>

<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<version>${spring.boot.version}</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>
</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,9 @@
package tech.ydb.liquibase

import org.springframework.boot.autoconfigure.SpringBootApplication

/**
* @author Kirill Kurdyukov
*/
@SpringBootApplication
class LiquibaseApplication
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package tech.ydb.liquibase.model

import jakarta.persistence.Column
import jakarta.persistence.Entity
import jakarta.persistence.Id
import jakarta.persistence.Table
import java.time.LocalDate
import java.time.LocalDateTime

@Entity
@Table(name = "employee")
data class Employee(
@Id
val id: Long,

@Column(name = "full_name")
val fullName: String,

@Column
val email: String,

@Column(name = "hire_date")
val hireDate: LocalDate,

@Column
val salary: java.math.BigDecimal,

@Column(name = "is_active")
val isActive: Boolean,

@Column
val department: String,

@Column
val age: Int,
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package tech.ydb.liquibase.repository

import org.springframework.data.repository.CrudRepository
import tech.ydb.liquibase.model.Employee

interface EmployeeRepository : CrudRepository<Employee, Long>

fun EmployeeRepository.findByIdOrNull(id: Long): Employee? = this.findById(id).orElse(null)
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
spring.jpa.properties.hibernate.dialect=tech.ydb.hibernate.dialect.YdbDialect

spring.datasource.driver-class-name=tech.ydb.jdbc.YdbDriver
spring.datasource.url=jdbc:ydb:grpc://localhost:2136/local

spring.liquibase.change-log=classpath:changelog.yaml

logging.level.liquibase=DEBUG
45 changes: 45 additions & 0 deletions jdbc/spring-liquibase-app/src/main/resources/changelog.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
databaseChangeLog:
- changeSet:
id: "employee"
author: "kurdyukov-kir"
changes:
- createTable:
tableName: employee
columns:
- column:
name: id
type: bigint
constraints:
primaryKey: true
nullable: false
- column:
name: full_name
type: varchar
- column:
name: email
type: varchar
- column:
name: hire_date
type: date
- column:
name: salary
type: decimal(22,9)
- column:
name: is_active
type: boolean
- column:
name: department
type: varchar
- column:
name: age
type: int
- column:
name: limit_date_password
type: datetime
- createIndex:
indexName: idx_employee_email
tableName: employee
unique: false
columns:
- column:
name: email
Loading

0 comments on commit 11b66d7

Please sign in to comment.