Skip to content
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

Slick/JDBC create SlickSession from Database and Profile. #1509

Closed
Kreinoee opened this issue Feb 15, 2019 · 5 comments
Closed

Slick/JDBC create SlickSession from Database and Profile. #1509

Kreinoee opened this issue Feb 15, 2019 · 5 comments
Labels
Milestone

Comments

@Kreinoee
Copy link
Contributor

Short description

It should be possible to create a SlickSession, from a Database object and a Profile object.

Details

A SlickSession is basically just a wrapper arround a Database and a Profile, but you ironically, you cannot create it, if these two objects are your starting point. Currently its only possiby to create a SlickSession from a Config or a DatabaseConfig.

I have a situation, where I use another Library, that supplies a Database object to me, for using in unit tests. So my problem is, that I have the Database object, and now what Profile to use with it, and therefore have the two things that makes up a SlickSession, but I have no easy way of actually creating the needed SlickSession instance.

I would suggest creating an extra forDatabaseAndProfile factory method, to SlickSessions companion object. I have created a Local fork to test it out, and it works fine, so I can provide it as a pull request on the other side of the weekend.

@ennru
Copy link
Member

ennru commented Feb 18, 2019

Yes, this sounds useful (even the forConfig hasn't been around too long). It would be great to get in your PR for this.

@ennru ennru added the p:slick label Feb 18, 2019
Kreinoee added a commit to Kreinoee/alpakka that referenced this issue Oct 24, 2019
* Added the method SlickSession.forDbAndProfile(db: JdbcBackend#Database, profile: JdbcProfile)
@Kreinoee
Copy link
Contributor Author

Sorry for the delay, but gut stuck on other projects.

I may need some help here. I have made a fix, that works for me now. However for being able to build alpakka at all, I had to remove a lot of stuff from the build files. As you contributions policies require, I would like add some documentation for this new way of creating a SlickSession. However when i try to run docs/previewSite sbt task, I get a lot of errors like:

error] Failed to resolve [akka.stream.alpakka.sqs.SqsAckResultEntry] because property [scaladoc.akka.stream.alpakka.base_url] contains an invalid URL [//] at /home/anders/cloudSolution/projects/alpakka/docs/src/main/paradox/sqs.md:292
[error] `SqsAckFlow.grouped` batches actions on their type and forwards a @scaladoc[`SqsAckResultEntry`](akka.stream.alpakka.sqs.SqsAckResultEntry) 

This could very well be caused by all the stuff that I have deleted in the build file, but if I revert the changes in the build files, or just try on a fresh clone of alpakka, I cannot even start sbt, due to this error:

/tmp/alpakka/ sbt
OpenJDK 64-Bit Server VM warning: ignoring option MaxPermSize=2G; support was removed in 8.0
[info] Loading global plugins from /home/anders/.sbt/1.0/plugins
[info] Loading settings for project alpakka-build from plugins.sbt ...
[info] Loading project definition from /tmp/alpakka/project
[info] Updating ProjectRef(uri("file:/tmp/alpakka/project/"), "alpakka-build")...
[warn]  module not found: com.typesafe#sbt-mima-plugin;0.3.0
[warn] ==== typesafe-ivy-releases: tried
[warn]   https://repo.typesafe.com/typesafe/ivy-releases/com.typesafe/sbt-mima-plugin/scala_2.12/sbt_1.0/0.3.0/ivys/ivy.xml
[warn] ==== sbt-plugin-releases: tried
[warn]   https://repo.scala-sbt.org/scalasbt/sbt-plugin-releases/com.typesafe/sbt-mima-plugin/scala_2.12/sbt_1.0/0.3.0/ivys/ivy.xml
[warn] ==== local: tried
[warn]   /home/anders/.ivy2/local/com.typesafe/sbt-mima-plugin/scala_2.12/sbt_1.0/0.3.0/ivys/ivy.xml
[warn] ==== public: tried
[warn]   https://repo1.maven.org/maven2/com/typesafe/sbt-mima-plugin_2.12_1.0/0.3.0/sbt-mima-plugin-0.3.0.pom
[warn] ==== local-preloaded-ivy: tried
[warn]   /home/anders/.sbt/preloaded/com.typesafe/sbt-mima-plugin/0.3.0/ivys/ivy.xml
[warn] ==== local-preloaded: tried
[warn]   file:////home/anders/.sbt/preloaded/com/typesafe/sbt-mima-plugin_2.12_1.0/0.3.0/sbt-mima-plugin-0.3.0.pom
[warn] ==== bintray-2m-sbt-plugins: tried
[warn]   https://dl.bintray.com/2m/sbt-plugins/com.typesafe/sbt-mima-plugin/scala_2.12/sbt_1.0/0.3.0/ivys/ivy.xml
[warn]  ::::::::::::::::::::::::::::::::::::::::::::::
[warn]  ::          UNRESOLVED DEPENDENCIES         ::
[warn]  ::::::::::::::::::::::::::::::::::::::::::::::
[warn]  :: com.typesafe#sbt-mima-plugin;0.3.0: not found
[warn]  ::::::::::::::::::::::::::::::::::::::::::::::
[warn] 
[warn]  Note: Some unresolved dependencies have extra attributes.  Check that these dependencies exist with the requested attributes.
[warn]          com.typesafe:sbt-mima-plugin:0.3.0 (scalaVersion=2.12, sbtVersion=1.0)
[warn] 
[warn]  Note: Unresolved dependencies path:
[warn]          com.typesafe:sbt-mima-plugin:0.3.0 (scalaVersion=2.12, sbtVersion=1.0) (/tmp/alpakka/project/plugins.sbt#L10-11)
[warn]            +- default:alpakka-build:0.1.0-SNAPSHOT (scalaVersion=2.12, sbtVersion=1.0)
[error] sbt.librarymanagement.ResolveException: unresolved dependency: com.typesafe#sbt-mima-plugin;0.3.0: not found
[error]         at sbt.internal.librarymanagement.IvyActions$.resolveAndRetrieve(IvyActions.scala:332)
[error]         at sbt.internal.librarymanagement.IvyActions$.$anonfun$updateEither$1(IvyActions.scala:208)
[error]         at sbt.internal.librarymanagement.IvySbt$Module.$anonfun$withModule$1(Ivy.scala:239)
[error]         at sbt.internal.librarymanagement.IvySbt.$anonfun$withIvy$1(Ivy.scala:204)
[error]         at sbt.internal.librarymanagement.IvySbt.sbt$internal$librarymanagement$IvySbt$$action$1(Ivy.scala:70)
[error]         at sbt.internal.librarymanagement.IvySbt$$anon$3.call(Ivy.scala:77)
[error]         at xsbt.boot.Locks$GlobalLock.withChannel$1(Locks.scala:95)
[error]         at xsbt.boot.Locks$GlobalLock.xsbt$boot$Locks$GlobalLock$$withChannelRetries$1(Locks.scala:80)
[error]         at xsbt.boot.Locks$GlobalLock$$anonfun$withFileLock$1.apply(Locks.scala:99)
[error]         at xsbt.boot.Using$.withResource(Using.scala:10)
[error]         at xsbt.boot.Using$.apply(Using.scala:9)
[error]         at xsbt.boot.Locks$GlobalLock.ignoringDeadlockAvoided(Locks.scala:60)
[error]         at xsbt.boot.Locks$GlobalLock.withLock(Locks.scala:50)
[error]         at xsbt.boot.Locks$.apply0(Locks.scala:31)
[error]         at xsbt.boot.Locks$.apply(Locks.scala:28)
[error]         at sbt.internal.librarymanagement.IvySbt.withDefaultLogger(Ivy.scala:77)
[error]         at sbt.internal.librarymanagement.IvySbt.withIvy(Ivy.scala:199)
[error]         at sbt.internal.librarymanagement.IvySbt.withIvy(Ivy.scala:196)
[error]         at sbt.internal.librarymanagement.IvySbt$Module.withModule(Ivy.scala:238)
[error]         at sbt.internal.librarymanagement.IvyActions$.updateEither(IvyActions.scala:193)
[error]         at sbt.librarymanagement.ivy.IvyDependencyResolution.update(IvyDependencyResolution.scala:20)
[error]         at sbt.librarymanagement.DependencyResolution.update(DependencyResolution.scala:56)
[error]         at sbt.internal.LibraryManagement$.resolve$1(LibraryManagement.scala:45)
[error]         at sbt.internal.LibraryManagement$.$anonfun$cachedUpdate$12(LibraryManagement.scala:93)
[error]         at sbt.util.Tracked$.$anonfun$lastOutput$1(Tracked.scala:68)
[error]         at sbt.internal.LibraryManagement$.$anonfun$cachedUpdate$19(LibraryManagement.scala:106)
[error]         at scala.util.control.Exception$Catch.apply(Exception.scala:224)
[error]         at sbt.internal.LibraryManagement$.$anonfun$cachedUpdate$11(LibraryManagement.scala:106)
[error]         at sbt.internal.LibraryManagement$.$anonfun$cachedUpdate$11$adapted(LibraryManagement.scala:89)
[error]         at sbt.util.Tracked$.$anonfun$inputChanged$1(Tracked.scala:149)
[error]         at sbt.internal.LibraryManagement$.cachedUpdate(LibraryManagement.scala:120)
[error]         at sbt.Classpaths$.$anonfun$updateTask$5(Defaults.scala:2561)
[error]         at scala.Function1.$anonfun$compose$1(Function1.scala:44)
[error]         at sbt.internal.util.$tilde$greater.$anonfun$$u2219$1(TypeFunctions.scala:40)
[error]         at sbt.std.Transform$$anon$4.work(System.scala:67)
[error]         at sbt.Execute.$anonfun$submit$2(Execute.scala:269)
[error]         at sbt.internal.util.ErrorHandling$.wideConvert(ErrorHandling.scala:16)
[error]         at sbt.Execute.work(Execute.scala:278)
[error]         at sbt.Execute.$anonfun$submit$1(Execute.scala:269)
[error]         at sbt.ConcurrentRestrictions$$anon$4.$anonfun$submitValid$1(ConcurrentRestrictions.scala:178)
[error]         at sbt.CompletionService$$anon$2.call(CompletionService.scala:37)
[error]         at java.util.concurrent.FutureTask.run(FutureTask.java:266)
[error]         at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
[error]         at java.util.concurrent.FutureTask.run(FutureTask.java:266)
[error]         at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
[error]         at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
[error]         at java.lang.Thread.run(Thread.java:748)
[error] (update) sbt.librarymanagement.ResolveException: unresolved dependency: com.typesafe#sbt-mima-plugin;0.3.0: not found
Project loading failed: (r)etry, (q)uit, (l)ast, or (i)gnore? 

Is there some global repo there should be set in sbt or something?

@ennru
Copy link
Member

ennru commented Oct 25, 2019

There is a problem with downloading the Mima plugin. Try this workaround lightbend-labs/mima#422 (comment)

@ennru
Copy link
Member

ennru commented Oct 25, 2019

You know what? It is fixed now. No need to work around it anymore.

Kreinoee added a commit to Kreinoee/alpakka that referenced this issue Oct 31, 2019
* Moved the method SlickSession.forDbAndProfile(db: JdbcBackend#Database, profile: JdbcProfile) to the scaladsl version of SlickSession, as slick offers no good Java API for creating a Database instance.
* Created abstract class SlickSessionFactory, and letting both the javadsl and scaladsl version of SlickSession object extends it, to avoid duplicating the shared factory methods.
* Made the unit test for the factory method close the connection it creates, and the end of the test.
* Added documentation about the new way of creating a SlickSession instance.
Kreinoee added a commit to Kreinoee/alpakka that referenced this issue Nov 6, 2019
    * Added line for ignoring akka.stream.alpakka.slick.javadsl.SlickSession$SlickSessionImpl.
    * Added line for ignoring akka.stream.alpakka.slick.scaladsl.package.SlickSession.
@ennru
Copy link
Member

ennru commented Mar 30, 2020

This was implemented with #1996.

@ennru ennru closed this as completed Mar 30, 2020
@ennru ennru added this to the 2.0.0-M1 milestone Mar 30, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants