From ba9557e7002e6fd2cf497d847ff69601da543bfd Mon Sep 17 00:00:00 2001 From: lukaseder Date: Thu, 27 Nov 2014 08:28:15 +0100 Subject: [PATCH] Fixed Nashorn example --- jOOQ-examples/jOOQ-nashorn-example/.classpath | 5 +++ jOOQ-examples/jOOQ-nashorn-example/pom.xml | 7 ++-- .../org/jooq/example/test/settings.js | 33 +++++++++++++++++++ .../org/jooq/example/test/simple-query.js | 16 +++++++++ 4 files changed, 58 insertions(+), 3 deletions(-) create mode 100644 jOOQ-examples/jOOQ-nashorn-example/src/test/resources/org/jooq/example/test/settings.js create mode 100644 jOOQ-examples/jOOQ-nashorn-example/src/test/resources/org/jooq/example/test/simple-query.js diff --git a/jOOQ-examples/jOOQ-nashorn-example/.classpath b/jOOQ-examples/jOOQ-nashorn-example/.classpath index f481d62016..e3f9b6131d 100644 --- a/jOOQ-examples/jOOQ-nashorn-example/.classpath +++ b/jOOQ-examples/jOOQ-nashorn-example/.classpath @@ -17,6 +17,11 @@ + + + + + diff --git a/jOOQ-examples/jOOQ-nashorn-example/pom.xml b/jOOQ-examples/jOOQ-nashorn-example/pom.xml index 54029e2b81..f63f19745a 100644 --- a/jOOQ-examples/jOOQ-nashorn-example/pom.xml +++ b/jOOQ-examples/jOOQ-nashorn-example/pom.xml @@ -20,6 +20,7 @@ UTF-8 3.2.6.RELEASE 3.6.0-SNAPSHOT + 1.4.181 @@ -33,7 +34,7 @@ com.h2database h2 - 1.3.168 + ${org.h2.version} @@ -154,7 +155,7 @@ com.h2database h2 - 1.3.168 + ${org.h2.version} @@ -205,7 +206,7 @@ com.h2database h2 - 1.3.168 + ${org.h2.version} diff --git a/jOOQ-examples/jOOQ-nashorn-example/src/test/resources/org/jooq/example/test/settings.js b/jOOQ-examples/jOOQ-nashorn-example/src/test/resources/org/jooq/example/test/settings.js new file mode 100644 index 0000000000..1bc5c3a411 --- /dev/null +++ b/jOOQ-examples/jOOQ-nashorn-example/src/test/resources/org/jooq/example/test/settings.js @@ -0,0 +1,33 @@ +var DSL = Java.type("org.jooq.impl.DSL"); +var Settings = Java.type("org.jooq.conf.Settings"); +var RenderNameStyle = Java.type("org.jooq.conf.RenderNameStyle"); + +var Assert = Java.type("org.junit.Assert"); +var Arrays = Java.type("java.util.Arrays"); + +var Tables = Java.type("org.jooq.example.db.h2.Tables"); +var b = Tables.BOOK; +var a = Tables.AUTHOR; + + +// Unfortunately, there is a Nashorn / Java interoperablility issue documented here: +// http://stackoverflow.com/q/25603191/521799 +// +// To work around this issue, tables should probably be supplied in JavaScript arrays, +// in order to explicitly invoke the method accepting varargs, instead of the overloaded method + +var authors = DSL.using(connection, new Settings().withRenderNameStyle(RenderNameStyle.AS_IS)) + .select(a.ID) + .from([a]) + .orderBy(a.ID) + .fetch(a.ID); + +Assert.assertEquals(Arrays.asList([1, 2]), authors); + +var authors = DSL.using(connection, new Settings().withRenderNameStyle(RenderNameStyle.AS_IS)) + .select(a.ID) + .from([DSL.tableByName("author")]) + .orderBy(a.ID) + .fetch(a.ID); + +Assert.assertEquals(Arrays.asList([1, 2]), authors); \ No newline at end of file diff --git a/jOOQ-examples/jOOQ-nashorn-example/src/test/resources/org/jooq/example/test/simple-query.js b/jOOQ-examples/jOOQ-nashorn-example/src/test/resources/org/jooq/example/test/simple-query.js new file mode 100644 index 0000000000..69f665d13c --- /dev/null +++ b/jOOQ-examples/jOOQ-nashorn-example/src/test/resources/org/jooq/example/test/simple-query.js @@ -0,0 +1,16 @@ +var DSL = Java.type("org.jooq.impl.DSL"); + +var Assert = Java.type("org.junit.Assert"); +var Arrays = Java.type("java.util.Arrays"); + +var Tables = Java.type("org.jooq.example.db.h2.Tables"); +var b = Tables.BOOK; +var a = Tables.AUTHOR; + +var books = DSL.using(connection) + .select(b.ID) + .from(b) + .orderBy(b.ID) + .fetch(b.ID); + +Assert.assertEquals(Arrays.asList([1, 2, 3, 4]), books);