From 7df7f708659be5791fb8441998105f8416649f9f Mon Sep 17 00:00:00 2001 From: Lukas Eder Date: Fri, 26 Oct 2012 12:12:03 +0200 Subject: [PATCH] [#1773] Add a new jOOQ-Scala project and jooq-scala artefactId, to contain jOOQ extensions in the Scala language - Updated manual --- .../scala/org/jooq/scala/example/Test.scala | 2 +- jOOQ-website/src/main/resources/html-util.xsl | 5 + .../src/main/resources/manual-2.6.xml | 203 +++++++++++++++++- jOOQ-website/src/main/resources/pdf.xsl | 2 +- 4 files changed, 203 insertions(+), 9 deletions(-) diff --git a/jOOQ-scala/src/test/scala/org/jooq/scala/example/Test.scala b/jOOQ-scala/src/test/scala/org/jooq/scala/example/Test.scala index e39bb06509..6fa8f66008 100644 --- a/jOOQ-scala/src/test/scala/org/jooq/scala/example/Test.scala +++ b/jOOQ-scala/src/test/scala/org/jooq/scala/example/Test.scala @@ -58,7 +58,7 @@ object Test { T_BOOK.TITLE || " abc" || " xy") from T_BOOK leftOuterJoin ( - f select ( x.ID, x.YEAR_OF_BIRTH) + f select (x.ID, x.YEAR_OF_BIRTH) from x limit 1 asTable x.getName() diff --git a/jOOQ-website/src/main/resources/html-util.xsl b/jOOQ-website/src/main/resources/html-util.xsl index 0db9f7370c..0abf5dd679 100644 --- a/jOOQ-website/src/main/resources/html-util.xsl +++ b/jOOQ-website/src/main/resources/html-util.xsl @@ -180,6 +180,11 @@ + +
+					
+				
+
 					
diff --git a/jOOQ-website/src/main/resources/manual-2.6.xml b/jOOQ-website/src/main/resources/manual-2.6.xml
index a2f6d2a6d3..30385ca0c6 100644
--- a/jOOQ-website/src/main/resources/manual-2.6.xml
+++ b/jOOQ-website/src/main/resources/manual-2.6.xml
@@ -885,7 +885,73 @@ public class Main {
 					
 					
jOOQ and Scala - + +

+ As any other library, jOOQ can be easily used in Scala, taking advantage of the many Scala language features such as for example: +

+
    +
  • Optional "." to dereference methods from expressions
  • +
  • Optional "(" and ")" to delimit method argument lists
  • +
  • Optioanl ";" at the end of a Scala statement
  • +
  • Type inference using "var" and "val" keywords
  • +
+ +

+ But jOOQ also leverages other useful Scala features, such as +

+
    +
  • implicit defs for operator overloading
  • +
  • Scala Macros (soon to come)
  • +
+ +

+ A short example jOOQ application in Scala might look like this: +

+ + 2) // Using the olerloaded "<>" operator + or (T_BOOK.TITLE in ("O Alquimista", "Brida")) // Neat IN predicate expression + fetch // + ) { // + println(r) // + } // + } // +}]]> + +

+ For more details about jOOQ's Scala integration, please refer to the manual's section about . +

+
@@ -5200,7 +5266,135 @@ create.attach(select);]]>
SQL building in Scala - + +

+ jOOQ-Scala is a maven module used for leveraging some advanced Scala features for those users that wish to use jOOQ with Scala. +

+ +

Using Scala's implicit defs to allow for operator overloading

+

+ The most obvious Scala feature to use in jOOQ are implicit defs for implicit conversions in order to enhance the type with SQL-esque operators. +

+

+ The following depicts a trait which wraps all fields: +

+ +(value : T) : Condition + def <>(value : Field[T]) : Condition + + def >(value : T) : Condition + def >(value : Field[T]) : Condition + + def >=(value : T) : Condition + def >=(value : Field[T]) : Condition + + def <(value : T) : Condition + def <(value : Field[T]) : Condition + + def <=(value : T) : Condition + def <=(value : Field[T]) : Condition + + def <=>(value : T) : Condition + def <=>(value : Field[T]) : Condition +}]]> + +

+ The following depicts a trait which wraps numeric fields: +

+ +>(value : T) : Field[T] + def >>(value : Field[T]) : Field[T] +}]]> + +

+ An example query using such overloaded operators would then look like this: +

+ + 2) +or (T_BOOK.TITLE in ("O Alquimista", "Brida")) +fetch]]> + +

Scala 2.10 Macros

+

+ This feature is still being experimented with. With Scala Macros, it might be possible to inline a true SQL dialect into the Scala syntax, backed by the jOOQ API. Stay tuned! +

+
@@ -7419,11 +7613,6 @@ Finishing : Total: 4.814ms, +3.375ms

- -
- SQL execution in Scala - -
diff --git a/jOOQ-website/src/main/resources/pdf.xsl b/jOOQ-website/src/main/resources/pdf.xsl index 00533192cb..29c6eb2ffd 100644 --- a/jOOQ-website/src/main/resources/pdf.xsl +++ b/jOOQ-website/src/main/resources/pdf.xsl @@ -517,7 +517,7 @@ - +