scray.jdbc.extractors.ScrayH2Dialect.scala Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of scray-jdbc Show documentation
Show all versions of scray-jdbc Show documentation
scray adapter to r/w JDBC tables
The newest version!
package scray.jdbc.extractors
import scray.querying.description.internal.Domain
import scray.querying.description.TableIdentifier
import scray.querying.description.QueryRange
/**
* H2 dialect for Scray
*/
object ScrayH2Dialect extends ScraySQLDialect("H2") {
/**
* H2 implements limits by limit and offset (if limit has been specified) or offset and fetch
*/
override def getEnforcedLimit(rangeOpt: Option[QueryRange], where: List[Domain[_]]): (String, List[Domain[_]]) = rangeOpt.map { range =>
val sbuf = new StringBuffer
if(range.skip.isDefined || range.limit.isDefined) {
range.limit.map { limit =>
sbuf.append(s" LIMIT ${limit} ")
range.skip.foreach { skip =>
sbuf.append(s" OFFSET ${skip} ")
}
}.getOrElse {
sbuf.append(s" OFFSET ${range.skip.getOrElse(0L)} ROWS ")
}
}
(sbuf.toString, List())
}.getOrElse(("", List()))
/**
* we scan if the URL is of format:
* jdbc:h2:...
*
* correct format according to H2 website is:
* jdbc:h2:tcp://[:]/[]
*/
override def isDialectJdbcURL(jdbcURL: String): Boolean =
jdbcURL.toUpperCase().startsWith("JDBC:H2:")
override val DRIVER_CLASS_NAME = "org.h2.Driver"
}