Skip to content
This repository has been archived by the owner on Feb 12, 2024. It is now read-only.

Commit

Permalink
synchronized PrepareStatement
Browse files Browse the repository at this point in the history
  • Loading branch information
found-cake committed Nov 14, 2023
1 parent e41deed commit 23c8e2a
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 13 deletions.
24 changes: 15 additions & 9 deletions src/main/kotlin/kr/foundcake/sch_sw_notice/database/ChannelDB.kt
Original file line number Diff line number Diff line change
Expand Up @@ -23,29 +23,35 @@ class ChannelDB(conn: Connection) {
)

fun registerChannel(serverId: Long, channelId: Long) : Boolean{
registerChannelStmt.setLong(1, serverId)
registerChannelStmt.setLong(2, channelId)
registerChannelStmt.setLong(3, channelId)
return registerChannelStmt.execute()
synchronized(registerChannelStmt) {
registerChannelStmt.setLong(1, serverId)
registerChannelStmt.setLong(2, channelId)
registerChannelStmt.setLong(3, channelId)
return registerChannelStmt.execute()
}
}

private val removeChannelByServerIdStmt: PreparedStatement = conn.prepareStatement(
"DELETE FROM `channel_db` WHERE `serverId`=?"
)

fun removeChannelByServerId(serverId: Long): Boolean {
removeChannelByServerIdStmt.setLong(1, serverId)
return removeChannelByServerIdStmt.execute()
synchronized(removeChannelByServerIdStmt) {
removeChannelByServerIdStmt.setLong(1, serverId)
return removeChannelByServerIdStmt.execute()
}
}

private val removeChannelByChannelIdStmt: PreparedStatement = conn.prepareStatement(
"DELETE FROM `channel_db` WHERE `serverId`=? and `channelId`=?"
)

fun removeChannelByChannelId(serverId: Long, channelId: Long) : Boolean{
removeChannelByChannelIdStmt.setLong(1, serverId)
removeChannelByChannelIdStmt.setLong(2, channelId)
return removeChannelByChannelIdStmt.execute()
synchronized(removeChannelByChannelIdStmt) {
removeChannelByChannelIdStmt.setLong(1, serverId)
removeChannelByChannelIdStmt.setLong(2, channelId)
return removeChannelByChannelIdStmt.execute()
}
}

private val getChannelsStmt: PreparedStatement = conn.prepareStatement(
Expand Down
10 changes: 6 additions & 4 deletions src/main/kotlin/kr/foundcake/sch_sw_notice/database/NoticeDB.kt
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,12 @@ class NoticeDB(conn: Connection) {
)

fun addNotice(notice: Notice) : Boolean {
addNoticeStmt.setString(1, notice.title)
addNoticeStmt.setString(2, notice.url)
addNoticeStmt.setString(3, notice.author)
return addNoticeStmt.execute()
synchronized(addNoticeStmt) {
addNoticeStmt.setString(1, notice.title)
addNoticeStmt.setString(2, notice.url)
addNoticeStmt.setString(3, notice.author)
return addNoticeStmt.execute()
}
}

private val removeNoticeStmt: PreparedStatement = conn.prepareStatement(
Expand Down

1 comment on commit 23c8e2a

@found-cake
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

solve #2

Please sign in to comment.