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

changeset 284
671c1c8fbf1c
parent 268
ca5501d851fa
child 292
703591e739f4
     1.1 --- a/src/main/kotlin/de/uapcore/lightpit/dao/PostgresDataAccessObject.kt	Sat Jul 22 15:07:23 2023 +0200
     1.2 +++ b/src/main/kotlin/de/uapcore/lightpit/dao/PostgresDataAccessObject.kt	Sat Jul 22 22:32:04 2023 +0200
     1.3 @@ -26,6 +26,7 @@
     1.4  package de.uapcore.lightpit.dao
     1.5  
     1.6  import de.uapcore.lightpit.entities.*
     1.7 +import de.uapcore.lightpit.types.CommitRef
     1.8  import de.uapcore.lightpit.types.IssueHistoryType
     1.9  import de.uapcore.lightpit.types.RelationType
    1.10  import de.uapcore.lightpit.types.WebColor
    1.11 @@ -358,7 +359,7 @@
    1.12      //language=SQL
    1.13      private val projectQuery =
    1.14          """
    1.15 -        select projectid, name, node, ordinal, description, repourl,
    1.16 +        select projectid, name, node, ordinal, description, vcs, repourl,
    1.17              userid, username, lastname, givenname, mail
    1.18          from lpit_project
    1.19          left join lpit_user owner on lpit_project.owner = owner.userid
    1.20 @@ -370,6 +371,7 @@
    1.21              node = getString("node")
    1.22              ordinal = getInt("ordinal")
    1.23              description = getString("description")
    1.24 +            vcs = getEnum("vcs")
    1.25              repoUrl = getString("repourl")
    1.26              owner = extractOptionalUser()
    1.27          }
    1.28 @@ -381,6 +383,7 @@
    1.29              setStringSafe(i++, node)
    1.30              setInt(i++, ordinal)
    1.31              setStringOrNull(i++, description)
    1.32 +            setEnum(i++, vcs)
    1.33              setStringOrNull(i++, repoUrl)
    1.34              setIntOrNull(i++, owner?.id)
    1.35          }
    1.36 @@ -405,14 +408,14 @@
    1.37          }
    1.38  
    1.39      override fun insertProject(project: Project) {
    1.40 -        withStatement("insert into lpit_project (name, node, ordinal, description, repourl, owner) values (?, ?, ?, ?, ?, ?)") {
    1.41 +        withStatement("insert into lpit_project (name, node, ordinal, description, vcs, repourl, owner) values (?, ?, ?, ?, ?::vcstype, ?, ?)") {
    1.42              setProject(1, project)
    1.43              executeUpdate()
    1.44          }
    1.45      }
    1.46  
    1.47      override fun updateProject(project: Project) {
    1.48 -        withStatement("update lpit_project set name = ?, node = ?, ordinal = ?, description = ?, repourl = ?, owner = ? where projectid = ?") {
    1.49 +        withStatement("update lpit_project set name = ?, node = ?, ordinal = ?, description = ?, vcs = ?::vcstype, repourl = ?, owner = ? where projectid = ?") {
    1.50              val col = setProject(1, project)
    1.51              setInt(col, project.id)
    1.52              executeUpdate()
    1.53 @@ -471,6 +474,17 @@
    1.54              }
    1.55          }
    1.56  
    1.57 +    override fun mergeCommitRefs(refs: List<CommitRef>) {
    1.58 +        withStatement("insert into lpit_commit_ref (issueid, commit_hash, commit_brief) values (?,?,?) on conflict do nothing") {
    1.59 +            refs.forEach { ref ->
    1.60 +                setInt(1, ref.issueId)
    1.61 +                setString(2, ref.hash)
    1.62 +                setString(3, ref.message)
    1.63 +                executeUpdate()
    1.64 +            }
    1.65 +        }
    1.66 +    }
    1.67 +
    1.68      //</editor-fold>
    1.69  
    1.70      //<editor-fold desc="Issue">
    1.71 @@ -636,6 +650,18 @@
    1.72          }
    1.73      }
    1.74  
    1.75 +    override fun listCommitRefs(issue: Issue): List<CommitRef> =
    1.76 +        withStatement("select commit_hash, commit_brief from lpit_commit_ref where issueid = ?") {
    1.77 +            setInt(1, issue.id)
    1.78 +            queryAll {
    1.79 +                CommitRef(
    1.80 +                    issueId = issue.id,
    1.81 +                    hash = it.getString("commit_hash"),
    1.82 +                    message = it.getString("commit_brief")
    1.83 +                )
    1.84 +            }
    1.85 +        }
    1.86 +
    1.87      //</editor-fold>
    1.88  
    1.89      //<editor-fold desc="Issue Relations">

mercurial