commit 14072025
This commit is contained in:
2
.idea/inspectionProfiles/Project_Default.xml
generated
2
.idea/inspectionProfiles/Project_Default.xml
generated
@@ -1,7 +1,7 @@
|
|||||||
<component name="InspectionProjectProfileManager">
|
<component name="InspectionProjectProfileManager">
|
||||||
<profile version="1.0">
|
<profile version="1.0">
|
||||||
<option name="myName" value="Project Default" />
|
<option name="myName" value="Project Default" />
|
||||||
<inspection_tool class="DuplicatedCode" enabled="true" level="WEAK WARNING" enabled_by_default="true">
|
<inspection_tool class="DuplicatedCode" enabled="false" level="WEAK WARNING" enabled_by_default="false">
|
||||||
<Languages>
|
<Languages>
|
||||||
<language minSize="47" name="Kotlin" />
|
<language minSize="47" name="Kotlin" />
|
||||||
</Languages>
|
</Languages>
|
||||||
|
|||||||
13
.idea/libraries/jetbrains_kotlinx_coroutines_core.xml
generated
Normal file
13
.idea/libraries/jetbrains_kotlinx_coroutines_core.xml
generated
Normal file
@@ -0,0 +1,13 @@
|
|||||||
|
<component name="libraryTable">
|
||||||
|
<library name="jetbrains.kotlinx.coroutines.core" type="repository">
|
||||||
|
<properties maven-id="org.jetbrains.kotlinx:kotlinx-coroutines-core:1.10.2" />
|
||||||
|
<CLASSES>
|
||||||
|
<root url="jar://$MAVEN_REPOSITORY$/org/jetbrains/kotlinx/kotlinx-coroutines-core/1.10.2/kotlinx-coroutines-core-1.10.2.jar!/" />
|
||||||
|
<root url="jar://$MAVEN_REPOSITORY$/org/jetbrains/kotlinx/kotlinx-coroutines-core-jvm/1.10.2/kotlinx-coroutines-core-jvm-1.10.2.jar!/" />
|
||||||
|
<root url="jar://$MAVEN_REPOSITORY$/org/jetbrains/annotations/23.0.0/annotations-23.0.0.jar!/" />
|
||||||
|
<root url="jar://$MAVEN_REPOSITORY$/org/jetbrains/kotlin/kotlin-stdlib/2.1.0/kotlin-stdlib-2.1.0.jar!/" />
|
||||||
|
</CLASSES>
|
||||||
|
<JAVADOC />
|
||||||
|
<SOURCES />
|
||||||
|
</library>
|
||||||
|
</component>
|
||||||
@@ -3,8 +3,7 @@ package database
|
|||||||
import org.mariadb.jdbc.Connection
|
import org.mariadb.jdbc.Connection
|
||||||
import org.tinylog.Logger
|
import org.tinylog.Logger
|
||||||
import java.sql.DriverManager
|
import java.sql.DriverManager
|
||||||
import java.time.LocalDateTime
|
import java.util.function.Consumer
|
||||||
import java.time.format.DateTimeFormatter
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A class to manage a connection to a MariaDB database.
|
* A class to manage a connection to a MariaDB database.
|
||||||
@@ -28,13 +27,43 @@ class MariaDB (
|
|||||||
var SoundbankList : ArrayList<Soundbank> = ArrayList()
|
var SoundbankList : ArrayList<Soundbank> = ArrayList()
|
||||||
var MessagebankList : ArrayList<Messagebank> = ArrayList()
|
var MessagebankList : ArrayList<Messagebank> = ArrayList()
|
||||||
|
|
||||||
|
companion object {
|
||||||
|
fun ValidDate(date: String): Boolean {
|
||||||
|
// Check if the date is in the format DD/MM/YYYY
|
||||||
|
val regex = Regex("""^\d{2}/\d{2}/\d{4}$""")
|
||||||
|
return regex.matches(date)
|
||||||
|
}
|
||||||
|
fun ValidTime(time: String): Boolean {
|
||||||
|
// Check if the time is in the format HH:MM:SS
|
||||||
|
val regex = Regex("""^\d{2}:\d{2}:\d{2}$""")
|
||||||
|
return regex.matches(time)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
init {
|
init {
|
||||||
try {
|
try {
|
||||||
connection = DriverManager.getConnection("jdbc:mariadb://$address:$port/$dbName", username, password) as Connection
|
connection = DriverManager.getConnection("jdbc:mariadb://$address:$port/$dbName", username, password) as Connection
|
||||||
Logger.info("Connected to MariaDB" as Any)
|
Logger.info("Connected to MariaDB" as Any)
|
||||||
connected = true
|
connected = true
|
||||||
Reload_Soundbank()
|
|
||||||
|
val loadthread = Thread {
|
||||||
|
// Load soundbank and messagebank lists
|
||||||
Reload_Messagebank()
|
Reload_Messagebank()
|
||||||
|
Logger.info { "Messagebank loaded" }
|
||||||
|
Reload_Soundbank()
|
||||||
|
Logger.info { "Soundbank loaded" }
|
||||||
|
|
||||||
|
}
|
||||||
|
loadthread.name = "LoadMariaDBThread"
|
||||||
|
loadthread.isDaemon = true
|
||||||
|
loadthread.start()
|
||||||
|
|
||||||
|
loadthread.join()
|
||||||
|
Logger.info { "Loading MariaDB completed" }
|
||||||
|
Logger.info { "Soundbank count: ${SoundbankList.size}" }
|
||||||
|
Logger.info { "Messagebank count: ${MessagebankList.size}" }
|
||||||
|
|
||||||
|
|
||||||
} catch (e : Exception) {
|
} catch (e : Exception) {
|
||||||
Logger.error("Failed to connect to MariaDB: ${e.message}" as Any)
|
Logger.error("Failed to connect to MariaDB: ${e.message}" as Any)
|
||||||
}
|
}
|
||||||
@@ -55,10 +84,10 @@ class MariaDB (
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get Log from database
|
* Get All Log from database
|
||||||
* @return ArrayList of Log objects
|
* @param consumer A Consumer that will receive the list of logs
|
||||||
*/
|
*/
|
||||||
fun GetLog() : ArrayList<Log> {
|
fun GetLog(consumer : Consumer<ArrayList<Log>>) {
|
||||||
val logList = ArrayList<Log>()
|
val logList = ArrayList<Log>()
|
||||||
try {
|
try {
|
||||||
val statement = connection?.createStatement()
|
val statement = connection?.createStatement()
|
||||||
@@ -76,16 +105,17 @@ class MariaDB (
|
|||||||
} catch (e : Exception) {
|
} catch (e : Exception) {
|
||||||
Logger.error("Error fetching logs: ${e.message}" as Any)
|
Logger.error("Error fetching logs: ${e.message}" as Any)
|
||||||
}
|
}
|
||||||
return logList
|
consumer.accept(logList)
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get Log from database by date
|
* Get Log from database by date
|
||||||
* @param date The date to filter logs by (format: DD/MM/YYYY)
|
* @param date The date to filter logs by (format: DD/MM/YYYY)
|
||||||
* @return ArrayList of Log objects for the specified date
|
* @param consumer A Consumer that will receive the list of logs for the specified date
|
||||||
*/
|
*/
|
||||||
fun GetLog(date : String) : ArrayList<Log> {
|
fun GetLog(date : String, consumer: Consumer<ArrayList<Log>>) {
|
||||||
val logList = ArrayList<Log>()
|
val logList = ArrayList<Log>()
|
||||||
|
if (ValidDate(date)){
|
||||||
try {
|
try {
|
||||||
val statement = connection?.prepareStatement("SELECT * FROM log WHERE datenya = ?")
|
val statement = connection?.prepareStatement("SELECT * FROM log WHERE datenya = ?")
|
||||||
statement?.setString(1, date)
|
statement?.setString(1, date)
|
||||||
@@ -103,23 +133,42 @@ class MariaDB (
|
|||||||
} catch (e : Exception) {
|
} catch (e : Exception) {
|
||||||
Logger.error("Error fetching logs for date $date: ${e.message}" as Any)
|
Logger.error("Error fetching logs for date $date: ${e.message}" as Any)
|
||||||
}
|
}
|
||||||
return logList
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
consumer.accept(logList)
|
||||||
* Get Log from database by date
|
}
|
||||||
* @param date The date to filter logs by (as LocalDateTime)
|
|
||||||
* @return ArrayList of Log objects for the specified date
|
fun GetLog(date : String, filter : String, consumer: Consumer<ArrayList<Log>>) {
|
||||||
*/
|
val logList = ArrayList<Log>()
|
||||||
fun GetLog(date : LocalDateTime) : ArrayList<Log> {
|
if (ValidDate(date)){
|
||||||
val datenya = DateTimeFormatter.ofPattern("DD/MM/YYYY").format(date)
|
try {
|
||||||
return GetLog(datenya)
|
val statement = connection?.prepareStatement("SELECT * FROM log WHERE datenya = ? AND description LIKE ?")
|
||||||
|
statement?.setString(1, date)
|
||||||
|
statement?.setString(2, "%$filter%")
|
||||||
|
val resultSet = statement?.executeQuery()
|
||||||
|
while (resultSet?.next() == true) {
|
||||||
|
val log = Log(
|
||||||
|
resultSet.getLong("index").toULong(),
|
||||||
|
resultSet.getString("datenya"),
|
||||||
|
resultSet.getString("timenya"),
|
||||||
|
resultSet.getString("machine"),
|
||||||
|
resultSet.getString("description")
|
||||||
|
)
|
||||||
|
logList.add(log)
|
||||||
|
}
|
||||||
|
} catch (e : Exception) {
|
||||||
|
Logger.error("Error fetching logs for date $date with filter $filter: ${e.message}" as Any)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
consumer.accept(logList)
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Reloads the soundbank list from the database.
|
* Reloads the soundbank list from the database.
|
||||||
*/
|
*/
|
||||||
private fun Reload_Soundbank() {
|
private fun Reload_Soundbank() {
|
||||||
|
|
||||||
SoundbankList.clear()
|
SoundbankList.clear()
|
||||||
try {
|
try {
|
||||||
val statement = connection?.createStatement()
|
val statement = connection?.createStatement()
|
||||||
@@ -153,12 +202,13 @@ class MariaDB (
|
|||||||
val messagebank = Messagebank(
|
val messagebank = Messagebank(
|
||||||
resultSet.getLong("index").toUInt(),
|
resultSet.getLong("index").toUInt(),
|
||||||
resultSet.getString("Description"),
|
resultSet.getString("Description"),
|
||||||
resultSet.getString("TAG"),
|
|
||||||
resultSet.getInt("Category").toUInt(),
|
|
||||||
resultSet.getString("Language"),
|
resultSet.getString("Language"),
|
||||||
resultSet.getString("VoiceType"),
|
resultSet.getInt("ANN_ID").toUInt(),
|
||||||
resultSet.getString("Path")
|
resultSet.getString("Voice_Type"),
|
||||||
|
resultSet.getString("Message_Detail"),
|
||||||
|
resultSet.getString("Message_TAGS")
|
||||||
)
|
)
|
||||||
|
|
||||||
MessagebankList.add(messagebank)
|
MessagebankList.add(messagebank)
|
||||||
}
|
}
|
||||||
} catch (e : Exception) {
|
} catch (e : Exception) {
|
||||||
|
|||||||
Reference in New Issue
Block a user