-
Notifications
You must be signed in to change notification settings - Fork 5
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
WIP : begin working on gridfs implementation #29
base: master
Are you sure you want to change the base?
Changes from 1 commit
6aed298
daff698
2711ffb
c6b1e2b
617ecd3
667e18e
954ad72
661d443
da6ee9a
7c29a2e
c656a44
2706535
fa86969
4a6e9d7
b6ee310
6b4aee1
bf33963
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,37 +1,49 @@ | ||
/* | ||
* Copyright (C) 2018-2019 Zengularity SA (FaberNovel Technologies) <https://www.zengularity.com> | ||
*/ | ||
// /* | ||
// * Copyright (C) 2018-2019 Zengularity SA (FaberNovel Technologies) <https://www.zengularity.com> | ||
// */ | ||
package com.zengularity.benji.gridfs | ||
|
||
import reactivemongo.api.MongoConnection | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Il y a un import |
||
|
||
import reactivemongo.api.gridfs.GridFS | ||
import reactivemongo.api.BSONSerializationPack | ||
import scala.concurrent.{ ExecutionContext, Future } | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sur la forme, J'essaie de me tenir à un ordre pour les imports, en groupant d'abord les importe JVM/Java classique, après les imports scalalib ( Adaptation des règles javastyle, c'est configurable dans Intellij (Order import) |
||
import scala.util.{ Failure, Success, Try } | ||
|
||
import com.zengularity.benji.exception.BenjiUnknownError | ||
import scala.util.Success | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Double import |
||
|
||
final class GridFSTransport(driver: reactivemongo.api.MongoDriver, val gridfsdb: Future[GridFS[BSONSerializationPack.type]]) { | ||
final class GridFSTransport(driver: reactivemongo.api.MongoDriver, connection: MongoConnection, mongoUri: MongoConnection.ParsedURI) { | ||
def close(): Unit = { | ||
driver.close() | ||
} | ||
|
||
def gridfs(prefix: String)(implicit ec: ExecutionContext): Future[GridFS[BSONSerializationPack.type]] = { | ||
mongoUri.db match { | ||
case Some(name) => | ||
for { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
db <- connection.database(name) | ||
gridfs = GridFS[BSONSerializationPack.type](db, prefix) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Quelle différence entre avoir cette ligne et avoir |
||
} yield gridfs | ||
|
||
case None => | ||
Future.failed(new BenjiUnknownError(s"Couldn't get the db from $mongoUri")) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. La formulation actuelle des erreurs est plutôt "Fails to ..." |
||
} | ||
} | ||
} | ||
|
||
object GridFSTransport { | ||
def apply(uri: String, prefix: String)(implicit ec: ExecutionContext): GridFSTransport = { | ||
def apply(uri: String)(implicit ec: ExecutionContext): Try[GridFSTransport] = { | ||
val driver = new reactivemongo.api.MongoDriver | ||
|
||
val gridfsdb = for { | ||
mongoUri <- Future.fromTry(MongoConnection.parseURI(uri)) | ||
val res = for { | ||
mongoUri <- MongoConnection.parseURI(uri) | ||
con = driver.connection(mongoUri) | ||
gridfs <- mongoUri.db match { | ||
case Some(name) => | ||
con.database(name).map(db => | ||
GridFS[BSONSerializationPack.type](db, prefix)) | ||
case None => Future.failed(new BenjiUnknownError(s"Couldn't get the db from $mongoUri")) | ||
} | ||
} yield gridfs | ||
|
||
new GridFSTransport(driver, gridfsdb) | ||
} yield (mongoUri, con) | ||
val (mongoUri, connection) = (res.map(_._1), res.map(_._2)) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Pourquoi sortir du |
||
connection match { | ||
case Success(connection) => new Success(GridFSTransport(driver, connection, mongoUri)) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
case Failure(_) => Failure[GridFSTransport](new BenjiUnknownError(s"Couldn't create the connection to $uri")) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Le détails de l'erreur/root cause est perdu (cf https://github.com/zengularity/benji/blob/master/core/src/main/scala/exception/BenjiException.scala#L17 ) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Formulation message "Fails to ..." |
||
} | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
?