質問編集履歴

1

該当のソースコードの修正。

2021/01/29 02:48

投稿

shunji2740
shunji2740

スコア4

test CHANGED
File without changes
test CHANGED
@@ -226,73 +226,115 @@
226
226
 
227
227
  ```
228
228
 
229
+ ```UserService
230
+
231
+ package mrs.domain.service.user;
232
+
233
+
234
+
235
+ import org.springframework.beans.factory.annotation.Autowired;
236
+
237
+ import org.springframework.dao.DataAccessException;
238
+
239
+ import org.springframework.stereotype.Service;
240
+
241
+
242
+
243
+ import mrs.domain.model.User;
244
+
245
+ import mrs.domain.repository.user.EditUserRepositoryJdbc;
246
+
247
+ import mrs.domain.repository.user.UserRepository;
248
+
249
+
250
+
251
+ @Service
252
+
253
+ public class UserService {
254
+
255
+
256
+
257
+ @Autowired
258
+
259
+ EditUserRepositoryJdbc userRepositoryJdbc;
260
+
261
+
262
+
263
+ @Autowired
264
+
265
+ UserRepository userRepository;
266
+
267
+
268
+
269
+ public void saveOrUpdate(User user, String userId) throws DataAccessException {
270
+
271
+ System.out.println("beforeFix: " + userId);
272
+
273
+ System.out.println("fixed: " + user.getUserId());
274
+
275
+
276
+
277
+ userRepositoryJdbc.update(user, userId);
278
+
279
+ }
280
+
281
+
282
+
283
+ public boolean checkDuplicate(String userId) {
284
+
285
+ if (userRepository.countByUserId(userId) != 0) {
286
+
287
+ return false;
288
+
289
+ }
290
+
291
+
292
+
293
+ return true;
294
+
295
+ }
296
+
297
+ }
298
+
299
+
300
+
229
301
  ```
230
302
 
303
+ ```UserRepository
304
+
231
- package mrs.domain.service.user;
305
+ package mrs.domain.repository.user;
306
+
307
+
308
+
232
-
309
+ import javax.persistence.LockModeType;
233
-
234
-
310
+
311
+
312
+
235
- import org.springframework.beans.factory.annotation.Autowired;
313
+ import org.springframework.data.jpa.repository.JpaRepository;
236
-
314
+
237
- import org.springframework.dao.DataAccessException;
315
+ import org.springframework.data.jpa.repository.Lock;
238
-
316
+
239
- import org.springframework.stereotype.Service;
317
+ import org.springframework.stereotype.Repository;
240
318
 
241
319
 
242
320
 
243
321
  import mrs.domain.model.User;
244
322
 
245
- import mrs.domain.repository.user.EditUserRepositoryJdbc;
323
+
246
-
247
- import mrs.domain.repository.user.UserRepository;
324
+
248
-
249
-
250
-
251
- @Service
252
-
253
- public class UserService {
254
-
255
-
256
-
257
- @Autowired
325
+ @Repository
258
-
259
- EditUserRepositoryJdbc userRepositoryJdbc;
326
+
260
-
261
-
262
-
263
- @Autowired
264
-
265
- UserRepository userRepository;
266
-
267
-
268
-
269
- public void saveOrUpdate(User user, String userId) throws DataAccessException {
327
+ public interface UserRepository extends JpaRepository<User, String> {
270
-
328
+
329
+
330
+
271
- System.out.println("beforeFix: " + userId);
331
+ @Lock(LockModeType.PESSIMISTIC_WRITE)
272
-
273
- System.out.println("fixed: " + user.getUserId());
332
+
274
-
275
-
276
-
277
- userRepositoryJdbc.update(user, userId);
333
+ User findOneForUpdateByUserId(String userId);
278
-
279
- }
334
+
280
-
281
-
282
-
283
- public boolean checkDuplicate(String userId) {
335
+ long countByUserId(String userId);
284
-
285
- if (userRepository.countByUserId(userId) != 0) {
336
+
286
-
287
- return false;
337
+
288
-
289
- }
290
-
291
-
292
-
293
- return true;
294
-
295
- }
296
338
 
297
339
  }
298
340
 
@@ -300,39 +342,255 @@
300
342
 
301
343
  ```
302
344
 
303
- ```UserRepository
304
-
305
- package mrs.domain.repository.user;
306
-
307
-
308
-
309
- import javax.persistence.LockModeType;
310
-
311
-
312
-
313
- import org.springframework.data.jpa.repository.JpaRepository;
314
-
315
- import org.springframework.data.jpa.repository.Lock;
316
-
317
- import org.springframework.stereotype.Repository;
318
-
319
-
320
-
321
- import mrs.domain.model.User;
322
-
323
-
324
-
325
- @Repository
326
-
327
- public interface UserRepository extends JpaRepository<User, String> {
328
-
329
-
330
-
331
- @Lock(LockModeType.PESSIMISTIC_WRITE)
332
-
333
- User findOneForUpdateByUserId(String userId);
334
-
335
- long countByUserId(String userId);
345
+ ```User
346
+
347
+ package mrs.domain.model;
348
+
349
+
350
+
351
+ import java.io.Serializable;
352
+
353
+
354
+
355
+ import javax.persistence.Entity;
356
+
357
+ import javax.persistence.Id;
358
+
359
+ import javax.persistence.Table;
360
+
361
+ import javax.validation.constraints.Email;
362
+
363
+ import javax.validation.constraints.NotBlank;
364
+
365
+ import javax.validation.constraints.Pattern;
366
+
367
+ import javax.validation.constraints.Size;
368
+
369
+
370
+
371
+ import org.hibernate.validator.constraints.Length;
372
+
373
+
374
+
375
+ import mrs.app.user.UserIdDuplicateCheck;
376
+
377
+
378
+
379
+
380
+
381
+ //会議室予約システムを利用するユーザー情報を格納するテーブル
382
+
383
+ //Userエンティティー
384
+
385
+ @Entity
386
+
387
+ @Table(name = "usr")
388
+
389
+ @UserIdDuplicateCheck(message="このユーザーIDは既に登録されています")
390
+
391
+ public class User implements Serializable {
392
+
393
+
394
+
395
+ @Id
396
+
397
+ @NotBlank(groups=ValidGroup1.class)
398
+
399
+ @Email(groups=ValidGroup2.class)
400
+
401
+ private String userId;
402
+
403
+
404
+
405
+ @NotBlank(groups=ValidGroup1.class)
406
+
407
+ @Length(min=4, max=100, groups=ValidGroup2.class)
408
+
409
+ private String password;
410
+
411
+
412
+
413
+ @NotBlank(groups=ValidGroup1.class)
414
+
415
+ private String firstName;
416
+
417
+
418
+
419
+ @NotBlank(groups=ValidGroup1.class)
420
+
421
+ private String lastName;
422
+
423
+
424
+
425
+ /**
426
+
427
+ * 電話番号
428
+
429
+ */
430
+
431
+ @NotBlank(groups=ValidGroup1.class)
432
+
433
+ @Pattern(regexp = "0\d{1,4}\d{1,4}\d{4}", groups=ValidGroup2.class)
434
+
435
+ private String phoneNumber;
436
+
437
+
438
+
439
+ @NotBlank(groups=ValidGroup1.class)
440
+
441
+ private String zipCode;
442
+
443
+
444
+
445
+ /**
446
+
447
+ * 住所
448
+
449
+ */
450
+
451
+ @NotBlank(groups=ValidGroup1.class)
452
+
453
+ @Size(max = 200, groups=ValidGroup2.class)
454
+
455
+ private String address;
456
+
457
+
458
+
459
+ //@Enumerated(EnumType.STRING)
460
+
461
+ @NotBlank(groups=ValidGroup1.class)
462
+
463
+ private String roleName;
464
+
465
+
466
+
467
+
468
+
469
+ public String getUserId() {
470
+
471
+ return userId;
472
+
473
+ }
474
+
475
+
476
+
477
+ public void setUserId(String userId) {
478
+
479
+ this.userId = userId;
480
+
481
+ }
482
+
483
+
484
+
485
+ public String getPassword() {
486
+
487
+ return password;
488
+
489
+ }
490
+
491
+
492
+
493
+ public void setPassword(String password) {
494
+
495
+ this.password = password;
496
+
497
+ }
498
+
499
+
500
+
501
+ public String getFirstName() {
502
+
503
+ return firstName;
504
+
505
+ }
506
+
507
+
508
+
509
+ public void setFirstName(String firstName) {
510
+
511
+ this.firstName = firstName;
512
+
513
+ }
514
+
515
+
516
+
517
+ public String getLastName() {
518
+
519
+ return lastName;
520
+
521
+ }
522
+
523
+
524
+
525
+ public void setLastName(String lastName) {
526
+
527
+ this.lastName = lastName;
528
+
529
+ }
530
+
531
+
532
+
533
+ public String getRoleName() {
534
+
535
+ return roleName;
536
+
537
+ }
538
+
539
+
540
+
541
+ public void setRoleName(String roleName) {
542
+
543
+ this.roleName = roleName;
544
+
545
+ }
546
+
547
+
548
+
549
+ public String getPhoneNumber() {
550
+
551
+ return phoneNumber;
552
+
553
+ }
554
+
555
+
556
+
557
+ public void setPhoneNumber(String phoneNumber) {
558
+
559
+ this.phoneNumber = phoneNumber;
560
+
561
+ }
562
+
563
+
564
+
565
+ public String getZipCode() {
566
+
567
+ return zipCode;
568
+
569
+ }
570
+
571
+
572
+
573
+ public void setZipCode(String zipCode) {
574
+
575
+ this.zipCode = zipCode;
576
+
577
+ }
578
+
579
+
580
+
581
+ public String getAddress() {
582
+
583
+ return address;
584
+
585
+ }
586
+
587
+
588
+
589
+ public void setAddress(String address) {
590
+
591
+ this.address = address;
592
+
593
+ }
336
594
 
337
595
 
338
596
 
@@ -342,264 +600,6 @@
342
600
 
343
601
  ```
344
602
 
345
- ```User
346
-
347
- package mrs.domain.model;
348
-
349
-
350
-
351
- import java.io.Serializable;
352
-
353
-
354
-
355
- import javax.persistence.Entity;
356
-
357
- import javax.persistence.Id;
358
-
359
- import javax.persistence.Table;
360
-
361
- import javax.validation.constraints.Email;
362
-
363
- import javax.validation.constraints.NotBlank;
364
-
365
- import javax.validation.constraints.Pattern;
366
-
367
- import javax.validation.constraints.Size;
368
-
369
-
370
-
371
- import org.hibernate.validator.constraints.Length;
372
-
373
-
374
-
375
- import mrs.app.user.UserIdDuplicateCheck;
376
-
377
-
378
-
379
-
380
-
381
- //会議室予約システムを利用するユーザー情報を格納するテーブル
382
-
383
- //Userエンティティー
384
-
385
- @Entity
386
-
387
- @Table(name = "usr")
388
-
389
- @UserIdDuplicateCheck(message="このユーザーIDは既に登録されています")
390
-
391
- public class User implements Serializable {
392
-
393
-
394
-
395
- @Id
396
-
397
- @NotBlank(groups=ValidGroup1.class)
398
-
399
- @Email(groups=ValidGroup2.class)
400
-
401
- private String userId;
402
-
403
-
404
-
405
- @NotBlank(groups=ValidGroup1.class)
406
-
407
- @Length(min=4, max=100, groups=ValidGroup2.class)
408
-
409
- private String password;
410
-
411
-
412
-
413
- @NotBlank(groups=ValidGroup1.class)
414
-
415
- private String firstName;
416
-
417
-
418
-
419
- @NotBlank(groups=ValidGroup1.class)
420
-
421
- private String lastName;
422
-
423
-
424
-
425
- /**
426
-
427
- * 電話番号
428
-
429
- */
430
-
431
- @NotBlank(groups=ValidGroup1.class)
432
-
433
- @Pattern(regexp = "0\d{1,4}\d{1,4}\d{4}", groups=ValidGroup2.class)
434
-
435
- private String phoneNumber;
436
-
437
-
438
-
439
- @NotBlank(groups=ValidGroup1.class)
440
-
441
- private String zipCode;
442
-
443
-
444
-
445
- /**
446
-
447
- * 住所
448
-
449
- */
450
-
451
- @NotBlank(groups=ValidGroup1.class)
452
-
453
- @Size(max = 200, groups=ValidGroup2.class)
454
-
455
- private String address;
456
-
457
-
458
-
459
- //@Enumerated(EnumType.STRING)
460
-
461
- @NotBlank(groups=ValidGroup1.class)
462
-
463
- private String roleName;
464
-
465
-
466
-
467
-
468
-
469
- public String getUserId() {
470
-
471
- return userId;
472
-
473
- }
474
-
475
-
476
-
477
- public void setUserId(String userId) {
478
-
479
- this.userId = userId;
480
-
481
- }
482
-
483
-
484
-
485
- public String getPassword() {
486
-
487
- return password;
488
-
489
- }
490
-
491
-
492
-
493
- public void setPassword(String password) {
494
-
495
- this.password = password;
496
-
497
- }
498
-
499
-
500
-
501
- public String getFirstName() {
502
-
503
- return firstName;
504
-
505
- }
506
-
507
-
508
-
509
- public void setFirstName(String firstName) {
510
-
511
- this.firstName = firstName;
512
-
513
- }
514
-
515
-
516
-
517
- public String getLastName() {
518
-
519
- return lastName;
520
-
521
- }
522
-
523
-
524
-
525
- public void setLastName(String lastName) {
526
-
527
- this.lastName = lastName;
528
-
529
- }
530
-
531
-
532
-
533
- public String getRoleName() {
534
-
535
- return roleName;
536
-
537
- }
538
-
539
-
540
-
541
- public void setRoleName(String roleName) {
542
-
543
- this.roleName = roleName;
544
-
545
- }
546
-
547
-
548
-
549
- public String getPhoneNumber() {
550
-
551
- return phoneNumber;
552
-
553
- }
554
-
555
-
556
-
557
- public void setPhoneNumber(String phoneNumber) {
558
-
559
- this.phoneNumber = phoneNumber;
560
-
561
- }
562
-
563
-
564
-
565
- public String getZipCode() {
566
-
567
- return zipCode;
568
-
569
- }
570
-
571
-
572
-
573
- public void setZipCode(String zipCode) {
574
-
575
- this.zipCode = zipCode;
576
-
577
- }
578
-
579
-
580
-
581
- public String getAddress() {
582
-
583
- return address;
584
-
585
- }
586
-
587
-
588
-
589
- public void setAddress(String address) {
590
-
591
- this.address = address;
592
-
593
- }
594
-
595
-
596
-
597
- }
598
-
599
-
600
-
601
- ```
602
-
603
603
 
604
604
 
605
605
  ### 試したこと