From fe4483f5c3282bffa336573e4df373a9497c4919 Mon Sep 17 00:00:00 2001 From: Jonas Reinwald Date: Sat, 3 Nov 2018 14:52:06 +0100 Subject: [PATCH] add mongo-db dependency and create collection in controller --- build.sbt | 2 ++ src/main/resources/logback.xml | 4 +++- .../controllerBaseImpl/Controller.scala | 11 ++++++++++- 3 files changed, 15 insertions(+), 2 deletions(-) diff --git a/build.sbt b/build.sbt index d690cf9..ba883ab 100755 --- a/build.sbt +++ b/build.sbt @@ -21,3 +21,5 @@ libraryDependencies += "ch.qos.logback" % "logback-classic" % "1.2.3" libraryDependencies += "com.typesafe.akka" %% "akka-http" % "10.0.0" libraryDependencies += "com.typesafe.scala-logging" %% "scala-logging" % "3.9.0" + +libraryDependencies += "org.mongodb.scala" %% "mongo-scala-driver" % "2.3.0" diff --git a/src/main/resources/logback.xml b/src/main/resources/logback.xml index f67b6c2..3abfe6d 100644 --- a/src/main/resources/logback.xml +++ b/src/main/resources/logback.xml @@ -18,4 +18,6 @@ - \ No newline at end of file + + + diff --git a/src/main/scala/de/htwg/se/sudoku/controller/controllerComponent/controllerBaseImpl/Controller.scala b/src/main/scala/de/htwg/se/sudoku/controller/controllerComponent/controllerBaseImpl/Controller.scala index f1fe0ac..68d2f83 100644 --- a/src/main/scala/de/htwg/se/sudoku/controller/controllerComponent/controllerBaseImpl/Controller.scala +++ b/src/main/scala/de/htwg/se/sudoku/controller/controllerComponent/controllerBaseImpl/Controller.scala @@ -10,8 +10,9 @@ import de.htwg.se.sudoku.model.fileIoComponent.FileIOInterface import de.htwg.se.sudoku.model.gridComponent.GridInterface import de.htwg.se.sudoku.util.UndoManager -import scala.util.{Success, Failure} +import scala.util.{Failure, Success} import com.typesafe.scalalogging.{LazyLogging, Logger} +import org.mongodb.scala.{MongoClient, MongoDatabase} class Controller @Inject()(var grid: GridInterface) extends ControllerInterface @@ -24,6 +25,14 @@ class Controller @Inject()(var grid: GridInterface) val injector = Guice.createInjector(new SudokuModule) val fileIo = injector.instance[FileIOInterface] + // database connection (could be injected later if database is running on another server) + // connects to the default server localhost on port 27017 + private val mongoClient: MongoClient = MongoClient() + private val db: MongoDatabase = mongoClient.getDatabase("sudoku-in-scala") + private val collection = db.getCollection("sudoku-in-scala-col") + // uncomment to delete the current database + //Await.result(collection.drop().toFuture(), Duration.Inf) + def createEmptyGrid: Unit = { grid.size match { case 1 => grid = injector.instance[GridInterface](Names.named("tiny"))