src/main/kotlin/de/uapcore/lightpit/dao/PostgresDataAccessObject.kt

changeset 263
aa22103809cd
parent 260
fb2ae2d63a56
child 268
ca5501d851fa
     1.1 --- a/src/main/kotlin/de/uapcore/lightpit/dao/PostgresDataAccessObject.kt	Fri Dec 30 13:21:09 2022 +0100
     1.2 +++ b/src/main/kotlin/de/uapcore/lightpit/dao/PostgresDataAccessObject.kt	Fri Dec 30 19:04:34 2022 +0100
     1.3 @@ -534,10 +534,15 @@
     1.4          return i
     1.5      }
     1.6  
     1.7 +    override fun listIssues(project: Project): List<Issue> =
     1.8 +        withStatement("$issueQuery where i.project = ?") {
     1.9 +            setInt(1, project.id)
    1.10 +            queryAll { it.extractIssue() }
    1.11 +        }
    1.12 +
    1.13      override fun listIssues(project: Project, version: Version?, component: Component?): List<Issue> =
    1.14          withStatement(
    1.15 -            """$issueQuery where
    1.16 -                (not ? or i.project = ?) and 
    1.17 +            """$issueQuery where i.project = ? and 
    1.18                  (not ? or ? in (resolved, affected)) and (not ? or (resolved is null and affected is null)) and
    1.19                  (not ? or component = ?) and (not ? or component is null)
    1.20              """.trimIndent()
    1.21 @@ -553,10 +558,9 @@
    1.22                      setInt(idcol, search.id)
    1.23                  }
    1.24              }
    1.25 -            setBoolean(1, true)
    1.26 -            setInt(2, project.id)
    1.27 -            applyFilter(version, 3, 5, 4)
    1.28 -            applyFilter(component, 6, 8, 7)
    1.29 +            setInt(1, project.id)
    1.30 +            applyFilter(version, 2, 4, 3)
    1.31 +            applyFilter(component, 5, 7, 6)
    1.32  
    1.33              queryAll { it.extractIssue() }
    1.34          }
    1.35 @@ -629,6 +633,53 @@
    1.36  
    1.37      //</editor-fold>
    1.38  
    1.39 +    //<editor-fold desc="Issue Relations">
    1.40 +    override fun insertIssueRelation(rel: IssueRelation) {
    1.41 +        withStatement(
    1.42 +            """
    1.43 +            insert into lpit_issue_relation (from_issue, to_issue, type)
    1.44 +            values (?, ?, ?::relation_type)
    1.45 +            on conflict do nothing
    1.46 +            """.trimIndent()
    1.47 +        ) {
    1.48 +            if (rel.reverse) {
    1.49 +                setInt(2, rel.from.id)
    1.50 +                setInt(1, rel.to.id)
    1.51 +            } else {
    1.52 +                setInt(1, rel.from.id)
    1.53 +                setInt(2, rel.to.id)
    1.54 +            }
    1.55 +            setEnum(3, rel.type)
    1.56 +            executeUpdate()
    1.57 +        }
    1.58 +    }
    1.59 +
    1.60 +    override fun deleteIssueRelation(rel: IssueRelation) {
    1.61 +        withStatement("delete from lpit_issue_relation where from_issue = ? and to_issue = ? and type=?::relation_type") {
    1.62 +            if (rel.reverse) {
    1.63 +                setInt(2, rel.from.id)
    1.64 +                setInt(1, rel.to.id)
    1.65 +            } else {
    1.66 +                setInt(1, rel.from.id)
    1.67 +                setInt(2, rel.to.id)
    1.68 +            }
    1.69 +            setEnum(3, rel.type)
    1.70 +            executeUpdate()
    1.71 +        }
    1.72 +    }
    1.73 +
    1.74 +    override fun listIssueRelations(issue: Issue): List<IssueRelation> = buildList {
    1.75 +        withStatement("select to_issue, type from lpit_issue_relation where from_issue = ?") {
    1.76 +            setInt(1, issue.id)
    1.77 +            queryAll { IssueRelation(issue, findIssue(it.getInt("to_issue"))!!, it.getEnum("type"), false) }
    1.78 +        }.forEach(this::add)
    1.79 +        withStatement("select from_issue, type from lpit_issue_relation where to_issue = ?") {
    1.80 +            setInt(1, issue.id)
    1.81 +            queryAll { IssueRelation(issue, findIssue(it.getInt("from_issue"))!!, it.getEnum("type"), true) }
    1.82 +        }.forEach(this::add)
    1.83 +    }
    1.84 +    //</editor-fold>
    1.85 +
    1.86      //<editor-fold desc="IssueComment">
    1.87  
    1.88      private fun ResultSet.extractIssueComment() =

mercurial