Unverified Commit f45b6ed6 authored by Sebastian Schüpbach's avatar Sebastian Schüpbach
Browse files

provide basic db communication means

parent a18265c7
......@@ -25,6 +25,7 @@ lazy val root = (project in file("."))
log4jCore,
log4jSlf4j,
log4jScala,
mariadbJdbcDriver,
memobaseServiceUtils,
scalatic,
scalaTest % Test)
......
......@@ -28,6 +28,7 @@ object Dependencies {
lazy val log4jCore = "org.apache.logging.log4j" % "log4j-core" % log4jV
lazy val log4jScala = "org.apache.logging.log4j" %% "log4j-api-scala" % "11.0"
lazy val log4jSlf4j = "org.apache.logging.log4j" % "log4j-slf4j-impl" % log4jV
lazy val mariadbJdbcDriver = "org.mariadb.jdbc" % "mariadb-java-client" % "2.6.0"
lazy val memobaseServiceUtils = "org.memobase" % "memobase-service-utilities" % "1.2.1"
lazy val scalatic = "org.scalactic" %% "scalactic" % scalatestV
lazy val scalaTest = "org.scalatest" %% "scalatest" % scalatestV
......
/*
* Extracts media files from Fedora repository
* Copyright (C) 2020 Memoriav
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package org.memobase.utils
import java.sql.{Connection, DriverManager}
import org.apache.logging.log4j.scala.Logging
class DBHandler(connection: Connection, table: String) {
def insert(sig: String, uri: String): Boolean = {
val st = connection.createStatement()
val res = st.executeQuery(s"UPDATE $table SET uri=$uri WHERE sig=$sig")
}
def close(): Unit = {
connection.close()
}
}
object DBHandler extends Logging {
def apply(host: String, port: Int, user: String, password: String, table: String): DBHandler = {
logger.info(s"Connecting to mediaserver database on $host:$port")
val connection = DriverManager.getConnection(s"jdbc:mariadb://$host:$port/DB?user=$user&password=$password");
new DBHandler(connection, table)
}
}
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment