- DholmbladRU
- May 4, 2006
-
|
Can anyone recommend a nice scala JDBC wrapper? I saw SalikeJDBC, but the number of usages on maven is pretty low.
|
#
¿
Feb 16, 2015 16:11
|
|
- Adbot
-
ADBOT LOVES YOU
|
|
#
¿
May 9, 2024 23:54
|
|
- DholmbladRU
- May 4, 2006
-
|
Slick was a long series of headaches for us and we ended up just rolling our own.
Im not quite to the point of creating my own relational mapping yet. Very new to scala. Ill look into using Slick for now. It seems like the only production ready type safe product Ive found.
DholmbladRU fucked around with this message at 17:07 on Feb 16, 2015
|
#
¿
Feb 16, 2015 16:22
|
|
- DholmbladRU
- May 4, 2006
-
|
Depending on the complexity of your project, here's something to get you started if you change your mind.
code:case class Foo(name: String, value: Int)
object Foo {
fetchFromDb(conn: Connection): List[Foo] = {
val sql = "SELECT name, value FROM foo_table"
val rs = conn.prepareStatement(sql).executeQuery()
val output: List[Foo] = List[Foo]()
while (rs.next()) output = output :+ {
val name = rs.getString("name")
val value = rs.getInt("value")
Foo(name, value)
}
output
}
}
Obviously there's numerous improvements that could be made: abstract the column fetchers, return a stream instead of a list, support nulls through Option outputs, etc. but if you're just trying to get some data out, this should get you started.
That is very similar to implementation for JDBC which I would write in java. I guess the benifit of something like Slick is it can be non-blocking, as I understand it.
The documentation for the Slick Schma generator is a little spotty. I am having a hard time figuring out how to implement it.
|
#
¿
Feb 16, 2015 21:23
|
|
- DholmbladRU
- May 4, 2006
-
|
ScalikeJDBC looks promising. It wont be async, but it looks better than Slick for my needs.
|
#
¿
Feb 17, 2015 15:39
|
|
- DholmbladRU
- May 4, 2006
-
|
If anyone has used ScalikeJDBC, is there a way to use prepared statements for stored procedures? Below is the only way in which I can figure out how to run stored proc:
code: def updateRow(user: row)(implicit session: DBSession = autoSession): Any = {
val template = "CALL SP_LU_RE(?,?, ?)"
try {
session.execute(template, List(1, 1, 1))
SuccessJSON(success = true)
} catch {
case e: SQLException => CustomErrorObject(CustomError(400, BadRequest.reason, "row could not be created"))
}
}
edit: Found this note...
https://github.com/scalikejdbc/scalikejdbc/issues/59
|
#
¿
Mar 17, 2015 20:25
|
|
- DholmbladRU
- May 4, 2006
-
|
edit: wrong ssl implementation
DholmbladRU fucked around with this message at 15:17 on May 5, 2015
|
#
¿
May 4, 2015 19:10
|
|
- DholmbladRU
- May 4, 2006
-
|
Currently I am implementing a web service with Scala using Spray i/o. Looking to use SSL to secure my requests.The issue is that when an HTTPs request is made to the api I get a tuncation attack error.
code: fatal error: 80: Inbound closed before receiving peer's close_notify: possible truncation attack?
javax.net.ssl.SSLException: Inbound closed before receiving peer's close_notify: possible truncation attack?
Created a cert using this
code: keytool -genkey -keyalg RSA -alias mykey -dname "CN=dev.site.com,OU=app" -keystore keystore.jks -storepass pas -validity 365
Created an ssl trait like this
code: trait SSLConfiguration {
implicit def sslContext: SSLContext = {
val keystore = keystore.jks
val password = pas
val keyStore = KeyStore.getInstance("jks")
val in = getClass.getClassLoader.getResourceAsStream(keystore)
require(in != null, "Bad java key storage file: " + keystore)
keyStore.load(in, password.toCharArray)
val keyManagerFactory = KeyManagerFactory.getInstance("SunX509")
keyManagerFactory.init(keyStore, password.toCharArray)
val trustManagerFactory = TrustManagerFactory.getInstance("SunX509")
trustManagerFactory.init(keyStore)
val context = SSLContext.getInstance("TLS")
context.init(keyManagerFactory.getKeyManagers, trustManagerFactory.getTrustManagers, new SecureRandom)
context
}
implicit def sslEngineProvider: ServerSSLEngineProvider = {
ServerSSLEngineProvider { engine =>
engine.setEnabledCipherSuites(Array("TLS_RSA_WITH_AES_256_CBC_SHA"))
engine.setEnabledProtocols(Array("SSLv3", "TLSv1"))
engine
}
}
}
Set up my boot to use the trait.
code: object Boot extends App with SSLConfiguration
IO(Http) ! Http.Bind(service, interface = interface, 8300)(sslEngineProvider)
application.conf
code:spray.can {
server {
ssl-encryption = on
}
}
DholmbladRU fucked around with this message at 16:22 on May 6, 2015
|
#
¿
May 5, 2015 17:40
|
|
- DholmbladRU
- May 4, 2006
-
|
Running into an issue with Slick and am unsure how to troubleshoot. Have a database table with a column which is of type Time. When I attempt to query this column I receive the above error message. Has anyone encountered this issue before? I know its an issue with the type because if I change it to integer or something else the query works perfectly.
error
code:ERROR "Illegal hour value XX for java.sql.Time type in value"
This error is picked up by the following, and what you see above is the localized message
code: def SQLException(e: SQLException) = CError(e.getErrorCode, e.getSQLState, e.getLocalizedMessage)
[code]
Below is the DAO
[code]
protected case class SomeRow(id: Int, companyId: Int, someTime: Option[DateTime] = None)
protected implicit def GetResultRow(implicit e0: GR[Int], e1: GR[Option[DateTime]], e2: GR[Byte], e3: GR[DateTime]): GR[SomeRow] = GR{
prs => import prs._
SomeRow.tupled((<<[Int],<<?[DateTime]))
}
protected class LU(_tableTag: Tag) extends Table[SomeRow](_tableTag, "SOME_TABLE") {
def * = (id, allotedTime) <> (SomeRow.tupled, SomeRow.unapply)
/** Maps whole row to an option. Useful for outer joins. */
def ? = (id.?, someTime).shaped.<>({r=>import r._; _1.map(_=> SomeRow.tupled((_1.get, _2.get)))}, (_:Any) =>
throw new Exception("Inserting into ? projection not supported."))
/** Database column ID DBType(INT), AutoInc */
val id: Column[Int] = column[Int]("RECORD_ID", O.AutoInc)
/** Database column SOME_ROW DBType(TIME), Default(None) */
}
}
query
code:DAL.SomeRow.filter(_.id === 1).firstOption
DholmbladRU fucked around with this message at 13:20 on Jun 16, 2015
|
#
¿
Jun 16, 2015 01:01
|
|
- DholmbladRU
- May 4, 2006
-
|
I see no above error message
ops. edited original content
|
#
¿
Jun 16, 2015 13:21
|
|
- DholmbladRU
- May 4, 2006
-
|
Is DateTime from joda.time? I'm pretty sure that Slick only supports the old standard library dates (util.Date, sql.Time, sql.Timestamp)
Yes DateTime is joda
|
#
¿
Jun 16, 2015 18:57
|
|
- Adbot
-
ADBOT LOVES YOU
|
|
#
¿
May 9, 2024 23:54
|
|
- DholmbladRU
- May 4, 2006
-
|
Try storing a "new java.sql.Time(someDate.getMillis())" instead, at least until Slick adds support for joda.time or java.time
In the case class or in the class LU?
|
#
¿
Jun 16, 2015 20:15
|
|