Commit 569e276b authored by Szabolcs Gyurko's avatar Szabolcs Gyurko
Browse files

Changed dbConfig handling to slick's HasDatabaseConfigProvider mixin.

parent ef1b7cf4
......@@ -6,7 +6,7 @@ import javax.inject.{Inject, Singleton}
import akka.actor.UntypedActor
import entities.{ChunkRecord, ChunksTable, JobsTable, QueueTable}
import play.api.Logger
import play.api.db.slick.DatabaseConfigProvider
import play.api.db.slick.{DatabaseConfigProvider, HasDatabaseConfigProvider}
import sget2.{Defaults, PersistEvent, SGet2}
import slick.driver.JdbcProfile
......@@ -18,7 +18,10 @@ import scala.concurrent.duration.Duration
* Created by sgyurko on 25/08/2016.
*/
@Singleton
class DataPersister @Inject() (private val dbConfigProvider: DatabaseConfigProvider, private val sget2: SGet2) extends UntypedActor {
class DataPersister @Inject() (protected val dbConfigProvider: DatabaseConfigProvider, private val sget2: SGet2)
extends UntypedActor with HasDatabaseConfigProvider[JdbcProfile] {
import driver.api._
@volatile
private var saveRequested: Boolean = false
......@@ -73,8 +76,6 @@ class DataPersister @Inject() (private val dbConfigProvider: DatabaseConfigProvi
/* Persists the queue data to DB asynchronously */
private def persist(event: PersistEvent): Unit = {
val dbConfig = dbConfigProvider.get[JdbcProfile]
import dbConfig.driver.api._
val jobs = TableQuery[JobsTable]
val chunks = TableQuery[ChunksTable]
val queue = TableQuery[QueueTable]
......
......@@ -6,7 +6,7 @@ import entities.{JobRecord, JobsTable, QueueRecord, QueueTable}
import play.api.Logger
import play.api.data.Form
import play.api.data.Forms._
import play.api.db.slick.DatabaseConfigProvider
import play.api.db.slick.{DatabaseConfigProvider, HasDatabaseConfigProvider}
import play.api.i18n.{I18nSupport, MessagesApi}
import play.api.libs.json.{JsResult, Json}
import play.api.mvc.{Action, Controller, Result}
......@@ -21,9 +21,9 @@ import scala.concurrent.Future
*/
final case class AddJobData(url: String, path: String, user: Option[String] = None, pass: Option[String] = None, maxThreads: Option[Int] = Some(4), maxBandwidth: Option[Int] = None)
class AddJob @Inject() (val messagesApi: MessagesApi, private val dbConfigProvider: DatabaseConfigProvider, private val sget2: SGet2) extends Controller with I18nSupport {
private val dbConfig = dbConfigProvider.get[JdbcProfile]
import dbConfig.driver.api._
class AddJob @Inject() (val messagesApi: MessagesApi, protected val dbConfigProvider: DatabaseConfigProvider, private val sget2: SGet2) extends Controller with I18nSupport with HasDatabaseConfigProvider[JdbcProfile] {
import driver.api._
private val jobs = TableQuery[JobsTable]
private val queue = TableQuery[QueueTable]
......
......@@ -3,7 +3,7 @@ package controllers
import javax.inject.Inject
import entities.{ChunksTable, JobsTable, QueueTable}
import play.api.db.slick.DatabaseConfigProvider
import play.api.db.slick.{DatabaseConfigProvider, HasDatabaseConfigProvider}
import play.api.i18n.{I18nSupport, MessagesApi}
import play.api.libs.json.Json
import play.api.mvc.{Action, Controller}
......@@ -20,9 +20,9 @@ final case class JobJson(state: String, currentSpeed: Double, lastCheck: Long, p
bandwidthLimit: Int, startTime: Long, finishTime: Long, size: Long, alive: Boolean, activeThreads: Int,
url: String, path: String, id: Int, downloaded: Long, chunkMatrix: DownloadObjectMapSettings)
class Job @Inject() (val messagesApi: MessagesApi, private val dbConfigProvider: DatabaseConfigProvider, private val sget2: SGet2) extends Controller with I18nSupport {
private val dbConfig = dbConfigProvider.get[JdbcProfile]
import dbConfig.driver.api._
class Job @Inject() (val messagesApi: MessagesApi, protected val dbConfigProvider: DatabaseConfigProvider, private val sget2: SGet2) extends Controller with I18nSupport with HasDatabaseConfigProvider[JdbcProfile]{
import driver.api._
private val jobs = TableQuery[JobsTable]
private val queue = TableQuery[QueueTable]
private val chunks = TableQuery[ChunksTable]
......
......@@ -4,20 +4,19 @@ import javax.inject.Inject
import play.api.data.Form
import play.api.data.Forms._
import play.api.db.slick.DatabaseConfigProvider
import play.api.i18n.{I18nSupport, MessagesApi}
import play.api.mvc.{Action, Controller}
import sget2.{Defaults, SGet2}
import scala.util.Try
import scala.concurrent.ExecutionContext.Implicits.global
import scala.util.Try
/**
* Created by sgyurko on 02/09/2016.
*/
final case class SettingsModel(downloadPath: Option[String],
maxActiveJobs: Option[Int], user: Option[String], pass: Option[String])
class Settings @Inject() (val messagesApi: MessagesApi, private val dbConfigProvider: DatabaseConfigProvider, private val sget2: SGet2) extends Controller with I18nSupport {
class Settings @Inject() (val messagesApi: MessagesApi, private val sget2: SGet2) extends Controller with I18nSupport {
private val settingsPostForm = Form(
mapping(
"downloadPath" optional(text),
......
......@@ -2,7 +2,7 @@ package sget2
import entities.{ChunkRecord, ChunksTable, JobsTable, QueueTable}
import play.api.Logger
import play.api.db.slick.DatabaseConfigProvider
import play.api.db.slick.{DatabaseConfigProvider, HasDatabaseConfigProvider}
import slick.driver.JdbcProfile
import workers.{FtpWorker, HttpWorker}
......@@ -17,12 +17,13 @@ case class DownloadQueueSettings(jobList: List[DownloadJobSettings],
* Created by GYURKS on 14/01/2015.
* @author GYURKS
*/
class DownloadQueue (private val sget2: SGet2, private val dbConfigProvider: DatabaseConfigProvider) {
class DownloadQueue (private val sget2: SGet2, protected val dbConfigProvider: DatabaseConfigProvider) extends HasDatabaseConfigProvider[JdbcProfile] {
import driver.api._
val jobList = new ListBuffer[DownloadJob]()
private var _bandwidthLimit: Int = 0
private val threadGroup = new ThreadGroup("DownloadQueue")
private val dbConfig = dbConfigProvider.get[JdbcProfile]
import dbConfig.driver.api._
private val chunks = TableQuery[ChunksTable]
private val queue = TableQuery[QueueTable]
private val jobs = TableQuery[JobsTable]
......
......@@ -4,7 +4,7 @@ import javax.inject.{Inject, Singleton}
import akka.actor.{ActorRef, ActorSystem}
import entities.{SettingsRecord, SettingsTable}
import play.api.db.slick.DatabaseConfigProvider
import play.api.db.slick.{DatabaseConfigProvider, HasDatabaseConfigProvider}
import slick.driver.JdbcProfile
import scala.concurrent.Await
......@@ -14,11 +14,11 @@ import scala.concurrent.duration.Duration
* Created by sgyurko on 31/08/2016.
*/
@Singleton
class SGet2 @Inject() (val dbConfigProvider: DatabaseConfigProvider, val actorSystem: ActorSystem) {
class SGet2 @Inject() (protected val dbConfigProvider: DatabaseConfigProvider, val actorSystem: ActorSystem) extends HasDatabaseConfigProvider[JdbcProfile] {
import driver.api._
private val eventBus = new SGet2EventBus
private val dbConfig = dbConfigProvider.get[JdbcProfile]
val downloadQueue = new DownloadQueue(this, dbConfigProvider)
import dbConfig.driver.api._
import scala.concurrent.ExecutionContext.Implicits.global
......
Markdown is supported
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