Skip to content

Commit b7647b4

Browse files
LEGLINK-789: Speed up Validation service result persistence (#1822)
* Add review and submit properties to validation categories. Update UI to provide access to api functions. * Update Web/Admin.UI/src/app/components/validation-config/validation-categories/validation-categories-management/validation-categories-management.component.ts Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com> * Use DB sequence for Result IDs Replaced Result identity generation with a dedicated dbo.result_sequence configured for Hibernate sequence allocation, and added batching settings for insert/update ordering. Included a migration that recreates the result and result_category tables plus sequence so the database matches the new JPA ID strategy. * Remove schema from SequenceGenerator in Result Remove the explicit schema = "dbo" from the @SequenceGenerator on Result.id. This allows JPA to use the default schema provided by the persistence setup, improving portability across database vendors and avoiding hard-coded SQL Server schema assumptions. --------- Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
1 parent da5f51e commit b7647b4

4 files changed

Lines changed: 124 additions & 1 deletion

File tree

Java/validation/src/main/java/com/lantanagroup/link/validation/entities/Result.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,8 @@ public class Result {
2727
private static final Logger logger = LoggerFactory.getLogger(Result.class);
2828

2929
@Id
30-
@GeneratedValue(strategy = GenerationType.IDENTITY)
30+
@SequenceGenerator(name = "result_seq", sequenceName = "result_sequence", allocationSize = 100)
31+
@GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "result_seq")
3132
private Long id;
3233

3334
@Column(nullable = false)

Java/validation/src/main/resources/application-docker.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,12 @@ spring:
2121
jpa:
2222
hibernate:
2323
ddl-auto: update
24+
properties:
25+
hibernate:
26+
jdbc:
27+
batch_size: 100
28+
order_inserts: true
29+
order_updates: true
2430

2531
data:
2632
redis:

Java/validation/src/main/resources/application-local.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,10 @@ spring:
1010
schema-generation:
1111
script:
1212
append: false
13+
jdbc:
14+
batch_size: 100
15+
order_inserts: true
16+
order_updates: true
1317

1418
jakarta:
1519
persistence:
Lines changed: 112 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,112 @@
1+
-- Drop old result tables (data will be lost per migration plan)
2+
if exists (select 1 from sys.foreign_keys where name = 'fk_result_category_result_id')
3+
begin
4+
alter table result_category drop constraint fk_result_category_result_id
5+
end
6+
7+
if exists (select 1 from sys.foreign_keys where name = 'fk_result_category_category_id')
8+
begin
9+
alter table result_category drop constraint fk_result_category_category_id
10+
end
11+
12+
if exists (select 1 from sys.tables where name = 'result_category' and schema_id = schema_id('dbo'))
13+
begin
14+
drop table result_category
15+
end
16+
17+
if exists (select 1 from sys.tables where name = 'result' and schema_id = schema_id('dbo'))
18+
begin
19+
drop table result
20+
end
21+
22+
if exists (select 1 from sys.sequences where name = 'result_sequence' and schema_name(schema_id) = 'dbo')
23+
begin
24+
drop sequence dbo.result_sequence
25+
end
26+
27+
-- Create sequence for Result IDs
28+
create sequence dbo.result_sequence
29+
as bigint
30+
start with 1
31+
increment by 100;
32+
33+
-- Recreate result table using sequence-based IDs (not IDENTITY)
34+
create table result
35+
(
36+
id bigint not null primary key default (NEXT VALUE FOR dbo.result_sequence),
37+
expression varchar(1000),
38+
code varchar(255) not null check (code in
39+
('INVALID', 'STRUCTURE', 'REQUIRED', 'VALUE', 'INVARIANT', 'SECURITY',
40+
'LOGIN', 'UNKNOWN', 'EXPIRED', 'FORBIDDEN', 'SUPPRESSED', 'PROCESSING',
41+
'NOTSUPPORTED', 'DUPLICATE', 'MULTIPLEMATCHES', 'NOTFOUND', 'DELETED',
42+
'TOOLONG', 'CODEINVALID', 'EXTENSION', 'TOOCOSTLY', 'BUSINESSRULE',
43+
'CONFLICT', 'TRANSIENT', 'LOCKERROR', 'NOSTORE', 'EXCEPTION',
44+
'TIMEOUT', 'INCOMPLETE', 'THROTTLED', 'INFORMATIONAL', 'NULL')),
45+
facility_id varchar(255) not null,
46+
location varchar(255),
47+
message varchar(max) not null,
48+
patient_id varchar(255) not null,
49+
report_id varchar(255) not null,
50+
severity varchar(255) not null check (severity in ('FATAL', 'ERROR', 'WARNING', 'INFORMATION', 'NULL'))
51+
);
52+
53+
-- Recreate result_category join table
54+
create table result_category
55+
(
56+
result_id bigint not null,
57+
category_id varchar(255) not null
58+
);
59+
60+
-- Indexes and constraints
61+
if not exists (select 1 from sys.indexes where name = 'ix_result_facility_id' and object_id = object_id('result'))
62+
create index ix_result_facility_id
63+
on result (facility_id);
64+
65+
if not exists (select 1 from sys.indexes where name = 'ix_result_facility_id_report_id' and object_id = object_id('result'))
66+
create index ix_result_facility_id_report_id
67+
on result (facility_id, report_id);
68+
69+
if not exists (select 1 from sys.indexes where name = 'ix_result_facility_id_report_id_patient_id' and object_id = object_id('result'))
70+
create index ix_result_facility_id_report_id_patient_id
71+
on result (facility_id, report_id, patient_id);
72+
73+
if not exists (select 1 from sys.indexes where name = 'ix_result_category_result_id' and object_id = object_id('result_category'))
74+
create index ix_result_category_result_id
75+
on result_category (result_id);
76+
77+
if not exists (select 1 from sys.key_constraints where name = 'ix_result_category_result_id_category_id')
78+
begin
79+
alter table result_category
80+
add constraint ix_result_category_result_id_category_id unique (result_id, category_id);
81+
end;
82+
83+
-- Foreign keys
84+
if not exists (select 1 from sys.foreign_keys where name = 'fk_result_category_category_id')
85+
begin
86+
alter table result_category
87+
add constraint fk_result_category_category_id
88+
foreign key (category_id)
89+
references category;
90+
end;
91+
92+
if not exists (select 1 from sys.foreign_keys where name = 'fk_result_category_result_id')
93+
begin
94+
alter table result_category
95+
add constraint fk_result_category_result_id
96+
foreign key (result_id)
97+
references result;
98+
end;
99+
100+
-- Ensure existing sequence uses increment 100 to match Hibernate allocationSize
101+
IF EXISTS (SELECT 1 FROM sys.sequences WHERE name = 'result_sequence' AND schema_name(schema_id) = 'dbo')
102+
BEGIN
103+
ALTER SEQUENCE dbo.result_sequence
104+
INCREMENT BY 100;
105+
END
106+
ELSE
107+
BEGIN
108+
CREATE SEQUENCE dbo.result_sequence
109+
AS bigint
110+
START WITH 1
111+
INCREMENT BY 100;
112+
END

0 commit comments

Comments
 (0)