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

changeset 227
f0ede8046b59
parent 225
87328572e36f
child 231
dcb1d5a7ea3a
equal deleted inserted replaced
226:c8e1b5282f69 227:f0ede8046b59
247 247
248 //<editor-fold desc="Component"> 248 //<editor-fold desc="Component">
249 //language=SQL 249 //language=SQL
250 private val componentQuery = 250 private val componentQuery =
251 """ 251 """
252 select id, project, name, node, color, ordinal, description, 252 select id, project, name, node, color, ordinal, description, active,
253 userid, username, givenname, lastname, mail 253 userid, username, givenname, lastname, mail
254 from lpit_component 254 from lpit_component
255 left join lpit_user on lead = userid 255 left join lpit_user on lead = userid
256 """.trimIndent() 256 """.trimIndent()
257 257
264 } catch (ex: IllegalArgumentException) { 264 } catch (ex: IllegalArgumentException) {
265 WebColor("000000") 265 WebColor("000000")
266 } 266 }
267 ordinal = getInt("ordinal") 267 ordinal = getInt("ordinal")
268 description = getString("description") 268 description = getString("description")
269 active = getBoolean("active")
269 lead = extractOptionalUser() 270 lead = extractOptionalUser()
270 } 271 }
271 272
272 private fun PreparedStatement.setComponent(index: Int, component: Component): Int { 273 private fun PreparedStatement.setComponent(index: Int, component: Component): Int {
273 with(component) { 274 with(component) {
275 setStringSafe(i++, name) 276 setStringSafe(i++, name)
276 setStringSafe(i++, node) 277 setStringSafe(i++, node)
277 setStringSafe(i++, color.hex) 278 setStringSafe(i++, color.hex)
278 setInt(i++, ordinal) 279 setInt(i++, ordinal)
279 setStringOrNull(i++, description) 280 setStringOrNull(i++, description)
281 setBoolean(i++, active)
280 setIntOrNull(i++, lead?.id) 282 setIntOrNull(i++, lead?.id)
281 return i 283 return i
282 } 284 }
283 } 285 }
284 286
300 summary as ( 302 summary as (
301 select c.id, phase, total 303 select c.id, phase, total
302 from lpit_component c 304 from lpit_component c
303 left join issues i on c.id = i.component 305 left join issues i on c.id = i.component
304 ) 306 )
305 select c.id, project, name, node, color, ordinal, description, 307 select c.id, project, name, node, color, ordinal, description, active,
306 userid, username, givenname, lastname, mail, 308 userid, username, givenname, lastname, mail,
307 open.total as open, active.total as active, done.total as done 309 open.total as open, wip.total as wip, done.total as done
308 from lpit_component c 310 from lpit_component c
309 left join lpit_user on lead = userid 311 left join lpit_user on lead = userid
310 left join summary open on c.id = open.id and open.phase = 0 312 left join summary open on c.id = open.id and open.phase = 0
311 left join summary active on c.id = active.id and active.phase = 1 313 left join summary wip on c.id = wip.id and wip.phase = 1
312 left join summary done on c.id = done.id and done.phase = 2 314 left join summary done on c.id = done.id and done.phase = 2
313 where c.project = ? 315 where c.project = ?
314 order by ordinal, name 316 order by ordinal, name
315 """.trimIndent() 317 """.trimIndent()
316 ) { 318 ) {
317 setInt(1, project.id) 319 setInt(1, project.id)
318 queryAll { rs -> 320 queryAll { rs ->
319 ComponentSummary(rs.extractComponent()).apply { 321 ComponentSummary(rs.extractComponent()).apply {
320 issueSummary.open = rs.getInt("open") 322 issueSummary.open = rs.getInt("open")
321 issueSummary.active = rs.getInt("active") 323 issueSummary.active = rs.getInt("wip")
322 issueSummary.done = rs.getInt("done") 324 issueSummary.done = rs.getInt("done")
323 } 325 }
324 } 326 }
325 } 327 }
326 328
336 setString(2, node) 338 setString(2, node)
337 querySingle { it.extractComponent() } 339 querySingle { it.extractComponent() }
338 } 340 }
339 341
340 override fun insertComponent(component: Component) { 342 override fun insertComponent(component: Component) {
341 withStatement("insert into lpit_component (name, node, color, ordinal, description, lead, project) values (?, ?, ?, ?, ?, ?, ?)") { 343 withStatement("insert into lpit_component (name, node, color, ordinal, description, active, lead, project) values (?, ?, ?, ?, ?, ?, ?, ?)") {
342 val col = setComponent(1, component) 344 val col = setComponent(1, component)
343 setInt(col, component.projectid) 345 setInt(col, component.projectid)
344 executeUpdate() 346 executeUpdate()
345 } 347 }
346 } 348 }
347 349
348 override fun updateComponent(component: Component) { 350 override fun updateComponent(component: Component) {
349 withStatement("update lpit_component set name = ?, node = ?, color = ?, ordinal = ?, description = ?, lead = ? where id = ?") { 351 withStatement("update lpit_component set name = ?, node = ?, color = ?, ordinal = ?, description = ?, active = ?, lead = ? where id = ?") {
350 val col = setComponent(1, component) 352 val col = setComponent(1, component)
351 setInt(col, component.id) 353 setInt(col, component.id)
352 executeUpdate() 354 executeUpdate()
353 } 355 }
354 } 356 }

mercurial