10
10
import org .lfenergy .compas .scl .data .repository .CompasSclDataRepository ;
11
11
import org .lfenergy .compas .scl .extensions .model .SclFileType ;
12
12
13
- import jakarta .enterprise .context .ApplicationScoped ;
14
- import jakarta .inject .Inject ;
15
13
import javax .sql .DataSource ;
16
14
import jakarta .transaction .Transactional ;
17
15
import java .sql .Array ;
27
25
import static jakarta .transaction .Transactional .TxType .SUPPORTS ;
28
26
import static org .lfenergy .compas .scl .data .exception .CompasSclDataServiceErrorCode .*;
29
27
30
- @ ApplicationScoped
31
28
public class CompasSclDataPostgreSQLRepository implements CompasSclDataRepository {
32
29
private static final String ID_FIELD = "id" ;
33
30
private static final String MAJOR_VERSION_FIELD = "major_version" ;
@@ -39,9 +36,23 @@ public class CompasSclDataPostgreSQLRepository implements CompasSclDataRepositor
39
36
private static final String HITEM_WHEN_FIELD = "hitem_when" ;
40
37
private static final String HITEM_WHAT_FIELD = "hitem_what" ;
41
38
42
- private final DataSource dataSource ;
39
+ protected final DataSource dataSource ;
40
+
41
+ protected static String DELETE_SCL_FILE_SQL = """
42
+ delete from scl_file
43
+ where scl_file.id = ?
44
+ and scl_file.type = ?
45
+ """ ;
46
+
47
+ protected static String DELETE_SCL_FILE_SQL_BY_VERSION = """
48
+ delete from scl_file
49
+ where scl_file.id = ?
50
+ and scl_file.type = ?
51
+ and scl_file.major_version = ?
52
+ and scl_file.minor_version = ?
53
+ and scl_file.patch_version = ?
54
+ """ ;
43
55
44
- @ Inject
45
56
public CompasSclDataPostgreSQLRepository (DataSource dataSource ) {
46
57
this .dataSource = dataSource ;
47
58
}
@@ -56,6 +67,7 @@ public List<IItem> list(SclFileType type) {
56
67
from (select distinct on (scl_file.id) *
57
68
from scl_file
58
69
where scl_file.type = ?
70
+ and scl_file.is_deleted = false
59
71
order by scl_file.id
60
72
, scl_file.major_version desc
61
73
, scl_file.minor_version desc
@@ -115,6 +127,7 @@ left outer join (
115
127
and scl_data.patch_version = scl_file.patch_version
116
128
where scl_file.id = ?
117
129
and scl_file.type = ?
130
+ and scl_file.is_deleted = false
118
131
order by scl_file.major_version
119
132
, scl_file.minor_version
120
133
, scl_file.patch_version
@@ -162,6 +175,7 @@ public String findByUUID(SclFileType type, UUID id, Version version) {
162
175
and scl_file.major_version = ?
163
176
and scl_file.minor_version = ?
164
177
and scl_file.patch_version = ?
178
+ and scl_file.is_deleted = false
165
179
""" ;
166
180
167
181
try (var connection = dataSource .getConnection ();
@@ -191,6 +205,7 @@ public boolean hasDuplicateSclName(SclFileType type, String name) {
191
205
select distinct on (scl_file.id) scl_file.name
192
206
from scl_file
193
207
where scl_file.type = ?
208
+ and scl_file.is_deleted = false
194
209
order by scl_file.id
195
210
, scl_file.major_version desc
196
211
, scl_file.minor_version desc
@@ -221,6 +236,7 @@ public IAbstractItem findMetaInfoByUUID(SclFileType type, UUID id) {
221
236
from scl_file
222
237
where scl_file.id = ?
223
238
and scl_file.type = ?
239
+ and scl_file.is_deleted = false
224
240
order by scl_file.major_version desc, scl_file.minor_version desc, scl_file.patch_version desc
225
241
""" ;
226
242
@@ -304,14 +320,9 @@ insert into scl_label(scl_id, major_version, minor_version, patch_version, label
304
320
@ Override
305
321
@ Transactional (REQUIRED )
306
322
public void delete (SclFileType type , UUID id ) {
307
- var sql = """
308
- delete from scl_file
309
- where scl_file.id = ?
310
- and scl_file.type = ?
311
- """ ;
312
323
313
324
try (var connection = dataSource .getConnection ();
314
- var stmt = connection .prepareStatement (sql )) {
325
+ var stmt = connection .prepareStatement (DELETE_SCL_FILE_SQL )) {
315
326
stmt .setObject (1 , id );
316
327
stmt .setString (2 , type .name ());
317
328
stmt .executeUpdate ();
@@ -323,17 +334,9 @@ public void delete(SclFileType type, UUID id) {
323
334
@ Override
324
335
@ Transactional (REQUIRED )
325
336
public void delete (SclFileType type , UUID id , Version version ) {
326
- var sql = """
327
- delete from scl_file
328
- where scl_file.id = ?
329
- and scl_file.type = ?
330
- and scl_file.major_version = ?
331
- and scl_file.minor_version = ?
332
- and scl_file.patch_version = ?
333
- """ ;
334
337
335
338
try (var connection = dataSource .getConnection ();
336
- var stmt = connection .prepareStatement (sql )) {
339
+ var stmt = connection .prepareStatement (DELETE_SCL_FILE_SQL_BY_VERSION )) {
337
340
stmt .setObject (1 , id );
338
341
stmt .setString (2 , type .name ());
339
342
stmt .setInt (3 , version .getMajorVersion ());
0 commit comments