Skip to content

Commit 5723d9d

Browse files
committed
replace uuid id to Int64
1 parent 6514f75 commit 5723d9d

File tree

30 files changed

+210
-197
lines changed

30 files changed

+210
-197
lines changed

dev-1/lesson-3.1/java/src/main/java/tech/ydb/app/Issue.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,5 @@
66
/**
77
* @author Kirill Kurdyukov
88
*/
9-
public record Issue(UUID id, String title, Instant now) {
9+
public record Issue(long id, String title, Instant now) {
1010
}

dev-1/lesson-3.1/java/src/main/java/tech/ydb/app/IssueYdbRepository.java

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
import java.util.ArrayList;
55
import java.util.List;
66
import java.util.UUID;
7+
import java.util.concurrent.ThreadLocalRandom;
8+
79
import tech.ydb.common.transaction.TxMode;
810
import tech.ydb.query.tools.QueryReader;
911
import tech.ydb.query.tools.SessionRetryContext;
@@ -21,21 +23,21 @@ public IssueYdbRepository(SessionRetryContext retryCtx) {
2123
}
2224

2325
public Issue addIssue(String title) {
24-
var id = UUID.randomUUID();
26+
var id = ThreadLocalRandom.current().nextLong();
2527
var now = Instant.now();
2628

2729
retryCtx.supplyResult(
2830
session -> session.createQuery(
2931
"""
30-
DECLARE $id AS UUID;
32+
DECLARE $id AS Int64;
3133
DECLARE $title AS Text;
3234
DECLARE $created_at AS Timestamp;
3335
UPSERT INTO issues (id, title, created_at)
3436
VALUES ($id, $title, $created_at);
3537
""",
3638
TxMode.SERIALIZABLE_RW,
3739
Params.of(
38-
"$id", PrimitiveValue.newUuid(id),
40+
"$id", PrimitiveValue.newInt64(id),
3941
"$title", PrimitiveValue.newText(title),
4042
"$created_at", PrimitiveValue.newTimestamp(now)
4143
)
@@ -57,7 +59,7 @@ public List<Issue> findAll() {
5759

5860
while (resultSetReader.next()) {
5961
titles.add(new Issue(
60-
resultSetReader.getColumn(0).getUuid(),
62+
resultSetReader.getColumn(0).getInt64(),
6163
resultSetReader.getColumn(1).getText(),
6264
resultSetReader.getColumn(2).getTimestamp()
6365
));

dev-1/lesson-3.1/java/src/main/java/tech/ydb/app/SchemaYdbRepository.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ public void createSchema() {
1919
session -> session.createQuery(
2020
"""
2121
CREATE TABLE issues (
22-
id UUID NOT NULL,
22+
id Int64 NOT NULL,
2323
title Text NOT NULL,
2424
created_at Timestamp NOT NULL,
2525
PRIMARY KEY (id)

dev-1/lesson-4.1/java/src/main/java/tech/ydb/app/Issue.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,5 @@
66
/**
77
* @author Kirill Kurdyukov
88
*/
9-
public record Issue(UUID id, String title, Instant now, String author, long linkCounts) {
9+
public record Issue(long id, String title, Instant now, String author, long linkCounts) {
1010
}

dev-1/lesson-4.1/java/src/main/java/tech/ydb/app/IssueLinkCount.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,5 @@
55
/**
66
* @author Kirill Kurdyukov
77
*/
8-
public record IssueLinkCount(UUID id, long linkCount) {
8+
public record IssueLinkCount(long id, long linkCount) {
99
}

dev-1/lesson-4.1/java/src/main/java/tech/ydb/app/IssueYdbRepository.java

Lines changed: 21 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
import java.util.List;
66
import java.util.UUID;
77
import java.util.concurrent.CompletableFuture;
8+
import java.util.concurrent.ThreadLocalRandom;
9+
810
import tech.ydb.common.transaction.TxMode;
911
import tech.ydb.core.Result;
1012
import tech.ydb.query.tools.QueryReader;
@@ -22,12 +24,12 @@ public IssueYdbRepository(SessionRetryContext retryCtx) {
2224
this.retryCtx = retryCtx;
2325
}
2426

25-
public List<IssueLinkCount> linkTicketsNoInteractive(UUID idT1, UUID idT2) {
27+
public List<IssueLinkCount> linkTicketsNoInteractive(long idT1, long idT2) {
2628
var valueReader = retryCtx.supplyResult(
2729
session -> QueryReader.readFrom(session.createQuery(
2830
"""
29-
DECLARE $t1 AS UUID;
30-
DECLARE $t2 AS UUID;
31+
DECLARE $t1 AS Int64;
32+
DECLARE $t2 AS Int64;
3133
3234
UPDATE issues
3335
SET link_count = COALESCE(link_count, 0) + 1
@@ -40,48 +42,48 @@ INSERT INTO links (source, destination)
4042
WHERE id IN ($t1, $t2)
4143
""",
4244
TxMode.SERIALIZABLE_RW,
43-
Params.of("$t1", PrimitiveValue.newUuid(idT1), "$t2", PrimitiveValue.newUuid(idT2))
45+
Params.of("$t1", PrimitiveValue.newInt64(idT1), "$t2", PrimitiveValue.newInt64(idT2))
4446
))
4547
).join().getValue();
4648

4749
return getLinkTicketPairs(valueReader);
4850
}
4951

50-
public List<IssueLinkCount> linkTicketsInteractive(UUID idT1, UUID idT2) {
52+
public List<IssueLinkCount> linkTicketsInteractive(long idT1, long idT2) {
5153
return retryCtx.supplyResult(
5254
session -> {
5355
var tx = session.createNewTransaction(TxMode.SERIALIZABLE_RW);
5456

5557
tx.createQuery("""
56-
DECLARE $t1 AS UUID;
57-
DECLARE $t2 AS UUID;
58+
DECLARE $t1 AS Int64;
59+
DECLARE $t2 AS Int64;
5860
5961
UPDATE issues
6062
SET link_count = COALESCE(link_count, 0) + 1
6163
WHERE id IN ($t1, $t2);
6264
""",
63-
Params.of("$t1", PrimitiveValue.newUuid(idT1), "$t2", PrimitiveValue.newUuid(idT2))
65+
Params.of("$t1", PrimitiveValue.newInt64(idT1), "$t2", PrimitiveValue.newInt64(idT2))
6466
).execute().join().getStatus().expectSuccess();
6567

6668
tx.createQuery("""
67-
DECLARE $t1 AS UUID;
68-
DECLARE $t2 AS UUID;
69+
DECLARE $t1 AS Int64;
70+
DECLARE $t2 AS Int64;
6971
7072
INSERT INTO links (source, destination)
7173
VALUES ($t1, $t2), ($t2, $t1);
7274
""",
73-
Params.of("$t1", PrimitiveValue.newUuid(idT1), "$t2", PrimitiveValue.newUuid(idT2))
75+
Params.of("$t1", PrimitiveValue.newInt64(idT1), "$t2", PrimitiveValue.newInt64(idT2))
7476
).execute().join().getStatus().expectSuccess();
7577

7678
var valueReader = QueryReader.readFrom(
7779
tx.createQueryWithCommit("""
78-
DECLARE $t1 AS UUID;
79-
DECLARE $t2 AS UUID;
80+
DECLARE $t1 AS Int64;
81+
DECLARE $t2 AS Int64;
8082
8183
SELECT id, link_count FROM issues
8284
WHERE id IN ($t1, $t2)
8385
""",
84-
Params.of("$t1", PrimitiveValue.newUuid(idT1), "$t2", PrimitiveValue.newUuid(idT2)))
86+
Params.of("$t1", PrimitiveValue.newInt64(idT1), "$t2", PrimitiveValue.newInt64(idT2)))
8587
).join().getValue();
8688

8789
var linkTicketPairs = getLinkTicketPairs(valueReader);
@@ -92,13 +94,13 @@ WHERE id IN ($t1, $t2)
9294
}
9395

9496
public void addIssue(String title, String author) {
95-
var id = UUID.randomUUID();
97+
var id = ThreadLocalRandom.current().nextLong();
9698
var now = Instant.now();
9799

98100
retryCtx.supplyResult(
99101
session -> session.createQuery(
100102
"""
101-
DECLARE $id AS UUID;
103+
DECLARE $id AS Int64;
102104
DECLARE $title AS Text;
103105
DECLARE $created_at AS Timestamp;
104106
DECLARE $author AS Text;
@@ -107,7 +109,7 @@ UPSERT INTO issues (id, title, created_at, author)
107109
""",
108110
TxMode.SERIALIZABLE_RW,
109111
Params.of(
110-
"$id", PrimitiveValue.newUuid(id),
112+
"$id", PrimitiveValue.newInt64(id),
111113
"$title", PrimitiveValue.newText(title),
112114
"$created_at", PrimitiveValue.newTimestamp(now),
113115
"$author", PrimitiveValue.newText(author)
@@ -128,7 +130,7 @@ public List<Issue> findAll() {
128130

129131
while (resultSetReader.next()) {
130132
titles.add(new Issue(
131-
resultSetReader.getColumn(0).getUuid(),
133+
resultSetReader.getColumn(0).getInt64(),
132134
resultSetReader.getColumn(1).getText(),
133135
resultSetReader.getColumn(2).getTimestamp(),
134136
resultSetReader.getColumn(3).getText(),
@@ -145,7 +147,7 @@ private static List<IssueLinkCount> getLinkTicketPairs(QueryReader valueReader)
145147

146148
while (resultSet.next()) {
147149
linkTicketPairs.add(
148-
new IssueLinkCount(resultSet.getColumn(0).getUuid(), resultSet.getColumn(1).getInt64())
150+
new IssueLinkCount(resultSet.getColumn(0).getInt64(), resultSet.getColumn(1).getInt64())
149151
);
150152
}
151153
return linkTicketPairs;

dev-1/lesson-4.1/java/src/main/java/tech/ydb/app/SchemaYdbRepository.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ public void createSchema() {
1919
session -> session.createQuery(
2020
"""
2121
CREATE TABLE issues (
22-
id UUID NOT NULL,
22+
id Int64 NOT NULL,
2323
title Text NOT NULL,
2424
created_at Timestamp NOT NULL,
2525
author Text,
@@ -34,8 +34,8 @@ PRIMARY KEY (id)
3434
"""
3535
ALTER TABLE issues ADD COLUMN link_count Int64;
3636
CREATE TABLE links (
37-
source UUID NOT NULL,
38-
destination UUID NOT NULL,
37+
source Int64 NOT NULL,
38+
destination Int64 NOT NULL,
3939
PRIMARY KEY(source, destination)
4040
);
4141
""", TxMode.NONE

dev-1/lesson-5.1/java/src/main/java/tech/ydb/app/Issue.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,5 @@
66
/**
77
* @author Kirill Kurdyukov
88
*/
9-
public record Issue(UUID id, String title, Instant now, String author, long linkCounts) {
9+
public record Issue(long id, String title, Instant now, String author, long linkCounts) {
1010
}

dev-1/lesson-5.1/java/src/main/java/tech/ydb/app/IssueLinkCount.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,5 @@
55
/**
66
* @author Kirill Kurdyukov
77
*/
8-
public record IssueLinkCount(UUID id, long linkCount) {
8+
public record IssueLinkCount(long id, long linkCount) {
99
}

dev-1/lesson-5.1/java/src/main/java/tech/ydb/app/IssueYdbRepository.java

Lines changed: 22 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
import java.util.List;
66
import java.util.UUID;
77
import java.util.concurrent.CompletableFuture;
8+
import java.util.concurrent.ThreadLocalRandom;
9+
810
import tech.ydb.common.transaction.TxMode;
911
import tech.ydb.core.Result;
1012
import tech.ydb.query.tools.QueryReader;
@@ -22,12 +24,12 @@ public IssueYdbRepository(SessionRetryContext retryCtx) {
2224
this.retryCtx = retryCtx;
2325
}
2426

25-
public List<IssueLinkCount> linkTicketsNoInteractive(UUID idT1, UUID idT2) {
27+
public List<IssueLinkCount> linkTicketsNoInteractive(long idT1, long idT2) {
2628
var valueReader = retryCtx.supplyResult(
2729
session -> QueryReader.readFrom(session.createQuery(
2830
"""
29-
DECLARE $t1 AS UUID;
30-
DECLARE $t2 AS UUID;
31+
DECLARE $t1 AS Int64;
32+
DECLARE $t2 AS Int64;
3133
3234
UPDATE issues
3335
SET link_count = COALESCE(link_count, 0) + 1
@@ -40,48 +42,48 @@ INSERT INTO links (source, destination)
4042
WHERE id IN ($t1, $t2)
4143
""",
4244
TxMode.SERIALIZABLE_RW,
43-
Params.of("$t1", PrimitiveValue.newUuid(idT1), "$t2", PrimitiveValue.newUuid(idT2))
45+
Params.of("$t1", PrimitiveValue.newInt64(idT1), "$t2", PrimitiveValue.newInt64(idT2))
4446
))
4547
).join().getValue();
4648

4749
return getLinkTicketPairs(valueReader);
4850
}
4951

50-
public List<IssueLinkCount> linkTicketsInteractive(UUID idT1, UUID idT2) {
52+
public List<IssueLinkCount> linkTicketsInteractive(long idT1, long idT2) {
5153
return retryCtx.supplyResult(
5254
session -> {
5355
var tx = session.createNewTransaction(TxMode.SERIALIZABLE_RW);
5456

5557
tx.createQuery("""
56-
DECLARE $t1 AS UUID;
57-
DECLARE $t2 AS UUID;
58+
DECLARE $t1 AS Int64;
59+
DECLARE $t2 AS Int64;
5860
5961
UPDATE issues
6062
SET link_count = COALESCE(link_count, 0) + 1
6163
WHERE id IN ($t1, $t2);
6264
""",
63-
Params.of("$t1", PrimitiveValue.newUuid(idT1), "$t2", PrimitiveValue.newUuid(idT2))
65+
Params.of("$t1", PrimitiveValue.newInt64(idT1), "$t2", PrimitiveValue.newInt64(idT2))
6466
).execute().join().getStatus().expectSuccess();
6567

6668
tx.createQuery("""
67-
DECLARE $t1 AS UUID;
68-
DECLARE $t2 AS UUID;
69+
DECLARE $t1 AS Int64;
70+
DECLARE $t2 AS Int64;
6971
7072
INSERT INTO links (source, destination)
7173
VALUES ($t1, $t2), ($t2, $t1);
7274
""",
73-
Params.of("$t1", PrimitiveValue.newUuid(idT1), "$t2", PrimitiveValue.newUuid(idT2))
75+
Params.of("$t1", PrimitiveValue.newInt64(idT1), "$t2", PrimitiveValue.newInt64(idT2))
7476
).execute().join().getStatus().expectSuccess();
7577

7678
var valueReader = QueryReader.readFrom(
7779
tx.createQueryWithCommit("""
78-
DECLARE $t1 AS UUID;
79-
DECLARE $t2 AS UUID;
80+
DECLARE $t1 AS Int64;
81+
DECLARE $t2 AS Int64;
8082
8183
SELECT id, link_count FROM issues
8284
WHERE id IN ($t1, $t2)
8385
""",
84-
Params.of("$t1", PrimitiveValue.newUuid(idT1), "$t2", PrimitiveValue.newUuid(idT2)))
86+
Params.of("$t1", PrimitiveValue.newInt64(idT1), "$t2", PrimitiveValue.newInt64(idT2)))
8587
).join().getValue();
8688

8789
var linkTicketPairs = getLinkTicketPairs(valueReader);
@@ -92,13 +94,13 @@ WHERE id IN ($t1, $t2)
9294
}
9395

9496
public void addIssue(String title, String author) {
95-
var id = UUID.randomUUID();
97+
var id = ThreadLocalRandom.current().nextLong();
9698
var now = Instant.now();
9799

98100
retryCtx.supplyResult(
99101
session -> session.createQuery(
100102
"""
101-
DECLARE $id AS UUID;
103+
DECLARE $id AS Int64;
102104
DECLARE $title AS Text;
103105
DECLARE $created_at AS Timestamp;
104106
DECLARE $author AS Text;
@@ -107,7 +109,7 @@ UPSERT INTO issues (id, title, created_at, author)
107109
""",
108110
TxMode.SERIALIZABLE_RW,
109111
Params.of(
110-
"$id", PrimitiveValue.newUuid(id),
112+
"$id", PrimitiveValue.newInt64(id),
111113
"$title", PrimitiveValue.newText(title),
112114
"$created_at", PrimitiveValue.newTimestamp(now),
113115
"$author", PrimitiveValue.newText(author)
@@ -128,7 +130,7 @@ public List<Issue> findAll() {
128130

129131
while (resultSetReader.next()) {
130132
titles.add(new Issue(
131-
resultSetReader.getColumn(0).getUuid(),
133+
resultSetReader.getColumn(0).getInt64(),
132134
resultSetReader.getColumn(1).getText(),
133135
resultSetReader.getColumn(2).getTimestamp(),
134136
resultSetReader.getColumn(3).getText(),
@@ -158,7 +160,7 @@ SELECT id, title, created_at, author, COALESCE(link_count, 0) FROM issues VIEW a
158160
resultSetReader.next();
159161

160162
return new Issue(
161-
resultSetReader.getColumn(0).getUuid(),
163+
resultSetReader.getColumn(0).getInt64(),
162164
resultSetReader.getColumn(1).getText(),
163165
resultSetReader.getColumn(2).getTimestamp(),
164166
resultSetReader.getColumn(3).getText(),
@@ -172,7 +174,7 @@ private static List<IssueLinkCount> getLinkTicketPairs(QueryReader valueReader)
172174

173175
while (resultSet.next()) {
174176
linkTicketPairs.add(
175-
new IssueLinkCount(resultSet.getColumn(0).getUuid(), resultSet.getColumn(1).getInt64())
177+
new IssueLinkCount(resultSet.getColumn(0).getInt64(), resultSet.getColumn(1).getInt64())
176178
);
177179
}
178180
return linkTicketPairs;

0 commit comments

Comments
 (0)