mirror of
https://github.com/OpenBankProject/OBP-API.git
synced 2026-02-06 19:16:53 +00:00
feature/Tweak the function getDbConnectionParameters 2
This commit is contained in:
parent
937d15f708
commit
884609b983
@ -3,8 +3,16 @@ package code.api.util
|
||||
import code.api.Constant
|
||||
|
||||
object DBUtil {
|
||||
def dbUrl: String = APIUtil.getPropsValue("db.url") openOr Constant.h2DatabaseDefaultUrlValue
|
||||
|
||||
def getDbConnectionParameters: (String, String, String) = {
|
||||
val dbUrl = APIUtil.getPropsValue("db.url") openOr Constant.h2DatabaseDefaultUrlValue
|
||||
dbUrl.contains("jdbc:h2") match {
|
||||
case true => getH2DbConnectionParameters
|
||||
case false => getOtherDbConnectionParameters
|
||||
}
|
||||
}
|
||||
|
||||
private def getOtherDbConnectionParameters: (String, String, String) = {
|
||||
val usernameAndPassword = dbUrl.split("\\?").filter(_.contains("user")).mkString
|
||||
val username = usernameAndPassword.split("&").filter(_.contains("user")).mkString.split("=")(1)
|
||||
val password = usernameAndPassword.split("&").filter(_.contains("password")).mkString.split("=")(1)
|
||||
@ -12,4 +20,12 @@ object DBUtil {
|
||||
val dbPassword = APIUtil.getPropsValue("db.password").getOrElse(password)
|
||||
(dbUrl, dbUser, dbPassword)
|
||||
}
|
||||
// H2 database has specific bd url string which is different compared to other databases
|
||||
private def getH2DbConnectionParameters: (String, String, String) = {
|
||||
val username = dbUrl.split(";").filter(_.contains("user")).toList.headOption.map(_.split("=")(1))
|
||||
val password = dbUrl.split(";").filter(_.contains("password")).toList.headOption.map(_.split("=")(1))
|
||||
val dbUser = APIUtil.getPropsValue("db.user").orElse(username)
|
||||
val dbPassword = APIUtil.getPropsValue("db.password").orElse(password)
|
||||
(dbUrl, dbUser.getOrElse(""), dbPassword.getOrElse(""))
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user