Skip to content

Commit 11b66d7

Browse files
committed
Merge branch 'master' into add-topic-transaction-examples
2 parents 53998f0 + 952de6e commit 11b66d7

File tree

25 files changed

+1108
-32
lines changed

25 files changed

+1108
-32
lines changed

.github/workflows/build.yaml

+3-3
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ on:
66
- master
77
- develop
88
pull_request:
9-
type: [opened, reopened, edited]
9+
type: [opened, reopened, edited, synchronize]
1010

1111
jobs:
1212
build:
@@ -44,7 +44,7 @@ jobs:
4444
4545
- name: Checkout YDB Java SDK
4646
if: ${{ env.NEED_SDK }}
47-
uses: actions/checkout@v3
47+
uses: actions/checkout@v4
4848
with:
4949
repository: ydb-platform/ydb-java-sdk
5050
ref: develop
@@ -61,7 +61,7 @@ jobs:
6161

6262
- name: Checkout YDB YC Auth Provider
6363
if: ${{ env.NEED_SDK }}
64-
uses: actions/checkout@v3
64+
uses: actions/checkout@v4
6565
with:
6666
repository: ydb-platform/ydb-java-yc
6767
ref: develop

basic_example/pom.xml

-4
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,6 @@
2121
<groupId>tech.ydb</groupId>
2222
<artifactId>ydb-sdk-table</artifactId>
2323
</dependency>
24-
<dependency>
25-
<groupId>tech.ydb</groupId>
26-
<artifactId>ydb-sdk-topic</artifactId>
27-
</dependency>
2824
<dependency>
2925
<groupId>tech.ydb.auth</groupId>
3026
<artifactId>yc-auth-provider</artifactId>

basic_example/src/main/java/tech/ydb/example/App.java

+5-7
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@
2626
import tech.ydb.table.settings.BulkUpsertSettings;
2727
import tech.ydb.table.settings.ExecuteScanQuerySettings;
2828
import tech.ydb.table.transaction.TableTransaction;
29-
import tech.ydb.table.transaction.Transaction;
3029
import tech.ydb.table.transaction.TxControl;
3130
import tech.ydb.table.values.ListType;
3231
import tech.ydb.table.values.ListValue;
@@ -305,6 +304,7 @@ private void scanQueryWithParams(long seriesID, long seasonID) {
305304

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

331330
// Get active transaction id
332-
String txId = res1.getTxId();
331+
logger.info("got transaction id {}", transaction.getId());
333332

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

377375
// Execute data query on new transaction.
378-
// Transaction will be created on server and become active
376+
// Transaction will be created on server and become active on client
379377
// Query will be executed on it, but transaction will not be committed
380378
DataQueryResult result = transaction.executeDataQuery(query, params)
381379
.join().getValue();

jdbc/pom.xml

+1
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@
4848
</activation>
4949
<modules>
5050
<module>spring-data-jpa</module>
51+
<module>spring-liquibase-app</module>
5152
</modules>
5253
</profile>
5354
</profiles>

jdbc/spring-data-jpa-v5/pom.xml

+2-2
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
<description>Basic example for SpringBoot3 and Hibernate 6</description>
1212
<properties>
1313
<kotlin.version>1.9.22</kotlin.version>
14-
<hibernate.ydb.dialect.version>0.9.1</hibernate.ydb.dialect.version>
14+
<hibernate.ydb.dialect.version>0.9.2</hibernate.ydb.dialect.version>
1515
<spring.boot.version>2.5.7</spring.boot.version>
1616
</properties>
1717
<dependencies>
@@ -57,7 +57,7 @@
5757
<dependency>
5858
<groupId>org.postgresql</groupId>
5959
<artifactId>postgresql</artifactId>
60-
<version>42.7.1</version>
60+
<version>42.7.3</version>
6161
</dependency>
6262
<dependency>
6363
<groupId>org.testcontainers</groupId>

jdbc/spring-data-jpa/pom.xml

+2-2
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
<properties>
1313
<maven.compiler.release>17</maven.compiler.release>
1414
<kotlin.version>1.9.22</kotlin.version>
15-
<hibernate.ydb.dialect.version>0.9.1</hibernate.ydb.dialect.version>
15+
<hibernate.ydb.dialect.version>0.9.2</hibernate.ydb.dialect.version>
1616
<spring.boot.version>3.2.1</spring.boot.version>
1717
</properties>
1818
<dependencies>
@@ -58,7 +58,7 @@
5858
<dependency>
5959
<groupId>org.postgresql</groupId>
6060
<artifactId>postgresql</artifactId>
61-
<version>42.7.1</version>
61+
<version>42.7.3</version>
6262
</dependency>
6363
<dependency>
6464
<groupId>org.testcontainers</groupId>

jdbc/spring-liquibase-app/pom.xml

+140
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,140 @@
1+
<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">
2+
<modelVersion>4.0.0</modelVersion>
3+
<parent>
4+
<groupId>tech.ydb.jdbc.examples</groupId>
5+
<artifactId>ydb-jdbc-examples</artifactId>
6+
<version>1.1.0-SNAPSHOT</version>
7+
</parent>
8+
9+
<artifactId>spring-liquibase-app</artifactId>
10+
<name>Spring Liquibase Example</name>
11+
<description>Basic example for SpringBoot3 and Liquibase</description>
12+
<properties>
13+
<maven.compiler.release>17</maven.compiler.release>
14+
<kotlin.version>1.9.22</kotlin.version>
15+
<hibernate.ydb.dialect.version>0.9.1</hibernate.ydb.dialect.version>
16+
<spring.boot.version>3.2.1</spring.boot.version>
17+
<liquibase.ydb.dialect.version>0.9.1</liquibase.ydb.dialect.version>
18+
<liquibase.core.version>4.24.0</liquibase.core.version>
19+
</properties>
20+
<dependencies>
21+
<dependency>
22+
<groupId>org.springframework.boot</groupId>
23+
<artifactId>spring-boot-starter-data-jpa</artifactId>
24+
<version>${spring.boot.version}</version>
25+
</dependency>
26+
<dependency>
27+
<groupId>org.springframework.data</groupId>
28+
<artifactId>spring-data-commons</artifactId>
29+
<version>${spring.boot.version}</version>
30+
</dependency>
31+
<dependency>
32+
<groupId>org.jetbrains.kotlin</groupId>
33+
<artifactId>kotlin-reflect</artifactId>
34+
<version>${kotlin.version}</version>
35+
</dependency>
36+
<dependency>
37+
<groupId>org.jetbrains.kotlin</groupId>
38+
<artifactId>kotlin-stdlib</artifactId>
39+
<version>${kotlin.version}</version>
40+
</dependency>
41+
<dependency>
42+
<groupId>tech.ydb.dialects</groupId>
43+
<artifactId>hibernate-ydb-dialect</artifactId>
44+
<version>${hibernate.ydb.dialect.version}</version>
45+
</dependency>
46+
<dependency>
47+
<groupId>tech.ydb.jdbc</groupId>
48+
<artifactId>ydb-jdbc-driver-shaded</artifactId>
49+
</dependency>
50+
<dependency>
51+
<groupId>tech.ydb.dialects</groupId>
52+
<artifactId>liquibase-ydb-dialect</artifactId>
53+
<version>0.9.7</version>
54+
</dependency>
55+
<dependency>
56+
<groupId>org.liquibase</groupId>
57+
<artifactId>liquibase-core</artifactId>
58+
<version>${liquibase.core.version}</version>
59+
</dependency>
60+
61+
<dependency>
62+
<groupId>org.springframework.boot</groupId>
63+
<artifactId>spring-boot-starter-test</artifactId>
64+
<version>${spring.boot.version}</version>
65+
<scope>test</scope>
66+
</dependency>
67+
<dependency>
68+
<groupId>tech.ydb.test</groupId>
69+
<artifactId>ydb-junit5-support</artifactId>
70+
<scope>test</scope>
71+
<exclusions>
72+
<exclusion>
73+
<groupId>org.junit.jupiter</groupId>
74+
<artifactId>junit-jupiter-api</artifactId>
75+
</exclusion>
76+
</exclusions>
77+
</dependency>
78+
</dependencies>
79+
<build>
80+
<sourceDirectory>${project.basedir}/src/main/kotlin</sourceDirectory>
81+
<testSourceDirectory>${project.basedir}/src/test/kotlin</testSourceDirectory>
82+
<plugins>
83+
<plugin>
84+
<groupId>org.apache.maven.plugins</groupId>
85+
<artifactId>maven-surefire-plugin</artifactId>
86+
<configuration>
87+
<environmentVariables>
88+
<TESTCONTAINERS_REUSE_ENABLE>true</TESTCONTAINERS_REUSE_ENABLE>
89+
</environmentVariables>
90+
</configuration>
91+
</plugin>
92+
<plugin>
93+
<groupId>org.springframework.boot</groupId>
94+
<artifactId>spring-boot-maven-plugin</artifactId>
95+
<version>${spring.boot.version}</version>
96+
</plugin>
97+
<plugin>
98+
<groupId>org.jetbrains.kotlin</groupId>
99+
<artifactId>kotlin-maven-plugin</artifactId>
100+
<version>${kotlin.version}</version>
101+
<executions>
102+
<execution>
103+
<id>compile</id>
104+
<phase>compile</phase>
105+
<goals>
106+
<goal>compile</goal>
107+
</goals>
108+
</execution>
109+
<execution>
110+
<id>test-compile</id>
111+
<goals>
112+
<goal>test-compile</goal>
113+
</goals>
114+
</execution>
115+
</executions>
116+
<configuration>
117+
<args>
118+
<arg>-Xjsr305=strict</arg>
119+
</args>
120+
<compilerPlugins>
121+
<plugin>spring</plugin>
122+
<plugin>jpa</plugin>
123+
</compilerPlugins>
124+
</configuration>
125+
<dependencies>
126+
<dependency>
127+
<groupId>org.jetbrains.kotlin</groupId>
128+
<artifactId>kotlin-maven-allopen</artifactId>
129+
<version>${kotlin.version}</version>
130+
</dependency>
131+
<dependency>
132+
<groupId>org.jetbrains.kotlin</groupId>
133+
<artifactId>kotlin-maven-noarg</artifactId>
134+
<version>${kotlin.version}</version>
135+
</dependency>
136+
</dependencies>
137+
</plugin>
138+
</plugins>
139+
</build>
140+
</project>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
package tech.ydb.liquibase
2+
3+
import org.springframework.boot.autoconfigure.SpringBootApplication
4+
5+
/**
6+
* @author Kirill Kurdyukov
7+
*/
8+
@SpringBootApplication
9+
class LiquibaseApplication
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
package tech.ydb.liquibase.model
2+
3+
import jakarta.persistence.Column
4+
import jakarta.persistence.Entity
5+
import jakarta.persistence.Id
6+
import jakarta.persistence.Table
7+
import java.time.LocalDate
8+
import java.time.LocalDateTime
9+
10+
@Entity
11+
@Table(name = "employee")
12+
data class Employee(
13+
@Id
14+
val id: Long,
15+
16+
@Column(name = "full_name")
17+
val fullName: String,
18+
19+
@Column
20+
val email: String,
21+
22+
@Column(name = "hire_date")
23+
val hireDate: LocalDate,
24+
25+
@Column
26+
val salary: java.math.BigDecimal,
27+
28+
@Column(name = "is_active")
29+
val isActive: Boolean,
30+
31+
@Column
32+
val department: String,
33+
34+
@Column
35+
val age: Int,
36+
)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
package tech.ydb.liquibase.repository
2+
3+
import org.springframework.data.repository.CrudRepository
4+
import tech.ydb.liquibase.model.Employee
5+
6+
interface EmployeeRepository : CrudRepository<Employee, Long>
7+
8+
fun EmployeeRepository.findByIdOrNull(id: Long): Employee? = this.findById(id).orElse(null)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
spring.jpa.properties.hibernate.dialect=tech.ydb.hibernate.dialect.YdbDialect
2+
3+
spring.datasource.driver-class-name=tech.ydb.jdbc.YdbDriver
4+
spring.datasource.url=jdbc:ydb:grpc://localhost:2136/local
5+
6+
spring.liquibase.change-log=classpath:changelog.yaml
7+
8+
logging.level.liquibase=DEBUG
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
databaseChangeLog:
2+
- changeSet:
3+
id: "employee"
4+
author: "kurdyukov-kir"
5+
changes:
6+
- createTable:
7+
tableName: employee
8+
columns:
9+
- column:
10+
name: id
11+
type: bigint
12+
constraints:
13+
primaryKey: true
14+
nullable: false
15+
- column:
16+
name: full_name
17+
type: varchar
18+
- column:
19+
name: email
20+
type: varchar
21+
- column:
22+
name: hire_date
23+
type: date
24+
- column:
25+
name: salary
26+
type: decimal(22,9)
27+
- column:
28+
name: is_active
29+
type: boolean
30+
- column:
31+
name: department
32+
type: varchar
33+
- column:
34+
name: age
35+
type: int
36+
- column:
37+
name: limit_date_password
38+
type: datetime
39+
- createIndex:
40+
indexName: idx_employee_email
41+
tableName: employee
42+
unique: false
43+
columns:
44+
- column:
45+
name: email

0 commit comments

Comments
 (0)