Skip to content

Commit 33c903f

Browse files
authoredSep 4, 2024··
feat: simple app spring jooq (#39)
1 parent cd26958 commit 33c903f

21 files changed

+1894
-2
lines changed
 

‎jdbc/pom.xml

+2-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
<packaging>pom</packaging>
1616

1717
<properties>
18-
<ydb.jdbc.version>2.0.7</ydb.jdbc.version>
18+
<ydb.jdbc.version>2.2.3</ydb.jdbc.version>
1919
<slf4j.version>1.7.36</slf4j.version>
2020
</properties>
2121

@@ -52,6 +52,7 @@
5252
<module>spring-liquibase-app</module>
5353
<module>shedlock</module>
5454
<module>spring-data-jdbc</module>
55+
<module>spring-jooq</module>
5556
</modules>
5657
</profile>
5758
</profiles>

‎jdbc/spring-jooq/pom.xml

+213
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,213 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<project xmlns="http://maven.apache.org/POM/4.0.0"
3+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
5+
<modelVersion>4.0.0</modelVersion>
6+
<parent>
7+
<groupId>tech.ydb.jdbc.examples</groupId>
8+
<artifactId>ydb-jdbc-examples</artifactId>
9+
<version>1.1.0-SNAPSHOT</version>
10+
</parent>
11+
12+
<groupId>ydb.tech</groupId>
13+
<artifactId>spring-jooq</artifactId>
14+
<dependencyManagement>
15+
<dependencies>
16+
<dependency>
17+
<groupId>org.springframework.boot</groupId>
18+
<artifactId>spring-boot-dependencies</artifactId>
19+
<version>3.3.3</version>
20+
<scope>import</scope>
21+
<type>pom</type>
22+
</dependency>
23+
<dependency>
24+
<groupId>org.jooq</groupId>
25+
<artifactId>jooq-parent</artifactId>
26+
<version>3.19.11</version>
27+
<type>pom</type>
28+
<scope>import</scope>
29+
</dependency>
30+
</dependencies>
31+
</dependencyManagement>
32+
<properties>
33+
<maven.compiler.release>17</maven.compiler.release>
34+
<kotlin.version>1.9.22</kotlin.version>
35+
<jooq.ydb.version>1.0.0-RC1</jooq.ydb.version>
36+
<flyway.version>10.7.1</flyway.version>
37+
</properties>
38+
<dependencies>
39+
<dependency>
40+
<groupId>org.springframework.boot</groupId>
41+
<artifactId>spring-boot-starter-jooq</artifactId>
42+
</dependency>
43+
<dependency>
44+
<groupId>org.jooq</groupId>
45+
<artifactId>jooq</artifactId>
46+
</dependency>
47+
<dependency>
48+
<groupId>org.jooq</groupId>
49+
<artifactId>jooq-meta</artifactId>
50+
</dependency>
51+
<dependency>
52+
<groupId>org.jooq</groupId>
53+
<artifactId>jooq-codegen</artifactId>
54+
</dependency>
55+
<dependency>
56+
<groupId>tech.ydb.dialects</groupId>
57+
<artifactId>jooq-ydb-dialect</artifactId>
58+
<version>${jooq.ydb.version}</version>
59+
</dependency>
60+
<dependency>
61+
<groupId>org.flywaydb</groupId>
62+
<artifactId>flyway-core</artifactId>
63+
</dependency>
64+
<dependency>
65+
<groupId>tech.ydb.dialects</groupId>
66+
<artifactId>flyway-ydb-dialect</artifactId>
67+
<version>1.0.0-RC0</version>
68+
</dependency>
69+
<dependency>
70+
<groupId>org.jetbrains.kotlin</groupId>
71+
<artifactId>kotlin-reflect</artifactId>
72+
<version>${kotlin.version}</version>
73+
</dependency>
74+
<dependency>
75+
<groupId>org.jetbrains.kotlin</groupId>
76+
<artifactId>kotlin-maven-allopen</artifactId>
77+
<version>${kotlin.version}</version>
78+
</dependency>
79+
<dependency>
80+
<groupId>org.jetbrains.kotlin</groupId>
81+
<artifactId>kotlin-stdlib</artifactId>
82+
<version>${kotlin.version}</version>
83+
</dependency>
84+
<dependency>
85+
<groupId>tech.ydb.jdbc</groupId>
86+
<artifactId>ydb-jdbc-driver</artifactId>
87+
</dependency>
88+
89+
<dependency>
90+
<groupId>org.springframework.boot</groupId>
91+
<artifactId>spring-boot-starter-test</artifactId>
92+
<scope>test</scope>
93+
</dependency>
94+
<dependency>
95+
<groupId>tech.ydb.test</groupId>
96+
<artifactId>ydb-junit5-support</artifactId>
97+
<scope>test</scope>
98+
</dependency>
99+
</dependencies>
100+
<build>
101+
<testSourceDirectory>${project.basedir}/src/test/kotlin</testSourceDirectory>
102+
<plugins>
103+
<plugin>
104+
<groupId>org.apache.maven.plugins</groupId>
105+
<artifactId>maven-surefire-plugin</artifactId>
106+
<configuration>
107+
<environmentVariables>
108+
<TESTCONTAINERS_REUSE_ENABLE>true</TESTCONTAINERS_REUSE_ENABLE>
109+
</environmentVariables>
110+
</configuration>
111+
</plugin>
112+
<plugin>
113+
<groupId>org.springframework.boot</groupId>
114+
<artifactId>spring-boot-maven-plugin</artifactId>
115+
</plugin>
116+
<!-- <plugin>-->
117+
<!-- <groupId>org.jooq</groupId>-->
118+
<!-- <artifactId>jooq-codegen-maven</artifactId>-->
119+
<!-- <version>3.19.11</version>-->
120+
<!-- <executions>-->
121+
<!-- <execution>-->
122+
<!-- <goals>-->
123+
<!-- <goal>generate</goal>-->
124+
<!-- </goals>-->
125+
<!-- </execution>-->
126+
<!-- </executions>-->
127+
<!-- <dependencies>-->
128+
<!-- <dependency>-->
129+
<!-- <groupId>tech.ydb.jdbc</groupId>-->
130+
<!-- <artifactId>ydb-jdbc-driver-shaded</artifactId>-->
131+
<!-- <version>${ydb.jdbc.version}</version>-->
132+
<!-- </dependency>-->
133+
<!-- <dependency>-->
134+
<!-- <groupId>tech.ydb.dialects</groupId>-->
135+
<!-- <artifactId>jooq-ydb-dialect</artifactId>-->
136+
<!-- <version>${jooq.ydb.version}</version>-->
137+
<!-- </dependency>-->
138+
<!-- </dependencies>-->
139+
<!-- <configuration>-->
140+
<!-- <jdbc>-->
141+
<!-- <driver>tech.ydb.jdbc.YdbDriver</driver>-->
142+
<!-- <url>jdbc:ydb:grpc://localhost:2136/local</url>-->
143+
<!-- </jdbc>-->
144+
145+
<!-- <generator>-->
146+
<!-- <name>org.jooq.codegen.JavaGenerator</name>-->
147+
148+
<!-- <strategy>-->
149+
<!-- <name>tech.ydb.jooq.codegen.YdbGeneratorStrategy</name>-->
150+
<!-- </strategy>-->
151+
152+
<!-- <database>-->
153+
<!-- <name>tech.ydb.jooq.codegen.YdbDatabase</name>-->
154+
<!-- <includes>.*</includes>-->
155+
<!-- <excludes/>-->
156+
<!-- </database>-->
157+
158+
<!-- <target>-->
159+
<!-- <packageName>ydb</packageName>-->
160+
<!-- <directory>./src/main/java</directory>-->
161+
<!-- </target>-->
162+
<!-- </generator>-->
163+
<!-- </configuration>-->
164+
<!-- </plugin>-->
165+
<plugin>
166+
<groupId>org.jetbrains.kotlin</groupId>
167+
<artifactId>kotlin-maven-plugin</artifactId>
168+
<version>${kotlin.version}</version>
169+
<executions>
170+
<execution>
171+
<id>compile</id>
172+
<phase>compile</phase>
173+
<goals>
174+
<goal>compile</goal>
175+
</goals>
176+
<configuration>
177+
<sourceDirs>
178+
<sourceDir>${project.basedir}/src/main/kotlin</sourceDir>
179+
<sourceDir>${project.basedir}/src/main/java</sourceDir>
180+
</sourceDirs>
181+
</configuration>
182+
</execution>
183+
<execution>
184+
<id>test-compile</id>
185+
<goals>
186+
<goal>test-compile</goal>
187+
</goals>
188+
</execution>
189+
</executions>
190+
<configuration>
191+
<args>
192+
<arg>-Xjsr305=strict</arg>
193+
</args>
194+
<compilerPlugins>
195+
<plugin>spring</plugin>
196+
</compilerPlugins>
197+
</configuration>
198+
<dependencies>
199+
<dependency>
200+
<groupId>org.jetbrains.kotlin</groupId>
201+
<artifactId>kotlin-maven-allopen</artifactId>
202+
<version>${kotlin.version}</version>
203+
</dependency>
204+
<dependency>
205+
<groupId>org.jetbrains.kotlin</groupId>
206+
<artifactId>kotlin-maven-noarg</artifactId>
207+
<version>${kotlin.version}</version>
208+
</dependency>
209+
</dependencies>
210+
</plugin>
211+
</plugins>
212+
</build>
213+
</project>

‎jdbc/spring-jooq/src/main/java/ydb/DefaultCatalog.java

+56
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎jdbc/spring-jooq/src/main/java/ydb/default_schema/DefaultSchema.java

+69
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎jdbc/spring-jooq/src/main/java/ydb/default_schema/Keys.java

+34
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎jdbc/spring-jooq/src/main/java/ydb/default_schema/Tables.java

+32
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎jdbc/spring-jooq/src/main/java/ydb/default_schema/tables/Episodes.java

+241
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎jdbc/spring-jooq/src/main/java/ydb/default_schema/tables/Seasons.java

+241
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎jdbc/spring-jooq/src/main/java/ydb/default_schema/tables/Series.java

+236
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎jdbc/spring-jooq/src/main/java/ydb/default_schema/tables/records/EpisodesRecord.java

+126
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎jdbc/spring-jooq/src/main/java/ydb/default_schema/tables/records/SeasonsRecord.java

+126
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎jdbc/spring-jooq/src/main/java/ydb/default_schema/tables/records/SeriesRecord.java

+111
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
package tech.ydb.jooq
2+
3+
import org.springframework.boot.autoconfigure.SpringBootApplication
4+
5+
/**
6+
* @author Kirill Kurdyukov
7+
*/
8+
@SpringBootApplication
9+
class JooqApplication
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
package tech.ydb.jooq.configuration
2+
3+
import org.springframework.boot.autoconfigure.jooq.JooqAutoConfiguration
4+
import org.springframework.context.annotation.Configuration
5+
import tech.ydb.jooq.impl.YdbDSLContextImpl
6+
7+
/**
8+
* @author Kirill Kurdyukov
9+
*/
10+
@Configuration
11+
class YdbJooqConfiguration : JooqAutoConfiguration.DslContextConfiguration() {
12+
13+
override fun dslContext(configuration: org.jooq.Configuration): YdbDSLContextImpl {
14+
return YdbDSLContextImpl(configuration)
15+
}
16+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
package tech.ydb.jooq.repository
2+
3+
import org.jooq.impl.DSL
4+
import org.springframework.stereotype.Repository
5+
import tech.ydb.jooq.YdbDSLContext
6+
import ydb.default_schema.Tables.EPISODES
7+
import ydb.default_schema.tables.records.EpisodesRecord
8+
9+
/**
10+
* @author Kirill Kurdyukov
11+
*/
12+
@Repository
13+
class EpisodesRepository(val ydbDSLContext: YdbDSLContext) {
14+
15+
fun findAll(): Array<EpisodesRecord> = ydbDSLContext.selectFrom(EPISODES).fetchArray()
16+
17+
fun findByPk(
18+
seriesId: Long,
19+
seasonId: Long,
20+
episodesId: Long,
21+
context: YdbDSLContext = ydbDSLContext,
22+
): EpisodesRecord? = context
23+
.selectFrom(EPISODES)
24+
.where(
25+
EPISODES.SERIES_ID.eq(seriesId)
26+
.and(EPISODES.SEASON_ID.eq(seasonId))
27+
.and(EPISODES.EPISODE_ID.eq(episodesId))
28+
)
29+
.fetchOne()
30+
31+
fun selectOrderByPkAndConditional(
32+
seriesId: Long,
33+
seasonId: Long,
34+
limit: Int = 3,
35+
context: YdbDSLContext = ydbDSLContext,
36+
): Array<EpisodesRecord> = context
37+
.selectFrom(EPISODES)
38+
.where(EPISODES.SERIES_ID.eq(seriesId).and(EPISODES.SEASON_ID.greaterThan(seasonId)))
39+
.orderBy(EPISODES.SERIES_ID, EPISODES.SEASON_ID, EPISODES.EPISODE_ID)
40+
.limit(limit)
41+
.fetchArray()
42+
43+
fun aggregateCountByEpisodes(
44+
seriesId: Long,
45+
context: YdbDSLContext = ydbDSLContext,
46+
): List<Triple<Long, Long, Int>> = context
47+
.select(EPISODES.SERIES_ID, EPISODES.SEASON_ID, DSL.count().`as`("cnt"))
48+
.from(EPISODES)
49+
.where(EPISODES.SERIES_ID.eq(seriesId))
50+
.groupBy(EPISODES.SERIES_ID, EPISODES.SEASON_ID)
51+
.orderBy(EPISODES.SERIES_ID, EPISODES.SEASON_ID)
52+
.fetch { rec -> Triple(rec.value1(), rec.value2(), rec.value3()) }
53+
54+
fun replace(record: EpisodesRecord, context: YdbDSLContext = ydbDSLContext) {
55+
context.replaceInto(EPISODES)
56+
.set(record)
57+
.execute()
58+
}
59+
60+
fun upsert(record: EpisodesRecord, context: YdbDSLContext = ydbDSLContext) {
61+
context.upsertInto(EPISODES)
62+
.set(record)
63+
.execute()
64+
}
65+
66+
fun insert(record: EpisodesRecord, context: YdbDSLContext = ydbDSLContext) {
67+
context.insertInto(EPISODES)
68+
.set(record)
69+
.execute()
70+
}
71+
72+
fun update(record: EpisodesRecord, context: YdbDSLContext = ydbDSLContext) {
73+
context.update(EPISODES)
74+
.set(EPISODES.TITLE.`as`(EPISODES.TITLE), record.title)
75+
.where(
76+
EPISODES.SERIES_ID.eq(record.seriesId).and(EPISODES.SEASON_ID.eq(record.seasonId))
77+
.and(EPISODES.EPISODE_ID.eq(record.episodeId))
78+
)
79+
.execute()
80+
}
81+
82+
fun delete(seriesId: Long, seasonId: Long, episodesId: Long, context: YdbDSLContext = ydbDSLContext) {
83+
context.delete(EPISODES)
84+
.where(
85+
EPISODES.SERIES_ID.eq(seriesId).and(EPISODES.SEASON_ID.eq(seasonId))
86+
.and(EPISODES.EPISODE_ID.eq(episodesId))
87+
).execute()
88+
}
89+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
package tech.ydb.jooq.repository
2+
3+
import org.springframework.stereotype.Repository
4+
import tech.ydb.jooq.YdbDSLContext
5+
import ydb.default_schema.Tables.SEASONS
6+
import ydb.default_schema.Tables.SERIES
7+
8+
/**
9+
* @author Kirill Kurdyukov
10+
*/
11+
@Repository
12+
class SeasonsRepository(val ydbDSLContext: YdbDSLContext) {
13+
14+
fun seasonsBySeriesId(seriesId: Long, context: YdbDSLContext = ydbDSLContext): List<Pair<String, String>> = context
15+
.select(
16+
SEASONS.TITLE.`as`("seasons_title"),
17+
SERIES.TITLE.`as`("series_title"),
18+
SERIES.SERIES_ID,
19+
SEASONS.SEASON_ID
20+
)
21+
.from(SEASONS)
22+
.innerJoin(SERIES)
23+
.on(SERIES.SERIES_ID.eq(SEASONS.SERIES_ID))
24+
.where(SERIES.SERIES_ID.eq(seriesId))
25+
.orderBy(SERIES.SERIES_ID, SEASONS.SEASON_ID)
26+
.fetch { rec -> rec.value1() to rec.value2() }
27+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
spring.datasource.driver-class-name=tech.ydb.jdbc.YdbDriver
2+
spring.datasource.url=jdbc:ydb:grpc://localhost:2136/local
3+
4+
logging.level.org.jooq.tools.LoggerListener=DEBUG
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
CREATE TABLE series
2+
(
3+
series_id Int64,
4+
title Utf8,
5+
series_info Utf8,
6+
release_date Date,
7+
PRIMARY KEY (series_id)
8+
);
9+
10+
CREATE TABLE seasons
11+
(
12+
series_id Int64,
13+
season_id Int64,
14+
title Utf8,
15+
first_aired Date,
16+
last_aired Date,
17+
PRIMARY KEY (series_id, season_id)
18+
);
19+
20+
CREATE TABLE episodes
21+
(
22+
series_id Int64,
23+
season_id Int64,
24+
episode_id Int64,
25+
title Utf8,
26+
air_date Date,
27+
PRIMARY KEY (series_id, season_id, episode_id)
28+
);
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
INSERT INTO series (series_id, title, release_date, series_info)
2+
VALUES (1,
3+
"IT Crowd",
4+
Date("2006-02-03"),
5+
"The IT Crowd is a British sitcom produced by Channel 4, written by Graham Linehan, produced by Ash Atalla and starring Chris O'Dowd, Richard Ayoade, Katherine Parkinson, and Matt Berry."),
6+
(2,
7+
"Silicon Valley",
8+
Date("2014-04-06"),
9+
"Silicon Valley is an American comedy television series created by Mike Judge, John Altschuler and Dave Krinsky. The series focuses on five young men who founded a startup company in Silicon Valley.")
10+
;
11+
12+
INSERT INTO seasons (series_id, season_id, title, first_aired, last_aired)
13+
VALUES (1, 1, "Season 1", Date("2006-02-03"), Date("2006-03-03")),
14+
(1, 2, "Season 2", Date("2007-08-24"), Date("2007-09-28")),
15+
(1, 3, "Season 3", Date("2008-11-21"), Date("2008-12-26")),
16+
(1, 4, "Season 4", Date("2010-06-25"), Date("2010-07-30")),
17+
(2, 1, "Season 1", Date("2014-04-06"), Date("2014-06-01")),
18+
(2, 2, "Season 2", Date("2015-04-12"), Date("2015-06-14")),
19+
(2, 3, "Season 3", Date("2016-04-24"), Date("2016-06-26")),
20+
(2, 4, "Season 4", Date("2017-04-23"), Date("2017-06-25")),
21+
(2, 5, "Season 5", Date("2018-03-25"), Date("2018-05-13"))
22+
;
23+
24+
INSERT INTO episodes (series_id, season_id, episode_id, title, air_date)
25+
VALUES (1, 1, 1, "Yesterday's Jam", Date("2006-02-03")),
26+
(1, 1, 2, "Calamity Jen", Date("2006-02-03")),
27+
(1, 1, 3, "Fifty-Fifty", Date("2006-02-10")),
28+
(1, 1, 4, "The Red Door", Date("2006-02-17")),
29+
(1, 1, 5, "The Haunting of Bill Crouse", Date("2006-02-24")),
30+
(1, 1, 6, "Aunt Irma Visits", Date("2006-03-03")),
31+
(1, 2, 1, "The Work Outing", Date("2006-08-24")),
32+
(1, 2, 2, "Return of the Golden Child", Date("2007-08-31")),
33+
(1, 2, 3, "Moss and the German", Date("2007-09-07")),
34+
(1, 2, 4, "The Dinner Party", Date("2007-09-14")),
35+
(1, 2, 5, "Smoke and Mirrors", Date("2007-09-21")),
36+
(1, 2, 6, "Men Without Women", Date("2007-09-28")),
37+
(1, 3, 1, "From Hell", Date("2008-11-21")),
38+
(1, 3, 2, "Are We Not Men?", Date("2008-11-28")),
39+
(1, 3, 3, "Tramps Like Us", Date("2008-12-05")),
40+
(1, 3, 4, "The Speech", Date("2008-12-12")),
41+
(1, 3, 5, "Friendface", Date("2008-12-19")),
42+
(1, 3, 6, "Calendar Geeks", Date("2008-12-26")),
43+
(1, 4, 1, "Jen The Fredo", Date("2010-06-25")),
44+
(1, 4, 2, "The Final Countdown", Date("2010-07-02")),
45+
(1, 4, 3, "Something Happened", Date("2010-07-09")),
46+
(1, 4, 4, "Italian For Beginners", Date("2010-07-16")),
47+
(1, 4, 5, "Bad Boys", Date("2010-07-23")),
48+
(1, 4, 6, "Reynholm vs Reynholm", Date("2010-07-30")),
49+
(2, 1, 1, "Minimum Viable Product", Date("2014-04-06")),
50+
(2, 1, 2, "The Cap Table", Date("2014-04-13")),
51+
(2, 1, 3, "Articles of Incorporation", Date("2014-04-20")),
52+
(2, 1, 4, "Fiduciary Duties", Date("2014-04-27")),
53+
(2, 1, 5, "Signaling Risk", Date("2014-05-04")),
54+
(2, 1, 6, "Third Party Insourcing", Date("2014-05-11")),
55+
(2, 1, 7, "Proof of Concept", Date("2014-05-18")),
56+
(2, 1, 8, "Optimal Tip-to-Tip Efficiency", Date("2014-06-01")),
57+
(2, 2, 1, "Sand Hill Shuffle", Date("2015-04-12")),
58+
(2, 2, 2, "Runaway Devaluation", Date("2015-04-19")),
59+
(2, 2, 3, "Bad Money", Date("2015-04-26")),
60+
(2, 2, 4, "The Lady", Date("2015-05-03")),
61+
(2, 2, 5, "Server Space", Date("2015-05-10")),
62+
(2, 2, 6, "Homicide", Date("2015-05-17")),
63+
(2, 2, 7, "Adult Content", Date("2015-05-24")),
64+
(2, 2, 8, "White Hat/Black Hat", Date("2015-05-31")),
65+
(2, 2, 9, "Binding Arbitration", Date("2015-06-07")),
66+
(2, 2, 10, "Two Days of the Condor", Date("2015-06-14")),
67+
(2, 3, 1, "Founder Friendly", Date("2016-04-24")),
68+
(2, 3, 2, "Two in the Box", Date("2016-05-01")),
69+
(2, 3, 3, "Meinertzhagen's Haversack", Date("2016-05-08")),
70+
(2, 3, 4, "Maleant Data Systems Solutions", Date("2016-05-15")),
71+
(2, 3, 5, "The Empty Chair", Date("2016-05-22")),
72+
(2, 3, 6, "Bachmanity Insanity", Date("2016-05-29")),
73+
(2, 3, 7, "To Build a Better Beta", Date("2016-06-05")),
74+
(2, 3, 8, "Bachman's Earnings Over-Ride", Date("2016-06-12")),
75+
(2, 3, 9, "Daily Active Users", Date("2016-06-19")),
76+
(2, 3, 10, "The Uptick", Date("2016-06-26")),
77+
(2, 4, 1, "Success Failure", Date("2017-04-23")),
78+
(2, 4, 2, "Terms of Service", Date("2017-04-30")),
79+
(2, 4, 3, "Intellectual Property", Date("2017-05-07")),
80+
(2, 4, 4, "Teambuilding Exercise", Date("2017-05-14")),
81+
(2, 4, 5, "The Blood Boy", Date("2017-05-21")),
82+
(2, 4, 6, "Customer Service", Date("2017-05-28")),
83+
(2, 4, 7, "The Patent Troll", Date("2017-06-04")),
84+
(2, 4, 8, "The Keenan Vortex", Date("2017-06-11")),
85+
(2, 4, 9, "Hooli-Con", Date("2017-06-18")),
86+
(2, 4, 10, "Server Error", Date("2017-06-25")),
87+
(2, 5, 1, "Grow Fast or Die Slow", Date("2018-03-25")),
88+
(2, 5, 2, "Reorientation", Date("2018-04-01")),
89+
(2, 5, 3, "Chief Operating Officer", Date("2018-04-08")),
90+
(2, 5, 4, "Tech Evangelist", Date("2018-04-15")),
91+
(2, 5, 5, "Facial Recognition", Date("2018-04-22")),
92+
(2, 5, 6, "Artificial Emotional Intelligence", Date("2018-04-29")),
93+
(2, 5, 7, "Initial Coin Offering", Date("2018-05-06")),
94+
(2, 5, 8, "Fifty-One Percent", Date("2018-05-13"));
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,139 @@
1+
package tech.ydb.jooq
2+
3+
import org.junit.jupiter.api.Assertions.*
4+
import org.junit.jupiter.api.Test
5+
import org.junit.jupiter.api.extension.RegisterExtension
6+
import org.springframework.beans.factory.annotation.Autowired
7+
import org.springframework.boot.test.context.SpringBootTest
8+
import org.springframework.test.context.DynamicPropertyRegistry
9+
import org.springframework.test.context.DynamicPropertySource
10+
import tech.ydb.jooq.repository.EpisodesRepository
11+
import tech.ydb.jooq.repository.SeasonsRepository
12+
import tech.ydb.test.junit5.YdbHelperExtension
13+
import ydb.default_schema.tables.records.EpisodesRecord
14+
import java.time.LocalDate
15+
16+
/**
17+
* @author Kirill Kurdyukov
18+
*/
19+
@SpringBootTest
20+
class JooqTest {
21+
22+
companion object {
23+
@JvmField
24+
@RegisterExtension
25+
val ydb = YdbHelperExtension()
26+
27+
@JvmStatic
28+
@DynamicPropertySource
29+
fun propertySource(registry: DynamicPropertyRegistry) {
30+
registry.add("spring.datasource.url") {
31+
"jdbc:ydb:${if (ydb.useTls()) "grpcs://" else "grpc://"}" +
32+
"${ydb.endpoint()}${ydb.database()}${ydb.authToken()?.let { "?token=$it" } ?: ""}"
33+
}
34+
}
35+
}
36+
37+
@Autowired
38+
lateinit var episodesRepository: EpisodesRepository
39+
40+
@Autowired
41+
lateinit var seasonsRepository: SeasonsRepository
42+
43+
@Autowired
44+
lateinit var ydbDSLContext: YdbDSLContext
45+
46+
@Test
47+
fun findAllTest() {
48+
assertEquals(70, episodesRepository.findAll().size)
49+
}
50+
51+
@Test
52+
fun selectOrderByPkAndConditionalTest() {
53+
val episodes = episodesRepository.selectOrderByPkAndConditional(1, 1)
54+
55+
assertEquals("The Work Outing", episodes[0].title)
56+
assertEquals("Return of the Golden Child", episodes[1].title)
57+
assertEquals("Moss and the German", episodes[2].title)
58+
}
59+
60+
@Test
61+
fun aggregateCountByEpisodesTest() {
62+
val episodes = episodesRepository.aggregateCountByEpisodes(1)
63+
64+
assertEquals(4, episodes.size)
65+
assertEquals(Triple(1, 1, 6).toString(), episodes[0].toString())
66+
assertEquals(Triple(1, 2, 6).toString(), episodes[1].toString())
67+
assertEquals(Triple(1, 3, 6).toString(), episodes[2].toString())
68+
assertEquals(Triple(1, 4, 6).toString(), episodes[3].toString())
69+
}
70+
71+
@Test
72+
fun `replace upsert insert test`() {
73+
val episodesExpected = EpisodesRecord().apply {
74+
seriesId = 2
75+
seasonId = 5
76+
episodeId = 10
77+
title = "Test Episode !!!"
78+
airDate = LocalDate.parse("2018-08-27")
79+
}
80+
81+
val check = {
82+
val episodeActual = episodesRepository.findByPk(2, 5, 10)
83+
assertNotNull(episodeActual)
84+
85+
assertEquals(episodesExpected, episodeActual)
86+
87+
episodesRepository.delete(2, 5, 10)
88+
assertNull(episodesRepository.findByPk(2, 5, 10))
89+
}
90+
91+
episodesRepository.replace(episodesExpected)
92+
check()
93+
94+
episodesRepository.upsert(episodesExpected)
95+
check()
96+
97+
episodesRepository.insert(episodesExpected)
98+
val episodeActual = episodesRepository.findByPk(2, 5, 10)
99+
assertNotNull(episodeActual)
100+
assertEquals(episodesExpected, episodeActual)
101+
102+
episodesRepository.update(episodesExpected.apply { title = "test Episode 2" })
103+
check()
104+
}
105+
106+
@Test
107+
fun transactionTest() {
108+
val episodesExpected = EpisodesRecord().apply {
109+
seriesId = 2
110+
seasonId = 5
111+
episodeId = 10
112+
title = "Test Episode !!!"
113+
airDate = LocalDate.parse("2018-08-27")
114+
}
115+
116+
ydbDSLContext.transaction { tx ->
117+
val dsl = YDB.using(tx)
118+
119+
episodesRepository.upsert(episodesExpected, dsl)
120+
episodesRepository.update(episodesExpected.apply { title = "test Episode 2" }, dsl)
121+
}
122+
123+
val episodeActual = episodesRepository.findByPk(2, 5, 10)
124+
assertEquals(episodesExpected, episodeActual)
125+
episodesRepository.delete(2, 5, 10)
126+
assertNull(episodesRepository.findByPk(2, 5, 10))
127+
}
128+
129+
@Test
130+
fun joinText() {
131+
val titles = seasonsRepository.seasonsBySeriesId(1)
132+
133+
assertEquals(4, titles.size)
134+
for (i in 1 .. 4) {
135+
assertEquals("Season $i", titles[i - 1].first)
136+
assertEquals("IT Crowd", titles[i - 1].second)
137+
}
138+
}
139+
}

‎pom.xml

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
<log4j.version>2.22.1</log4j.version>
1919
<jcommander.version>1.82</jcommander.version>
2020

21-
<ydb.sdk.version>2.2.3</ydb.sdk.version>
21+
<ydb.sdk.version>2.2.10</ydb.sdk.version>
2222
</properties>
2323

2424
<modules>

0 commit comments

Comments
 (0)
Please sign in to comment.