6
6
package org .hibernate .reactive ;
7
7
8
8
import java .util .Collection ;
9
+ import java .util .EnumSet ;
9
10
import java .util .List ;
10
11
import java .util .Objects ;
11
12
import java .util .Properties ;
12
13
import java .util .concurrent .CompletionStage ;
13
14
15
+ import org .hibernate .MappingException ;
14
16
import org .hibernate .annotations .GenericGenerator ;
15
17
import org .hibernate .annotations .Parameter ;
18
+ import org .hibernate .generator .EventType ;
19
+ import org .hibernate .generator .GeneratorCreationContext ;
16
20
import org .hibernate .id .Configurable ;
17
21
import org .hibernate .reactive .id .ReactiveIdentifierGenerator ;
18
22
import org .hibernate .reactive .session .ReactiveConnectionSupplier ;
19
- import org .hibernate .service .ServiceRegistry ;
20
- import org .hibernate .type .Type ;
21
23
22
24
import org .junit .jupiter .api .Test ;
23
25
@@ -44,36 +46,33 @@ protected Collection<Class<?>> annotatedEntities() {
44
46
45
47
@ Test
46
48
public void testSequenceGenerator (VertxTestContext context ) {
47
-
48
49
CustomId b = new CustomId ();
49
50
b .string = "Hello World" ;
50
51
51
- test (
52
- context ,
53
- openSession ()
54
- .thenCompose ( s -> s .persist ( b ).thenCompose ( v -> s .flush () ) )
55
- .thenCompose ( v -> openSession () )
56
- .thenCompose ( s2 -> s2
57
- .find ( CustomId .class , b .getId () )
58
- .thenAccept ( bb -> {
59
- assertNotNull ( bb );
60
- assertEquals ( bb .id , 1100 );
61
- assertEquals ( bb .string , b .string );
62
- assertEquals ( bb .version , 0 );
63
-
64
- bb .string = "Goodbye" ;
65
- } )
66
- .thenCompose ( vv -> s2 .flush () )
67
- .thenCompose ( vv -> s2 .find ( CustomId .class , b .getId () ) )
68
- .thenAccept ( bt -> {
69
- assertEquals ( bt .version , 1 );
70
- } ) )
71
- .thenCompose ( v -> openSession () )
72
- .thenCompose ( s3 -> s3 .find ( CustomId .class , b .getId () ) )
52
+ test ( context , openSession ()
53
+ .thenCompose ( s -> s .persist ( b ).thenCompose ( v -> s .flush () ) )
54
+ .thenCompose ( v -> openSession () )
55
+ .thenCompose ( s2 -> s2
56
+ .find ( CustomId .class , b .getId () )
73
57
.thenAccept ( bb -> {
74
- assertEquals ( bb .version , 1 );
75
- assertEquals ( bb .string , "Goodbye" );
58
+ assertNotNull ( bb );
59
+ assertEquals ( bb .id , 1100 );
60
+ assertEquals ( bb .string , b .string );
61
+ assertEquals ( bb .version , 0 );
62
+
63
+ bb .string = "Goodbye" ;
76
64
} )
65
+ .thenCompose ( vv -> s2 .flush () )
66
+ .thenCompose ( vv -> s2 .find ( CustomId .class , b .getId () ) )
67
+ .thenAccept ( bt -> {
68
+ assertEquals ( bt .version , 1 );
69
+ } ) )
70
+ .thenCompose ( v -> openSession () )
71
+ .thenCompose ( s3 -> s3 .find ( CustomId .class , b .getId () ) )
72
+ .thenAccept ( bb -> {
73
+ assertEquals ( bb .version , 1 );
74
+ assertEquals ( bb .string , "Goodbye" );
75
+ } )
77
76
);
78
77
}
79
78
@@ -87,15 +86,25 @@ public CompletionStage<Integer> generate(ReactiveConnectionSupplier session, Obj
87
86
}
88
87
89
88
@ Override
90
- public void configure (Type type , Properties params , ServiceRegistry serviceRegistry ) {
91
- current = Integer .parseInt ( params .getProperty ( "offset" , "0" ) );
89
+ public void configure (GeneratorCreationContext creationContext , Properties parameters ) throws MappingException {
90
+ current = Integer .parseInt ( parameters .getProperty ( "offset" , "0" ) );
91
+ }
92
+
93
+ @ Override
94
+ public boolean generatedOnExecution () {
95
+ return false ;
96
+ }
97
+
98
+ @ Override
99
+ public EnumSet <EventType > getEventTypes () {
100
+ return EnumSet .of ( EventType .INSERT );
92
101
}
93
102
}
94
103
95
104
@ Entity
96
105
@ GenericGenerator (
97
106
name = "thousands" ,
98
- strategy = "org.hibernate.reactive.CustomGeneratorTest$ Thousands" ,
107
+ type = Thousands . class ,
99
108
parameters = @ Parameter (name = "offset" , value = "100" )
100
109
)
101
110
public static class CustomId {
0 commit comments