-
Notifications
You must be signed in to change notification settings - Fork 645
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: Support PreparedStatement
use in Java DSL
#2318
Conversation
Thank you for suggesting this, it's a great improvement for the Java DSL. I wonder if there is a way to create the prepared statement only once and update it for every element. Maybe @renatocaval can have a look? |
Yep, I thought about that too. But Reuse |
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.
Looking good.
I dropped some comments, will continue after lunch.
slick/src/main/scala/akka/stream/alpakka/slick/javadsl/Slick.scala
Outdated
Show resolved
Hide resolved
slick/src/main/scala/akka/stream/alpakka/slick/javadsl/Slick.scala
Outdated
Show resolved
Hide resolved
slick/src/main/scala/akka/stream/alpakka/slick/javadsl/Slick.scala
Outdated
Show resolved
Hide resolved
private def toDBIO[T](javaDml: JBiFunction[T, Connection, PreparedStatement]): T => DBIO[Int] = { t => | ||
SimpleJdbcAction { ctx => | ||
val statement = javaDml(t, ctx.connection) | ||
if (statement != null) statement.executeUpdate() else 0 |
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.
This becomes a hidden filter
feature, but makes sense as a safe-guard.
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.
Yep. I thought about NPE-safety and I haven’t come up with anything better like this 🤷♂️
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.
But it becomes a dangerous mix with the failure handling you suggested in the example...
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.
I removed this check, rewritten examples in docs, and added test with recover
function.
Please, review.
slick/src/main/scala/akka/stream/alpakka/slick/javadsl/Slick.scala
Outdated
Show resolved
Hide resolved
dc67c48
to
20fc83a
Compare
Extend Java DSL for using `java.sql.PreparedStatement`
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.
LGTM. Great to finally make this usable from Java!
PreparedStatement
use in Java DSL
Thank you @ihostage! |
Extend Java DSL for using
java.sql.PreparedStatement
References #2247