[#1773] Add a new jOOQ-Scala project and jooq-scala artefactId, to

contain jOOQ extensions in the Scala language - Let SAnyField extend
Field, instead of QueryPartInternal
This commit is contained in:
Lukas Eder 2012-09-01 15:19:39 +02:00
parent e94931f85e
commit 37bcf540f7
2 changed files with 23 additions and 5 deletions

View File

@ -85,7 +85,7 @@ object Conversions {
* A Scala-esque representation of {@link org.jooq.Field}, adding overloaded
* operators for common jOOQ operations to arbitrary fields
*/
trait SAnyField[T] extends QueryPartInternal {
trait SAnyField[T] extends Field[T] {
// String operations
// -----------------
@ -183,8 +183,8 @@ object Conversions {
// QueryPart API
// -------------
def toSQL(context : RenderContext) = underlying.toSQL(context)
def bind (context : BindContext) = underlying.bind(context)
def toSQL(context : RenderContext) = underlying.asInstanceOf[QueryPartInternal].toSQL(context)
def bind (context : BindContext) = underlying.asInstanceOf[QueryPartInternal].bind(context)
// String operations
// -----------------
@ -289,12 +289,18 @@ object Conversions {
case class NumberFieldWrapper[T <: Number](override val underlying: Field[T])
extends NumberFieldBase[T] (underlying) {}
/**
* Enrich numeric {@link org.jooq.Field} with the {@link SNumberField} trait
*/
implicit def asSNumberField[T <: Number](f : Field[T]): SNumberField[T] = f match {
case AnyFieldWrapper(f) => f
case NumberFieldWrapper(f) => f
case _ => new NumberFieldWrapper(f)
}
/**
* Enrich any {@link org.jooq.Field} with the {@link SAnyField} trait
*/
implicit def asSAnyField[T](f : Field[T]): SAnyField[T] = f match {
case AnyFieldWrapper(f) => f
case _ => new AnyFieldWrapper(f)

View File

@ -33,6 +33,7 @@
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
package org.jooq.scala.example
import collection.JavaConversions._
@ -40,6 +41,7 @@ import java.sql.DriverManager
import org.jooq._
import org.jooq.impl._
import org.jooq.impl.Factory._
import org.jooq.scala.example.h2.Tables._
import org.jooq.scala.Conversions._
@ -47,14 +49,24 @@ object Test {
def main(args: Array[String]): Unit = {
val c = DriverManager.getConnection("jdbc:h2:~/test", "sa", "");
val f = new Factory(c, SQLDialect.H2);
val x = T_AUTHOR as "x"
for (r <- f
select (
T_BOOK.ID * T_BOOK.AUTHOR_ID,
T_BOOK.ID + T_BOOK.AUTHOR_ID * 3 + 4,
T_BOOK.TITLE || " abc" || " xy")
from T_BOOK
where (T_BOOK.ID <> 3) fetch
from T_BOOK
leftOuterJoin (
f select ( x.ID, x.YEAR_OF_BIRTH)
from x
limit 1
asTable x.getName()
)
on T_BOOK.AUTHOR_ID === x.ID
where (T_BOOK.ID <> 2)
or (T_BOOK.TITLE in ("O Alquimista", "Brida"))
fetch
) {
println(r)