@@ -67,10 +67,10 @@ private static String nameFromResult(List<String> rowSet) {
67
67
}
68
68
69
69
private CompletionStage <Double > selectWeightFromId (Integer id ) {
70
- return getSessionFactory ().withSession (
71
- session -> session .createSelectionQuery ("SELECT weight FROM GuineaPig WHERE id = " + id , Double .class )
72
- .getResultList ()
73
- .thenApply ( CompositeIdTest ::weightFromResult )
70
+ return getSessionFactory ().withSession ( session -> session
71
+ .createSelectionQuery ( "SELECT weight FROM GuineaPig WHERE id = " + id , Double .class )
72
+ .getResultList ()
73
+ .thenApply ( CompositeIdTest ::weightFromResult )
74
74
);
75
75
}
76
76
@@ -79,93 +79,85 @@ private static Double weightFromResult(List<Double> rowSet) {
79
79
case 0 :
80
80
return null ;
81
81
case 1 :
82
- return rowSet .get (0 );
82
+ return rowSet .get ( 0 );
83
83
default :
84
- throw new AssertionError ("More than one result returned: " + rowSet .size ());
84
+ throw new AssertionError ( "More than one result returned: " + rowSet .size () );
85
85
}
86
86
}
87
87
88
88
@ Test
89
89
public void reactiveFind (VertxTestContext context ) {
90
90
final GuineaPig expectedPig = new GuineaPig ( 5 , "Aloi" );
91
- test (
92
- context ,
93
- populateDB ()
94
- .thenCompose ( v -> openSession () )
95
- .thenCompose ( session -> session .find ( GuineaPig .class , new Pig (5 , "Aloi" ) ) )
96
- .thenAccept ( actualPig -> assertThatPigsAreEqual ( context , expectedPig , actualPig ) )
91
+ test ( context , populateDB ()
92
+ .thenCompose ( v -> openSession () )
93
+ .thenCompose ( session -> session .find ( GuineaPig .class , new Pig ( 5 , "Aloi" ) ) )
94
+ .thenAccept ( actualPig -> assertThatPigsAreEqual ( context , expectedPig , actualPig ) )
97
95
);
98
96
}
99
97
100
98
@ Test
101
99
public void reactivePersist (VertxTestContext context ) {
102
- test (
103
- context ,
104
- openSession ()
105
- .thenCompose ( s -> s .persist ( new GuineaPig ( 10 , "Tulip" ) )
106
- .thenCompose ( v -> s .flush () )
107
- )
108
- .thenCompose ( v -> selectNameFromId ( 10 ) )
109
- .thenAccept ( selectRes -> assertEquals ( "Tulip" , selectRes ) )
100
+ test ( context , openSession ()
101
+ .thenCompose ( s -> s
102
+ .persist ( new GuineaPig ( 10 , "Tulip" ) )
103
+ .thenCompose ( v -> s .flush () )
104
+ )
105
+ .thenCompose ( v -> selectNameFromId ( 10 ) )
106
+ .thenAccept ( selectRes -> assertEquals ( "Tulip" , selectRes ) )
110
107
);
111
108
}
112
109
113
110
@ Test
114
111
public void reactiveRemoveTransientEntity (VertxTestContext context ) {
115
- test (
116
- context ,
117
- populateDB ()
118
- .thenCompose ( v -> selectNameFromId ( 5 ) )
119
- .thenAccept ( Assertions ::assertNotNull )
120
- .thenCompose ( v -> openSession () )
121
- .thenCompose ( session -> session .remove ( new GuineaPig ( 5 , "Aloi" ) )
122
- .thenCompose ( v -> session .flush () )
123
- .thenCompose ( v -> session .close () )
124
- )
125
- .thenCompose ( v -> selectNameFromId ( 5 ) )
126
- .thenAccept ( Assertions ::assertNull )
127
- .handle ( (r , e ) -> {
128
- assertNotNull ( e );
129
- return r ;
130
- } )
112
+ test ( context , populateDB ()
113
+ .thenCompose ( v -> selectNameFromId ( 5 ) )
114
+ .thenAccept ( Assertions ::assertNotNull )
115
+ .thenCompose ( v -> openSession () )
116
+ .thenCompose ( session -> session
117
+ .remove ( new GuineaPig ( 5 , "Aloi" ) )
118
+ .thenCompose ( v -> session .flush () )
119
+ .thenCompose ( v -> session .close () )
120
+ )
121
+ .thenCompose ( v -> selectNameFromId ( 5 ) )
122
+ .thenAccept ( Assertions ::assertNull )
123
+ .handle ( (r , e ) -> {
124
+ assertNotNull ( e );
125
+ return r ;
126
+ } )
131
127
);
132
128
}
133
129
134
130
@ Test
135
131
public void reactiveRemoveManagedEntity (VertxTestContext context ) {
136
- test (
137
- context ,
138
- populateDB ()
139
- .thenCompose ( v -> openSession () )
140
- .thenCompose ( session ->
141
- session .find ( GuineaPig .class , new Pig (5 , "Aloi" ) )
142
- .thenCompose ( session ::remove )
143
- .thenCompose ( v -> session .flush () )
144
- .thenCompose ( v -> selectNameFromId ( session ,5 ) )
145
- .thenAccept ( Assertions ::assertNull )
146
- )
132
+ test ( context , populateDB ()
133
+ .thenCompose ( v -> openSession () )
134
+ .thenCompose ( session -> session
135
+ .find ( GuineaPig .class , new Pig ( 5 , "Aloi" ) )
136
+ .thenCompose ( session ::remove )
137
+ .thenCompose ( v -> session .flush () )
138
+ .thenCompose ( v -> selectNameFromId ( session , 5 ) )
139
+ .thenAccept ( Assertions ::assertNull )
140
+ )
147
141
);
148
142
}
149
143
150
144
@ Test
151
145
public void reactiveUpdate (VertxTestContext context ) {
152
146
final double NEW_WEIGHT = 200.0 ;
153
- test (
154
- context ,
155
- populateDB ()
156
- .thenCompose ( v -> openSession () )
157
- .thenCompose ( session ->
158
- session .find ( GuineaPig .class , new Pig (5 , "Aloi" ) )
159
- .thenAccept ( pig -> {
160
- assertNotNull ( pig );
161
- // Checking we are actually changing the name
162
- assertNotEquals ( pig .getWeight (), NEW_WEIGHT );
163
- pig .setWeight ( NEW_WEIGHT );
164
- } )
165
- .thenCompose ( v -> session .flush () )
166
- .thenCompose ( v -> session .close () )
167
- .thenCompose ( v -> selectWeightFromId ( 5 ) )
168
- .thenAccept ( w -> assertEquals ( NEW_WEIGHT , w ) ) )
147
+ test ( context , populateDB ()
148
+ .thenCompose ( v -> openSession () )
149
+ .thenCompose ( session -> session
150
+ .find ( GuineaPig .class , new Pig ( 5 , "Aloi" ) )
151
+ .thenAccept ( pig -> {
152
+ assertNotNull ( pig );
153
+ // Checking we are actually changing the name
154
+ assertNotEquals ( pig .getWeight (), NEW_WEIGHT );
155
+ pig .setWeight ( NEW_WEIGHT );
156
+ } )
157
+ .thenCompose ( v -> session .flush () )
158
+ .thenCompose ( v -> session .close () )
159
+ .thenCompose ( v -> selectWeightFromId ( 5 ) )
160
+ .thenAccept ( w -> assertEquals ( NEW_WEIGHT , w ) ) )
169
161
);
170
162
}
171
163
@@ -185,7 +177,8 @@ public Pig(Integer id, String name) {
185
177
this .name = name ;
186
178
}
187
179
188
- Pig () {}
180
+ Pig () {
181
+ }
189
182
190
183
public Integer getId () {
191
184
return id ;
@@ -197,25 +190,31 @@ public String getName() {
197
190
198
191
@ Override
199
192
public boolean equals (Object o ) {
200
- if (this == o ) return true ;
201
- if (o == null || getClass () != o .getClass ()) return false ;
193
+ if ( this == o ) {
194
+ return true ;
195
+ }
196
+ if ( o == null || getClass () != o .getClass () ) {
197
+ return false ;
198
+ }
202
199
Pig pig = (Pig ) o ;
203
- return id .equals (pig .id ) &&
204
- name .equals (pig .name );
200
+ return id .equals ( pig .id ) &&
201
+ name .equals ( pig .name );
205
202
}
206
203
207
204
@ Override
208
205
public int hashCode () {
209
- return Objects .hash (id , name );
206
+ return Objects .hash ( id , name );
210
207
}
211
208
}
212
209
213
- @ Entity (name = "GuineaPig" )
214
- @ Table (name = "Pig" )
210
+ @ Entity (name = "GuineaPig" )
211
+ @ Table (name = "Pig" )
215
212
@ IdClass (Pig .class )
216
213
public static class GuineaPig implements Serializable {
217
- @ Id private Integer id ;
218
- @ Id private String name ;
214
+ @ Id
215
+ private Integer id ;
216
+ @ Id
217
+ private String name ;
219
218
220
219
private double weight = 100.0 ;
221
220
0 commit comments