Skip to content

Commit 3419f8f

Browse files
cigalybeikov
authored andcommitted
HHH-18377 Renamed State record properties with addres 'last' prefix
1 parent 6daec2e commit 3419f8f

File tree

2 files changed

+16
-16
lines changed

2 files changed

+16
-16
lines changed

hibernate-core/src/main/java/org/hibernate/id/uuid/UuidVersion6Strategy.java

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -42,23 +42,23 @@ private static class Holder {
4242

4343
}
4444

45-
private record State(long timestamp, int sequence) {
45+
private record State(long lastTimestamp, int lastSequence) {
4646
public State getNextState() {
4747
final long now = instantToTimestamp();
48-
if ( this.timestamp < now ) {
48+
if ( this.lastTimestamp < now ) {
4949
return new State(
5050
now,
5151
randomSequence()
5252
);
5353
}
54-
else if ( sequence == 0x3FFF ) {
54+
else if ( lastSequence == 0x3FFF ) {
5555
return new State(
56-
this.timestamp + 1,
56+
this.lastTimestamp + 1,
5757
randomSequence()
5858
);
5959
}
6060
else {
61-
return new State( timestamp, sequence + 1 );
61+
return new State( lastTimestamp, lastSequence + 1 );
6262
}
6363
}
6464

@@ -104,15 +104,15 @@ public UUID generateUuid(final SharedSessionContractImplementor session) {
104104

105105
return new UUID(
106106
// MSB bits 0-47 - most significant 32 bits of the 60-bit starting timestamp
107-
state.timestamp << 4 & 0xFFFF_FFFF_FFFF_0000L
107+
state.lastTimestamp << 4 & 0xFFFF_FFFF_FFFF_0000L
108108
// MSB bits 48-51 - version = 6
109109
| 0x6000L
110110
// MSB bits 52-63 - least significant 12 bits from the 60-bit starting timestamp
111-
| state.timestamp & 0x0FFFL,
111+
| state.lastTimestamp & 0x0FFFL,
112112
// LSB bits 0-1 - variant = 4
113113
0x8000_0000_0000_0000L
114114
// LSB bits 2-15 - clock sequence
115-
| ( state.sequence & 0x3FFFL ) << 48
115+
| ( state.lastSequence & 0x3FFFL ) << 48
116116
// LSB bits 16-63 - pseudorandom data, least significant bit of the first octet is set to 1
117117
| randomNode()
118118
);

hibernate-core/src/main/java/org/hibernate/id/uuid/UuidVersion7Strategy.java

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -44,31 +44,31 @@ private static class Holder {
4444

4545
}
4646

47-
public record State(Instant timestamp, int sequence) {
47+
public record State(Instant lastTimestamp, int lastSequence) {
4848
public long millis() {
49-
return timestamp.toEpochMilli();
49+
return lastTimestamp.toEpochMilli();
5050
}
5151

5252
public long nanos() {
53-
return (long) ( ( timestamp.getNano() % 1_000_000L ) * 0.004096 );
53+
return (long) ( ( lastTimestamp.getNano() % 1_000_000L ) * 0.004096 );
5454
}
5555

5656
public State getNextState() {
5757
final Instant now = Instant.now();
58-
if ( timestamp.toEpochMilli() < now.toEpochMilli() ) {
58+
if ( lastTimestamp.toEpochMilli() < now.toEpochMilli() ) {
5959
return new State(
6060
now.truncatedTo( MILLIS ),
6161
randomSequence()
6262
);
6363
}
64-
else if ( sequence == 0x3FFF ) {
64+
else if ( lastSequence == 0x3FFF ) {
6565
return new State(
66-
timestamp.plusMillis( 1 ),
66+
lastTimestamp.plusMillis( 1 ),
6767
Holder.numberGenerator.nextInt( 1 << 14 )
6868
);
6969
}
7070
else {
71-
return new State( timestamp, sequence + 1 );
71+
return new State( lastTimestamp, lastSequence + 1 );
7272
}
7373
}
7474

@@ -116,7 +116,7 @@ public UUID generateUuid(final SharedSessionContractImplementor session) {
116116
// LSB bits 0-1 - variant = 4
117117
0x8000_0000_0000_0000L
118118
// LSB bits 2-15 - counter
119-
| ( state.sequence & 0x3FFFL ) << 48
119+
| ( state.lastSequence & 0x3FFFL ) << 48
120120
// LSB bits 16-63 - pseudorandom data
121121
| randomNode()
122122
);

0 commit comments

Comments
 (0)