Skip to content

Commit 60c86a7

Browse files
authored
Merge pull request #32 from Yuval-Roth/fg_db_fixes
Fg db fixes
2 parents 70bf0e8 + 3741cc4 commit 60c86a7

5 files changed

Lines changed: 20 additions & 7 deletions

File tree

common/src/main/java/com/imsproject/common/dataAccess/OfflineResultSet.kt

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,12 @@ class OfflineResultSet(rs: ResultSet) {
8484

8585
fun getLocalDateTime(columnName: String): LocalDateTime? {
8686
val obj = getObject(columnName) ?: return null
87-
return LocalDateTime.parse(obj as String, DateTimeFormatter.ISO_LOCAL_DATE_TIME)
87+
return when (obj) {
88+
is LocalDateTime -> obj
89+
is java.sql.Timestamp -> obj.toLocalDateTime()
90+
is String -> LocalDateTime.parse(obj, DateTimeFormatter.ISO_LOCAL_DATE_TIME)
91+
else -> throw IllegalArgumentException("Unsupported type for LocalDateTime: ${obj::class.java.name}")
92+
}
8893
}
8994

9095
inline fun <reified T> getEnum(columnName: String): T? {

database/init.sql

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ CREATE TABLE IF NOT EXISTS Experiments (
1212
exp_id SERIAL PRIMARY KEY,
1313
pid1 INT,
1414
pid2 INT,
15+
date_time TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
1516
FOREIGN KEY (pid1) REFERENCES Participants(pid),
1617
FOREIGN KEY (pid2) REFERENCES Participants(pid)
1718
);

game_server/src/main/kotlin/com/imsproject/gameserver/business/ExperimentOrchestrator.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ class ExperimentOrchestrator(
5555
val pid1 = Integer.parseInt(player1Id)
5656
val pid2 = Integer.parseInt(player2Id)
5757

58-
val experimentDTO = ExperimentDTO(null,pid1,pid2)
58+
val experimentDTO = ExperimentDTO(null,pid1,pid2,null)
5959
val expId = daoController.handleInsert(experimentDTO)
6060
experimentSessions.forEachIndexed { index, session ->
6161
if(session.dbId == null){

game_server/src/main/kotlin/com/imsproject/gameserver/dataAccess/implementations/ExperimentsDAO.kt

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,13 @@ import com.imsproject.gameserver.dataAccess.models.ExperimentWithParticipantName
1313
import org.springframework.stereotype.Component
1414

1515
@Component
16-
class ExperimentsDAO(cursor: SQLExecutor) : DAOBase<ExperimentDTO, ExperimentPK>(cursor, "Experiments", ExperimentPK.primaryColumnsList, arrayOf("pid1", "pid2")) {
16+
class ExperimentsDAO(cursor: SQLExecutor) : DAOBase<ExperimentDTO, ExperimentPK>(cursor, "Experiments", ExperimentPK.primaryColumnsList, arrayOf("pid1", "pid2", "date_time")) {
1717
override fun buildObjectFromResultSet(resultSet: OfflineResultSet): ExperimentDTO {
1818
return ExperimentDTO(
1919
expId = resultSet.getInt("exp_id"),
2020
pid1 = resultSet.getInt("pid1"),
21-
pid2 = resultSet.getInt("pid2")
21+
pid2 = resultSet.getInt("pid2"),
22+
dateTime = resultSet.getLocalDateTime("date_time")
2223
)
2324

2425
}
@@ -46,6 +47,7 @@ class ExperimentsDAO(cursor: SQLExecutor) : DAOBase<ExperimentDTO, ExperimentPK>
4647
fun selectWithParticipantNames(transactionId: String? = null): List<ExperimentWithParticipantNamesDTO> {
4748
val query = """
4849
SELECT e.exp_id AS eid,
50+
e.date_time AS date_time,
4951
p1.first_name AS p1_name,
5052
p2.first_name AS p2_name
5153
FROM experiments e
@@ -61,7 +63,8 @@ class ExperimentsDAO(cursor: SQLExecutor) : DAOBase<ExperimentDTO, ExperimentPK>
6163
ExperimentWithParticipantNamesDTO(
6264
expId = resultSet.getInt("eid")!!,
6365
participant1Name = resultSet.getString("p1_name")!!,
64-
participant2Name = resultSet.getString("p2_name")!!
66+
participant2Name = resultSet.getString("p2_name")!!,
67+
dateTime = resultSet.getLocalDateTime("date_time")!!
6568
)
6669
)
6770
}

game_server/src/main/kotlin/com/imsproject/gameserver/dataAccess/models/Models.kt

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
package com.imsproject.gameserver.dataAccess.models
22

33
import com.imsproject.common.gameserver.SessionEvent
4+
import java.time.LocalDate
5+
import java.time.LocalDateTime
46
import kotlin.math.exp
57

68
data class ParticipantDTO(
@@ -16,7 +18,8 @@ data class ParticipantDTO(
1618
data class ExperimentDTO(
1719
val expId: Int?,
1820
val pid1: Int?,
19-
val pid2: Int?
21+
val pid2: Int?,
22+
val dateTime: LocalDateTime?
2023
)
2124

2225
data class ExperimentFeedbackDTO(
@@ -132,6 +135,7 @@ data class SessionData(
132135

133136
data class ExperimentWithParticipantNamesDTO(
134137
val expId: Int,
138+
val dateTime: LocalDateTime,
135139
val participant1Name: String,
136140
val participant2Name: String
137-
) //todo: add date?
141+
)

0 commit comments

Comments
 (0)