From eaca0dd97c9d8ff7438b47fbddda516e2966e6d6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Timo=20Westk=C3=A4mper?= Date: Mon, 7 Mar 2011 14:47:36 +0000 Subject: [PATCH] updated docs --- .../main/docbook/content/tutorials/scala.xml | 206 +++++++++++++++++- .../query/scala/sql/JDBCIntegrationTest.scala | 4 +- 2 files changed, 202 insertions(+), 8 deletions(-) diff --git a/querydsl-docs/src/main/docbook/content/tutorials/scala.xml b/querydsl-docs/src/main/docbook/content/tutorials/scala.xml index bc9e23cba..78118e907 100644 --- a/querydsl-docs/src/main/docbook/content/tutorials/scala.xml +++ b/querydsl-docs/src/main/docbook/content/tutorials/scala.xml @@ -4,12 +4,206 @@ Querying in Scala - TODO + Generic support for Querydsl usage in Scala is available via querydsl-scala module. To add it to your Maven build, use the following snippet : - + + com.mysema.querydsl + querydsl-scala + ${querydsl.version} + +]]> + + + + DSL expressions for Scala + + Querydsl for Scala provides an alternative DSL for expression construction. The Scala DSL utilizes language features such as operator overloading, + function pointers and implicit imports for enhanced readability and conciseness. + + Here is an overview of the main alternatives : + + 5 +expr notBetween(2,6) expr not between (2,6) +expr negate -expr + +// numeric +expr add 3 expr + 3 +expr subtract 3 expr - 3 +expr divide 3 expr / 3 +expr multiply 3 expr * 3 +expr mod 5 expr % 5 +list.get(0) list(0) +map.get("X") map("X") +]]> + + + + + + Querying with SQL + + + Like with Querydsl SQL for Java you need to generate Query types to be able to construct your queries. + The following two unit test methods show how this is done : + + + + + + + Querying with other backends + + When querying with other backends the Expression model has to be created manually or alternatively the alias functionality can be used. + + Here is a minimal example with JPA/Hibernate : + + + + And here are some query examples + + + + The main import for Querydsl Scala integration is the following + + + + The factory method for query creation is + + + + In addition to queries you need variables which can be created like this + + + + The person variable is a proxy instance of the the Person class which can be used in queries. Now you can construct your queries, populate them via from-where-...-orderBy calls and get the projection out via list/uniqueResult/listResults calls. + + Querydsl expressions are constructed via method calls starting with the "$" sign. + + >With the Querydsl Java API a simple like expression would be constructed like this : + + + + Using the Scala API it is + + + + \ No newline at end of file diff --git a/querydsl-scala/src/test/scala/com/mysema/query/scala/sql/JDBCIntegrationTest.scala b/querydsl-scala/src/test/scala/com/mysema/query/scala/sql/JDBCIntegrationTest.scala index 8fb7f9df3..cac0b8be5 100644 --- a/querydsl-scala/src/test/scala/com/mysema/query/scala/sql/JDBCIntegrationTest.scala +++ b/querydsl-scala/src/test/scala/com/mysema/query/scala/sql/JDBCIntegrationTest.scala @@ -65,7 +65,7 @@ class JDBCIntegrationTest { exporter.setSerializerClass(classOf[ScalaMetaDataSerializer]); exporter.setCreateScalaSources(true); exporter.setTypeMappings(ScalaTypeMappings.create); - exporter.export(connection.getMetaData()); + exporter.export(connection.getMetaData); } @Test @@ -80,7 +80,7 @@ class JDBCIntegrationTest { exporter.setBeanSerializer(beanSerializer) exporter.setCreateScalaSources(true); exporter.setTypeMappings(ScalaTypeMappings.create); - exporter.export(connection.getMetaData()); + exporter.export(connection.getMetaData); } @Test