-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
perf(db): use
HikariCP
instead of JDBC DriverManager
for manage c…
…onnection
- Loading branch information
1 parent
2cf2b39
commit 6bf38aa
Showing
26 changed files
with
157 additions
and
148 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
55 changes: 24 additions & 31 deletions
55
src/main/scala/net/yoshinorin/qualtet/tasks/CreateAuthor.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,53 +1,46 @@ | ||
package net.yoshinorin.qualtet.tasks | ||
|
||
import cats.effect.IO | ||
import cats.implicits.catsSyntaxEq | ||
import doobie.ConnectionIO | ||
import doobie.util.transactor.Transactor.Aux | ||
import cats.effect.{ExitCode, IO, IOApp} | ||
import org.slf4j.LoggerFactory | ||
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder | ||
import net.yoshinorin.qualtet.domains.authors.{Author, AuthorDisplayName, AuthorName, AuthorRepository, AuthorService, BCryptPassword} | ||
import net.yoshinorin.qualtet.infrastructure.db.doobie.DoobieExecuter | ||
import net.yoshinorin.qualtet.Modules.* | ||
import net.yoshinorin.qualtet.domains.authors.{Author, AuthorDisplayName, AuthorName, BCryptPassword} | ||
import net.yoshinorin.qualtet.Modules | ||
import net.yoshinorin.qualtet.syntax.* | ||
import net.yoshinorin.qualtet.domains.authors.ResponseAuthor | ||
|
||
import cats.effect.unsafe.implicits.global | ||
import net.yoshinorin.qualtet.infrastructure.db.doobie.DoobieTransactor | ||
|
||
object CreateAuthor { | ||
object CreateAuthor extends IOApp { | ||
|
||
private val logger = LoggerFactory.getLogger(this.getClass) | ||
|
||
val doobieTransactor: DoobieTransactor[Aux] = summon[DoobieTransactor[Aux]] | ||
|
||
given dbContext: DoobieExecuter = new DoobieExecuter(doobieTransactor.make(config.db)) | ||
val authorRepository: AuthorRepository[ConnectionIO] = summon[AuthorRepository[ConnectionIO]] | ||
val authorService = new AuthorService(authorRepository) | ||
|
||
def main(args: Array[String]): Unit = { | ||
def run(args: List[String]): IO[ExitCode] = { | ||
if (args.length =!= 3) { | ||
throw new IllegalArgumentException("args must be three length.") | ||
} | ||
|
||
// https://docs.spring.io/spring-security/site/docs/current/reference/html5/#authentication-password-storage-bcrypt | ||
val bcryptPasswordEncoder = new BCryptPasswordEncoder() | ||
(for { | ||
author <- authorService.create( | ||
Author(name = AuthorName(args(0)), displayName = AuthorDisplayName(args(1)), password = BCryptPassword(bcryptPasswordEncoder.encode(args(2)))) | ||
) | ||
} yield author) | ||
.handleErrorWith { e => | ||
IO.pure(e) | ||
} | ||
.unsafeRunSync() match { | ||
case a: ResponseAuthor => | ||
logger.info(s"author created: ${a.asJson}") | ||
logger.info("shutting down...") | ||
case e: Exception => | ||
logger.error(e.getMessage) | ||
case _ => | ||
logger.error("unknown error") | ||
|
||
Modules.transactorResource.use { tx => | ||
val modules = new Modules(tx) | ||
(for { | ||
author <- modules.authorService.create( | ||
Author(name = AuthorName(args(0)), displayName = AuthorDisplayName(args(1)), password = BCryptPassword(bcryptPasswordEncoder.encode(args(2)))) | ||
) | ||
_ <- IO(logger.info(s"author created: ${author.asJson}")) | ||
_ <- IO(println(s"author created: ${author.asJson}")) | ||
} yield author) | ||
.handleErrorWith { e => | ||
e match | ||
case e: Exception => | ||
IO(logger.error(e.getMessage)) | ||
case _ => | ||
IO(logger.error("unknown error")) | ||
} | ||
.unsafeRunSync() // FIXME | ||
IO(ExitCode.Success) | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
src/test/scala/net/yoshinorin/qualtet/cache/CacheServiceSpec.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1 change: 0 additions & 1 deletion
1
src/test/scala/net/yoshinorin/qualtet/domains/archives/ArchiveServiceSpec.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.