2424import java .util .List ;
2525import java .util .Optional ;
2626import java .util .stream .Stream ;
27+ import javax .persistence .QueryHint ;
28+ import org .springframework .data .domain .Pageable ;
29+ import org .springframework .data .domain .Slice ;
2730import org .springframework .data .jpa .repository .Modifying ;
2831import org .springframework .data .jpa .repository .Query ;
32+ import org .springframework .data .jpa .repository .QueryHints ;
2933import org .springframework .data .repository .query .Param ;
3034
3135/**
@@ -37,6 +41,109 @@ public interface TestItemRepository extends ReportPortalRepository<TestItem, Lon
3741 @ Query (value = "SELECT * FROM test_item WHERE item_id = (SELECT parent_id FROM test_item WHERE item_id = :childId)" , nativeQuery = true )
3842 Optional <TestItem > findParentByChildId (@ Param ("childId" ) Long childId );
3943
44+ @ Query (value = """
45+ SELECT ti.* FROM test_item ti
46+ INNER JOIN launch l ON ti.launch_id = l.id
47+ WHERE ti.has_children = false
48+ AND ti.has_stats = true
49+ AND ti.retry_of IS NULL
50+ AND ti.type = 'STEP'
51+ AND l.project_id = :projectId
52+ AND ti.name ILIKE %:name%
53+ """ , nativeQuery = true )
54+ @ QueryHints (@ QueryHint (name = "javax.persistence.query.timeout" , value = "10000" ))
55+ Slice <TestItem > findTestItemsContainsName (@ Param ("name" ) String nameTerm ,
56+ @ Param ("projectId" ) Long projectId ,
57+ Pageable pageable );
58+
59+ @ Query (value = """
60+ SELECT ti.* FROM test_item ti
61+ JOIN test_item_results tir on ti.item_id = tir.result_id
62+ JOIN launch l ON ti.launch_id = l.id
63+ WHERE ti.has_children = false
64+ AND ti.has_stats = true
65+ AND ti.retry_of IS NULL
66+ AND ti.type = 'STEP'
67+ AND l.project_id = :projectId
68+ AND ti.name ILIKE %:name%
69+ AND CAST(tir.status AS VARCHAR) in (:statuses)
70+ """ , nativeQuery = true )
71+ @ QueryHints (@ QueryHint (name = "javax.persistence.query.timeout" , value = "10000" ))
72+ Slice <TestItem > findTestItemsContainsNameAndStatuses (@ Param ("name" ) String nameTerm ,
73+ @ Param ("projectId" ) Long projectId , @ Param ("statuses" ) List <String > statuses ,
74+ Pageable pageable );
75+
76+ @ Query (value = """
77+ SELECT ti.* FROM test_item ti
78+ JOIN launch l ON ti.launch_id = l.id
79+ LEFT JOIN item_attribute ia ON ti.item_id = ia.item_id
80+ WHERE ti.has_children = false
81+ AND ti.has_stats = true
82+ AND ti.retry_of IS NULL
83+ AND ti.type = 'STEP'
84+ AND l.project_id = :projectId
85+ AND ia.key = :key AND ia.value = :value and ia.system = false
86+ """ , nativeQuery = true )
87+ @ QueryHints (@ QueryHint (name = "javax.persistence.query.timeout" , value = "10000" ))
88+ Slice <TestItem > findTestItemsByAttribute (@ Param ("projectId" ) Long projectId ,
89+ @ Param ("key" ) String attributeKey ,
90+ @ Param ("value" ) String attributeValue ,
91+ Pageable pageable );
92+
93+ @ Query (value = """
94+ SELECT ti.* FROM test_item ti
95+ JOIN test_item_results tir on ti.item_id = tir.result_id
96+ JOIN launch l ON ti.launch_id = l.id
97+ LEFT JOIN item_attribute ia ON ti.item_id = ia.item_id
98+ WHERE ti.has_children = false
99+ AND ti.has_stats = true
100+ AND ti.retry_of IS NULL
101+ AND ti.type = 'STEP'
102+ AND l.project_id = :projectId
103+ AND ia.key = :key AND ia.value = :value and ia.system = false
104+ AND CAST(tir.status AS VARCHAR) in (:statuses)
105+ """ , nativeQuery = true )
106+ @ QueryHints (@ QueryHint (name = "javax.persistence.query.timeout" , value = "10000" ))
107+ Slice <TestItem > findTestItemsByAttributeAndStatuses (@ Param ("projectId" ) Long projectId ,
108+ @ Param ("key" ) String attributeKey ,
109+ @ Param ("value" ) String attributeValue ,
110+ @ Param ("statuses" ) List <String > statuses ,
111+ Pageable pageable );
112+
113+
114+ @ Query (value = """
115+ SELECT ti.* FROM test_item ti
116+ JOIN launch l ON ti.launch_id = l.id
117+ LEFT JOIN item_attribute ia ON ti.item_id = ia.item_id
118+ WHERE ti.has_children = false
119+ AND ti.has_stats = true
120+ AND ti.retry_of IS NULL
121+ AND ti.type = 'STEP'
122+ AND l.project_id = :projectId
123+ AND ia.key is null AND ia.value = :value and ia.system = false
124+ """ , nativeQuery = true )
125+ @ QueryHints (@ QueryHint (name = "javax.persistence.query.timeout" , value = "10000" ))
126+ Slice <TestItem > findTestItemsByAttribute (@ Param ("projectId" ) Long projectId ,
127+ @ Param ("value" ) String attributeValue , Pageable pageable );
128+
129+ @ Query (value = """
130+ SELECT ti.* FROM test_item ti
131+ JOIN launch l ON ti.launch_id = l.id
132+ JOIN test_item_results tir on ti.item_id = tir.result_id
133+ LEFT JOIN item_attribute ia ON ti.item_id = ia.item_id
134+ WHERE ti.has_children = false
135+ AND ti.has_stats = true
136+ AND ti.retry_of IS NULL
137+ AND ti.type = 'STEP'
138+ AND l.project_id = :projectId
139+ AND ia.key is null AND ia.value = :value and ia.system = false
140+ AND CAST(tir.status AS VARCHAR) in (:statuses)
141+ """ , nativeQuery = true )
142+ @ QueryHints (@ QueryHint (name = "javax.persistence.query.timeout" , value = "10000" ))
143+ Slice <TestItem > findTestItemsByAttributeAndStatuses (@ Param ("projectId" ) Long projectId ,
144+ @ Param ("value" ) String attributeValue , @ Param ("statuses" ) List <String > statuses ,
145+ Pageable pageable );
146+
40147 /**
41148 * Retrieve list of test item ids for provided launch
42149 *
@@ -351,24 +458,26 @@ Optional<Long> findLatestIdByTestCaseHashAndLaunchIdWithoutParents(
351458 @ Param ("testCaseHash" ) Integer testCaseHash ,
352459 @ Param ("launchId" ) Long launchId );
353460
354- /**
355- * Finds latest {@link TestItem#getItemId()} with specified {@code testCaseHash}, {@code launchId} and {@code parentId}
356- *
357- * @param testCaseHash {@link TestItem#getTestCaseHash()}
358- * @param launchId {@link TestItem#getLaunchId()}
359- * @param parentId {@link TestItem#getParentId()}
360- * @return {@link Optional} of {@link TestItem#getItemId()} if exists otherwise {@link Optional#empty()}
361- */
362- @ Query (value =
363- "SELECT t.item_id FROM test_item t WHERE t.test_case_hash = :testCaseHash AND t.launch_id = :launchId "
364- + " AND t.parent_id = :parentId AND t.has_stats AND t.retry_of IS NULL"
365- + " ORDER BY t.start_time DESC, t.item_id DESC LIMIT 1 FOR UPDATE" , nativeQuery = true )
366- Optional <Long > findLatestIdByTestCaseHashAndLaunchIdAndParentId (
367- @ Param ("testCaseHash" ) Integer testCaseHash ,
368- @ Param ("launchId" ) Long launchId , @ Param ("parentId" ) Long parentId );
369-
370- @ Query (value = "SELECT t.name FROM test_item t WHERE t.item_id = :itemId" , nativeQuery = true )
371- Optional <String > findItemNameByItemId (Long itemId );
461+ /**
462+ * Finds latest {@link TestItem#getItemId()} with specified {@code testCaseHash}, {@code launchId}
463+ * and {@code parentId}
464+ *
465+ * @param testCaseHash {@link TestItem#getTestCaseHash()}
466+ * @param launchId {@link TestItem#getLaunchId()}
467+ * @param parentId {@link TestItem#getParentId()}
468+ * @return {@link Optional} of {@link TestItem#getItemId()} if exists otherwise
469+ * {@link Optional#empty()}
470+ */
471+ @ Query (value =
472+ "SELECT t.item_id FROM test_item t WHERE t.test_case_hash = :testCaseHash AND t.launch_id = :launchId "
473+ + " AND t.parent_id = :parentId AND t.has_stats AND t.retry_of IS NULL"
474+ + " ORDER BY t.start_time DESC, t.item_id DESC LIMIT 1 FOR UPDATE" , nativeQuery = true )
475+ Optional <Long > findLatestIdByTestCaseHashAndLaunchIdAndParentId (
476+ @ Param ("testCaseHash" ) Integer testCaseHash ,
477+ @ Param ("launchId" ) Long launchId , @ Param ("parentId" ) Long parentId );
478+
479+ @ Query (value = "SELECT t.name FROM test_item t WHERE t.item_id = :itemId" , nativeQuery = true )
480+ Optional <String > findItemNameByItemId (Long itemId );
372481
373482 /**
374483 * Count items by launch id
0 commit comments